myinfo-connector-python api-doc
  • myinfo-connector-python API
    • Quick Start
    • v1.0
      • Users
      • Callback
Powered by GitBook
On this page
  • Step 1: Clone the repository in your local
  • Step 2: Install Pre-requisite
  • Step 3: Install packages
  • Step 4: Start server
  • Make your request
  • Get login url to redirect to myinfo
  • Callback called by Myinfo service
  • Get person data from myinfo
  1. myinfo-connector-python API

Quick Start

myinfo-connector-python is built with Django to make easy-to-go application.

Step 1: Clone the repository in your local

git clone git@github.com:leeleelee3264/myinfo-connector-python.git

Step 2: Install Pre-requisite

Install Python

You can exclude python 3 is already installed in your local.

brew install python@3.8 pipenv

Set Python Path in ~/.zshrc

export PATH="/opt/homebrew/opt/python@3.8/bin:$PATH"

Refresh ~/.zshrc

source ~/.zshrc

Step 3: Install packages

PIPENV_VENV_IN_PROJECT=1 
cd ~/myinfo-connector-python
pipenv install 

Step 4: Start server

pipenv run ./connector/manage.py runserver 0:3001

Make your request

To make your first request, call apis in order.

Step 1: Get myinfo redirect login url

Get login url to redirect to myinfo

GET http://localhost:3001/users/me/external/myinfo-redirect-login

Get login url to redirect to myinfo. This url contains attributes about person data requested to myinfo.

{
    "message": "OK",
    "data": {
        "url": "https://test.api.myinfo.gov.sg/com/v3/authorise?client_id=STG2-MYINFO-SELF-TEST&attributes=name,dob,birthcountry,nationality,uinfin,sex,regadd&state=eb03c000-00a3-4708-ab30-926306bfc4a8&redirect_uri=http://localhost:3001/callback&purpose=python-myinfo-connector",
        "state": "eb03c000-00a3-4708-ab30-926306bfc4a8"
    }
}

url: url to redirect to myinfo.

state: Identifier that represents the user's session/transaction with the client for reconciling query and response. The same value will be sent back via the callback URL. Use a unique system generated number for each user/transaction.

Step 2: Browse myinfo redirect login url

curl https://test.api.myinfo.gov.sg/com/v3/authorise?client_id=STG2-MYINFO-SELF-TEST&attributes=name,dob,birthcountry,nationality,uinfin,sex,regadd&state=eb03c000-00a3-4708-ab30-926306bfc4a8&redirect_uri=http://localhost:3001/callback&purpose=python-myinfo-connector// Some code

Step 3: Do login and check agree terms

(Automated) Step 4: Callback API get called by Myinfo

After login, Myinfo call our callback api to pass auth code as a response.

Callback called by Myinfo service

GET http://localhost:3001/callback

After login Myinfo and agree terms, Myinfo service automatically call myinfo-connector-python's callback API to pass auth code.

Query Parameters

Name
Type
Description

code*

String

state*

String

Identifier that represents the user's session/transaction with the client for reconciling query and response. The same value will be sent back via the callback URL. Use a unique system generated number for each user/transaction.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <span>Callback from Myinfo. Wait for calling person data API</span>
    <span id="code-container">{{ code }}</span>
</body>

<script>
    window.addEventListener('load',
        function (event) {
            let code_element = document.getElementById('code-container')
            let code_text = code_element.innerHTML

            let url = `http://localhost:3001/users/me/external/myinfo?code=${code_text}`
            window.location.href = url
        }
    );
</script>
</html>

callback url example

http://localhost:3001/callback?code=8932a98da8720a10e356bc76475d76c4c628aa7f&state=e2ad339a-337f-45ec-98fa-1672160cf463

Our callback api return simple HTML page to

  • get callback from Myinfo

  • call api for person data automatically right after the callback api called.

(Automated) Final Step: Get Person data from Myinfo

After callback, callback page automatically calls our api for person data

Get person data from myinfo

GET http://localhost:3001/users/me/external/myinfo

Get person data from myinfo. The API is final step of myinfo-connector-python

Query Parameters

Name
Type
Description

code

String

{
    "message": "OK",
    "sodata": {
        "regadd": {
            "country": {
                "code": "SG",
                "desc": "SINGAPORE"
            },
            "unit": {
                "value": "10"
            },
            "street": {
                "value": "ANCHORVALE DRIVE"
            },
            "lastupdated": "2022-07-14",
            "block": {
                "value": "319"
            },
            "source": "1",
            "postal": {
                "value": "542319"
            },
            "classification": "C",
            "floor": {
                "value": "38"
            },
            "type": "SG",
            "building": {
                "value": ""
            }
        },
        "dob": "1988-10-06",
        "sex": "M",
        "name": "ANDY LAU",
        "birthcountry": "SG",
        "nationality": "SG",
        "uinfin": "S6005048A"
    }
}

regadd: Registered Address of Person (including FIN holders)

dob: Date of Birth of Person.

sex: Sex of Person.

name: Full Name of the Person.

unifin: Singapore issued identification number of the Person.

{
    "message": "Internal server error.",
    "code": "INTERNAL_SERVER_ERROR",
    "error": {
        "title": "오류가 발생했습니다.",
        "description": "Fail to get Myinfo Access Token. Authcode Might be re-used or expired.",
        "code": "INTERNAL_SERVER_ERROR",
        "data": null
    }
}
{
    "message": "Internal server error.",
    "code": "INTERNAL_SERVER_ERROR",
    "error": {
        "title": "오류가 발생했습니다.",
        "description": "Fail to parse Myinfo Person Data.",
        "code": "INTERNAL_SERVER_ERROR",
        "data": null
    }
}

Previousmyinfo-connector-python APINextv1.0

Last updated 2 years ago

The authcode given by

The authcode given by

birthcountry: Country of Birth of Person. Refer to country in code table provided for description of each code.

nationality: Nationality of Person. Refer to the in the Support section for list of possible values.

HERE
Code reference tables
myinfo's authorise API
myinfo's authorise API
Myinfo Login Page
Myinfo Terms Agreement Page
Response Page for callback api