Giter VIP home page Giter VIP logo

myinfo-connector-python's Introduction

myinfo-connector-python


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.

Documents

Check Quick Start: link
Check API Doc: link



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 [email protected]: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 [email protected] pipenv

Set Python Path in ~/.zshrc

export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"

Refresh ~/.zshrc

source ~/.zshrc

Step 3: Install python 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

The REST API to make request is described below.

Step 1: Get myinfo redirect login url

Request

GET /users/me/external/myinfo-redirect-login

curl -i -H 'Accept: application/json' http://localhost:3001/user/me/external/myinfo-redirect-login

Response

{
    "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"
    }
}

Step 2: Browse myinfo redirect login

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

Step 3: Do login and check agree terms

Myinfo Login Page

Myinfo Login Page

Myinfo Terms Agreement Page

Myinfo Terms Agreement Page


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

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

callback url example

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

callback response HTML example

Response Page for callback api


(Automated) Final Step: Get Person data from Myinfo

After callback, callback page automatically calls our api for person data. The API is final step of myinfo-connector-python.

Request

GET /users/me/external/myinfo

curl -i -H 'Accept: application/json' http://localhost:3001/user/me/external/myinfo

Response

{
    "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"
    }
}


Project TODO List

  • 1st Implement
  • Apply Pipenv for package management
  • Apply python lint (flake8, pylint, mypy)
  • Documentation
  • 2nd Refactoring (Move DTO to domain layer)
  • 3th Redactoring (Entire)

myinfo-connector-python's People

Contributors

kasa-leelee avatar leeleelee3264 avatar

Watchers

 avatar

myinfo-connector-python's Issues

In Signpass API v4 "Invalid JWS Verification" using python ?

Hi
tmp_285b62f7-772e-4306-9b48-78e40f6e1e53
tmp_d1ef3994-38ac-496d-9f44-6f063fe9c87d

I'm looking for Singpass Myinfo V4 into our django application. While searching for a python package, I came across one designed for V3. However, I specifically require V4 compatibility. Currently we are building sing pass v4 in python with the reference of myinfo-connector-node.js package we generated client_assertion, Dpop, public signing key, and verified with singpass Api website it's shows verification success but in our application shows "INVALID JWS Verification". I stuck with this error for past few weeks. I would appreciate any suggestions or recommendations.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.