Exchange code for token
This guide is about the server half of sign-in: you have the code from onSuccess, and you
need to get a token and identify the user.
Exchange the code
Section titled “Exchange the code”Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&
code=RECEIVED_CODE&
redirect_uri=https://partner.example/callback&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRET&
code_verifier=CODE_VERIFIER_FROM_INIT_STEPThe response contains access_token (1-hour lifetime), refresh_token (30 days) and id_token.
Read the profile
Section titled “Read the profile”There are two ways to learn who the user is; both yield the same sub field.
- From
id_token— it is a JWT; verify the signature with the keys from JWKS and take thesubclaim. - Through UserInfo — call
GET /oauth/userinfowithAuthorization: Bearer <access_token>.
Authorization: Bearer ACCESS_TOKENDo not hardcode endpoint addresses — take them from
GET /.well-known/openid-configuration (discovery).
Refresh the token
Section titled “Refresh the token”Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&
refresh_token=REFRESH_TOKEN&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRETFull request and response schemas are in the API reference.