Quick Start
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
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
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
{
"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.
birthcountry: Country of Birth of Person. Refer to country
in code table provided HERE for description of each code.
nationality: Nationality of Person. Refer to the Code reference tables in the Support section for list of possible values.
unifin: Singapore issued identification number of the Person.
Last updated