node-my-info-sg 🇸🇬
Small wrapper around Singapore MyInfo V3 API for node JS. Wraps the scary-scary 😱 security logic into easy to use APIs.
Lightly refactored from the excellent official example 🎉
Usage
-
Initialise MyInfoClient
const MyInfoClient = require('node-my-info-sg');
const myInfoClient = new MyInfoClient({
baseUrl: 'https://sandbox.api.myinfo.gov.sg',
authLevel: 'L0',
publicCertPath: './ssl/stg-auth-signing-public.pem',
privateKeyPath: './ssl/stg-demoapp-client-privatekey-2018.pem',
clientId: 'STG2-MYINFO-SELF-TEST',
clientSecret: '44d953c796cccebcec9bdc826852857ab412fbe2',
redirectUrl: 'http://localhost:3001/callback',
});
-
Generate the OAuth2 url
const attributes = ['uinfin', 'name', 'mobileno'];
const { authoriseUrl, state } = myInfoClient.getAuthoriseUrl(purpose, attributes);
-
Get the person object
const { accessToken } = await myInfoClient.getToken(code);
const { person } = await myInfoClient.getPerson(accessToken, attributes)
console.log(JSON.stringify(person));
Example
In the example directory, run:
yarn install
./start.sh
Unit test
yarn lint
yarn test