@opengovsg/gov-login-client
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @opengovsg/gov-login-client

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

30.2 kB

Total Files

13

Last publish

Collaborators

  • lonerifle
  • liangyuanruo
  • pallani
  • opengovsg-npm