The Token Endpoint
The /token endpoint is a back channel endpoint that issues a usable access token. It supports multiple grant types as defined in OAuth 2.0 specifications.
info
-
All requests to the
/tokenendpoint should use the HTTP POST method and include appropriate authentication (e.g., client credentials in the Authorization header or in the request body). -
The url
/tokencan be anything, some other common urls are:/oauth/token,/v1/token, etc.
app.post("/token", async (req: Express.Request, res: Express.Response) => {
try {
const oauthResponse = await authorizationServer.respondToAccessTokenRequest(req);
return handleExpressResponse(res, oauthResponse);
} catch (e) {
handleExpressError(e, res);
return;
}
});
Flow
The /token endpoint supports the following grant types:
Authorization Code Grant (RFC6749 Section 4.1)
- Used to exchange an authorization code for an access token
- Request parameters:
grant_type=authorization_codecode: The authorization code received from the authorization serverredirect_uri: Must match the original redirect URI used in the authorization requestclient_id: The client identifier
Refresh Token Grant (RFC6749 Section 6)
- Used to obtain a new access token using a refresh token
- Request parameters:
grant_type=refresh_tokenrefresh_token: The refresh token issued to the clientscope(optional): The scope of the access request
Client Credentials Grant (RFC6749 Section 4.4)
- Used for machine-to-machine authentication where no user is involved
- Request parameters:
grant_type=client_credentialsscope(optional): The scope of the access request
Resource Owner Password Credentials Grant (RFC6749 Section 4.3)
- Used to exchange the resource owner's credentials for an access token
- Request parameters:
grant_type=passwordusername: The resource owner's usernamepassword: The resource owner's passwordscope(optional): The scope of the access request
Token Exchange (RFC8693)
- Used to exchange one security token for another
- Request parameters:
grant_type=urn:ietf:params:oauth:grant-type:token-exchangesubject_token: The security token that is the subject of the exchangesubject_token_type: An identifier for the type of thesubject_tokenrequested_token_type(optional): An identifier for the type of the requested security tokenaudience(optional): The logical name of the target service where the client intends to use the requested security token
Supports the following RFC'S