Integrating Using the SDK
There are two main ways of integrating your app with sgID:
Using the Javascript/Typescript SDK
Custom integration by writing your own code for each of the authorization code flow steps
Unfortunately, we only have support for a Javascript SDK, so if your app is written in a different programming language, jump ahead to the next page for the guide on custom integration.
Installing the SDK
Initializing the SDK
Creating an authorization URL
To allow your user to login into your app with sgID, you need to create an sgID authorization URL to redirect your user to so that they can authenticate with Singpass.
client.authorizationUrl(state, scope, [nonce], [redirectUri])
The full authorization URL should look something like this:
Exchange auth code for access token
After the user authenticates with Singpass, sgID will redirect the user back to the callback URL you provided, together with the authorization code and a state value. Reusing the callback URL defined in the example above:
Using this authorization code, we can use the SDK to exchange it for an access token, which will be used to retrieve user information.
async client.callback(code, [nonce], [redirectUri])
Here, the sub
refers to the end user's unique identifier for your client. Note that as part of sgID's privacy-preserving measures, each end user's unique identifier is different for each sgID client.
Request for user info
Once you have the access token, you can use it to request information about the user corresponding to the scopes that you requested.
async client.userinfo(accessToken)
Last updated