Start Date | 2022-07-05 |
---|---|
End Date | 2022-07-23 |
This is repository for Python/Django Connector for Singapore government mydata service, Singpass myinfo. MyInfo Connector aims to simplify consumer's integration effort with MyInfo by providing an easy to use Python library to integrate into your application.
Myinfo provide Java, nodejs connector. I wanted to use myinfo API in Python, so I made a myinfo connector with python.
Check Quick Start: link
Check API Doc: link
myinfo-connector-python is built with Django to make easy-to-go application.
git clone git@github.com:leeleelee3264/myinfo-connector-python.git
You can exclude python 3 is already installed in your local.
brew install python@3.8 pipenv
export PATH="/opt/homebrew/opt/python@3.8/bin:$PATH"
source ~/.zshrc
PIPENV_VENV_IN_PROJECT=1
cd ~/myinfo-connector-python
pipenv install
pipenv run ./connector/manage.py runserver 0:3001
The REST API to make request is described below.
GET /users/me/external/myinfo-redirect-login
curl -i -H 'Accept: application/json' http://localhost:3001/user/me/external/myinfo-redirect-login
{
"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"
}
}
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
After login Myinfo and agree terms, Myinfo service automatically call myinfo-connector-python's callback API to pass auth code. The authcode given by myinfo's authorise API
http://localhost:3001/callback?code=8932a98da8720a10e356bc76475d76c4c628aa7f&state=e2ad339a-337f-45ec-98fa-1672160cf463
After callback, callback page automatically calls our api for person data. The API is final step of myinfo-connector-python.
GET /users/me/external/myinfo
curl -i -H 'Accept: application/json' http://localhost:3001/user/me/external/myinfo
{
"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"
}
}
- 1st Implement
- Apply Pipenv for package management
- Apply python lint (flake8, pylint, mypy)
- Documentation
- 2nd Refactoring (Move DTO to domain layer)
- 3th Redactoring (Entire)