spcp-myinfo

Helper library to use SingPass/CorpPass OIDC authentication & MyInfo Person Basic.
Install via NPM
npm install spcp-myinfo
Usage
import express from 'express';
import { SCPC, MyInfoGov } from 'spcp-myinfo';
const app = express();
const singpass = new SPCP({
type: 'singpass',
clientId: 'your_clientId',
clientSecret: 'your_clientSecret_given_by_spcp',
redirectUri: 'https://www.youreservice.com/singpass/callback',
spcpPublicCert: 'public_cert_given_by_spcp',
ownPrivateKey: 'your_server_ssl_private_key',
environment: 'production'
});
const myinfo = new MyInfoGov({
clientId: 'your_clientId',
singpassClientId: 'your_singpassClientId',
attributes: ['name', 'dob', 'sex'],
myinfoPublicCert: 'public_cert_given_by_myinfo',
ownPrivateKey: 'your_server_ssl_private_key',
environment: 'production'
});
app.get('/singpass/authorizeUri', (req, res) => {
const url = singpass.getAuthorizeUri();
res.json({ url });
});
app.get('/singpass/callback', async (req, res) => {
const { uinFin, accessToken } = await singpass.callback(req.query);
const person = await myinfo.getPersonBasic(uinFin, accessToken);
});
Mock SPCP in Development/Testing Environment
import express from 'express';
import { SCPC } from 'spcp-myinfo';
const app = express();
const singpass = new SPCP({
type: 'singpass',
clientId: 'your_clientId',
clientSecret: 'your_clientSecret_given_by_spcp',
redirectUri: 'https://www.youreservice.com/singpass/bypass',
spcpPublicCert: 'public_cert_given_by_spcp',
ownPrivateKey: 'your_server_ssl_private_key',
environment: 'mock',
mockAuthorizeUri: 'https://www.youreservice.com/singpass/mock'
});
app.get('/singpass/authorizeUri', (req, res) => {
const url = singpass.getAuthorizeUri();
res.json({ url });
});
app.get('/singpass/bypass', async (req, res) => {
const uinFin = req.query.uinFin;
});
app.get('/singpass/mock', (req, res) => {
const html = singpass.getMockPassHtml();
res.send(html);
});