Skip to content

The official TypeScript/JavaScript SDK for gov-login

License

Notifications You must be signed in to change notification settings

opengovsg/gov-login-client

 
 

Repository files navigation

gov-login-client

npm version

The official TypeScript/JavaScript client for gov-login

This SDK is a fork of the sgID SDK.

CHANGELOG

See Releases for CHANGELOG and breaking changes.

Installation

npm i @opengovsg/gov-login-client

Usage

Initialization

import GovLoginClient from '@opengovsg/gov-login-client'

const client = new GovLoginClient({
  clientId: 'CLIENT-ID',
  clientSecret: 'cLiEnTsEcReT',
  redirectUri: 'http://localhost:3000/callback',
})

Get Authorization URL

client.authorizationUrl(state, scope, [nonce], [redirectUri])

const { url } = client.authorizationUrl(
  'state',
  ['openid', 'myinfo.nric_number'], // or space-concatenated string
  null, // defaults to randomly generated nonce if unspecified
  'http://localhost:3000/other_callback', // overrides redirect uri
)

Token exchange

async client.callback(code, [nonce], [redirectUri])

const { sub, accessToken } = await client.callback(
  'code', // auth code reuturned from redirect_url
  null,
  'http://localhost:3000/other_callback', // optional, unless overridden
)

User info

async client.userinfo(accessToken)

const { sub } = await client.userinfo('access_token')

Supported Runtime and Environment

This library depends on jose npm package which currently supports these Node.js versions.

About

The official TypeScript/JavaScript SDK for gov-login

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 96.7%
  • JavaScript 1.9%
  • Shell 1.4%