3. Token Exchange
Token exchange refers to the process of making a POST request to the token endpoint to exchange the authorization code (obtained from the redirect URL in the previous step) with an ID token and access token.
The token endpoint is defined in the token_endpoint
field located in our authorization server's OpenID Configuration.
The process of token exchange involves two parts:
Generation of a client assertion, which we will use to authenticate you.
Sending the client assertion together with the request body to the token endpoint.
Generation of client assertion
You will need to generate a client assertion using private_key_jwt
mechanism specified in the OIDC specifications. This mechanism involves you building a client assertion by signing a JWT using one of your signing keys defined in your JWKS.
To reduce complexity, we recommend that you use a JWT library to perform the JWT encoding and signing on your behalf, instead of implementing this on your own. You may refer to this list to look for a suitable library for your programming language.
The JWT must have the structure outlined below.
JWT Header
The JWT header should contain the following parameters:
alg
The signature algorithm that you are using to sign this JWT
One of the following strings:
ES256
ES384
ES512
typ
The type of this JWT
Must be the string JWT
kid
The kid
of the signing key that you are using to sign this JWT header.
If this is not provided, we will test against all of the signing keys in your JWKS when attempting to verify the signature.
String, optional
JWT Payload
The JWT payload should contain the following claims:
sub
The client ID of your registered client, provided by Singpass during app onboarding.
A 32-character case-sensitive alphanumeric string.
aud
This should be the issuer identifier of our authorization server. You can obtain this value from the issuer
field in the OpenID configuration of our authorization server.
String
iss
The client ID of your registered client, provided by Singpass during app onboarding.
A 32-character case-sensitive alphanumeric string.
iat
The unix timestamp, in seconds, at which you generated this JWT.
Number
exp
The unix timestamp, in seconds, on or after which this JWT must not be accepted by us for processing.
Note also that this must be less than or equal to 2 minutes after iat
.
Number
jti
A unique identifier for this token. This identifier must only be used once. You should generate a new jti
value for every request
String
code
The authorization code issued by us, obtained from the redirect URL in the previous step.
A base64url-encoded string.
Request Body
You should send the request body in application/x-www-form-urlencoded
format. The DPoP header containing the DPoP JWT proof should also be included in your request.
The request body should have the following parameters:
client_id
The client ID of your registered client, provided by Singpass during app onboarding.
A 32-character case-sensitive alphanumeric string.
redirect_uri
The redirect_uri
which you had used earlier when making the Authorization request.
URL
grant_type
The grant being requested.
Must be the string authorization_code
, as mandated by OIDC specifications.
code
The authorization code issued by us, obtained via redirection back to your redirect_url
in the previous step.
A base64url-encoded string.
client_assertion_type
The type of client assertion.
Must be the string urn:ietf:params:oauth:client-assertion-type:jwt-bearer
, as mandated by OIDC specifications.
client_assertion
Your client assertion, generated using the instructions in the "Authentication" section above.
A string containing the signed JWT.
code_verifier
The code verifier which you have generated when constructing your authorization request.
String containing only alphanumeric characters, dashes, and underscores, between 43-128 characters long.
Response Body
We will return a response in application/json
format. This response includes the following parameters:
access_token
For Login applications, this is a random string which should not be used. For Myinfo (v5) applications, this is an encoded JWT that can be used to obtain user information using the UserInfo endpoint. This access token has a lifetime of 30 minutes.
String
id_token
The encrypted ID token in JWT format, signed by us. More information on how to parse this ID token is available in the next page.
String
token_type
The type of token being requested.
This will always be DPoP
, as mandated by FAPI 2.0 specifications.
Last updated
Was this helpful?