POST /recipe/oauth/token
Issues or refreshes OAuth 2.0 access tokens. Supports authorization code, refresh token, and client credentials grant types.Request Body
Parameters
- iss (string, required): Token issuer URL
-
inputBody (object, required): Token request parameters
-
grant_type (string, required): One of:
authorization_code: Exchange authorization code for tokensrefresh_token: Exchange refresh token for new access tokenclient_credentials: M2M authentication
- code (string, required for authorization_code): Authorization code from /auth endpoint
- redirect_uri (string, required for authorization_code): Must match the redirect_uri used in /auth
- refresh_token (string, required for refresh_token): Valid refresh token
- client_id (string, optional): OAuth client ID (can be provided via Authorization header instead)
- client_secret (string, optional): OAuth client secret (can be provided via Authorization header instead)
-
grant_type (string, required): One of:
-
authorizationHeader (string, optional): Basic authentication header containing Base64-encoded
client_id:client_secret - access_token (object, required for authorization_code): Additional claims to include in access token
- id_token (object, required for authorization_code): Additional claims to include in ID token
-
useStaticSigningKey (boolean, optional): Use static signing key. Defaults to
true, set tofalsefor dynamic keys
Response
Success Response
- access_token (string): JWT access token
- token_type (string): Always “Bearer”
- expires_in (number): Token lifetime in seconds
- refresh_token (string, optional): Refresh token (not returned if refresh token rotation is enabled and refreshing)
- scope (string): Granted OAuth scopes
- id_token (string, optional): OpenID Connect ID token
Grant Type Details
Authorization Code
Exchanges an authorization code for tokens. This is the most common flow for web applications.Refresh Token
Exchanges a refresh token for a new access token.Client Credentials
Machine-to-machine authentication using client credentials.Implementation Details
- Located in:
src/main/java/io/supertokens/webserver/api/oauth/OAuthTokenAPI.java:68 - Recipe:
OAUTH - Refresh token requests are synchronized using named locks to prevent race conditions
- The endpoint validates refresh tokens before issuing new tokens
- Inactive or invalid refresh tokens return a
token_inactiveerror - OAuth sessions are created/updated with token metadata (gid, jti, expiry)
- For refresh token rotation, old tokens are invalidated when new ones are issued
- Client credentials tokens are tracked as M2M tokens
- Session handles in tokens trigger last active time updates