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
var { authoriseUrl, state } = myInfoClient.getAuthoriseUrl(purpose, attributes);
-
Get the person object
myInfoClient.getToken(code)
.then(({ accessToken }) => myInfoClient.getPerson(accessToken, _attributes))
.then(({ person }) => console.log(JSON.stringify(person)));
Example
In the example directory, run:
yarn install
./start.sh
Future Improvement
- Add unit tests and sensible linting rules
- Pass this repository to the cool government guy, so they can maintain it