Helper library for using Singapore NDI Singpass/Corpass login.
npm install ndi-login
import { NdiLogin } from 'ndi-login';
or
const { NdiLogin } = require('ndi-login');
const ndiLogin = new NdiLogin({
issuer: 'https://stg-id.singpass.gov.sg',
clientId: 'YOUR_CLIENT_ID',
clientAssertionJwk: {
// JWK for signing/verifying client assertion in JSON format
},
idTokenJwk: {
// JWK for encrypting/decrypting ID token in JSON format
},
});
const uri = await ndiLogin.generateAuthorizationUri({ redirectUri, codeChallenge, state, nonce })
const clientAssertion = await ndiLogin.generateClientAssertion();
const { authReqId } = await ndiLogin.backchannelAuthenticate({ clientAssertion, uin })
const clientAssertion = await ndiLogin.generateClientAssertion();
const { idToken } = await ndiLogin.getTokens({ clientAssertion, code, redirectUri, codeVerifier });
const { sub } = await ndiLogin.getIdTokenClaims(idToken);
const { uin } = NdiLogin.parseIdTokenSub(sub);
const clientAssertion = await ndiLogin.generateClientAssertion();
const { idToken } = await ndiLogin.getTokens({ clientAssertion, authReqId });
const { sub } = await ndiLogin.getIdTokenClaims(idToken);
const { uin } = NdiLogin.parseIdTokenSub(sub);
const jwks = await ndiLogin.getRpJwks();
const { clientAssertionJwk, idTokenJwk } = await NdiLogin.generateRpJwks();
const codeVerifier = NdiLogin.generateCodeVerifier();
const codeChallenge = NdiLogin.generateCodeChallege(codeVerifier);
const state = NdiLogin.generateState();
const nonce = NdiLogin.generateNonce();