liveBook · Manning

Token endpoint

As explained in Spring Security in Action, Second Edition

A token endpoint is an OAuth endpoint where a client exchanges a grant or credential for tokens.

A token endpoint lets a client exchange an authorization code for tokens after successful user authentication. The client sends an HTTP POST request and authenticates with HTTP Basic when that method was registered. section 14.2

A successful authorization-code request includes:

  • client_id identifying the client. section 14.2
  • redirect_uri matching the URI used during authorization. section 14.2
  • grant_type=authorization_code, the authorization code, and the code verifier. section 14.2
  • Values must match the registered client and earlier authorization request or the exchange fails. section 14.2

Request and response

POST http://localhost:8080/oauth2/token with the authorization code parameters and an HTTP Basic client credential produces an access token. With OpenID Connect enabled, the response also includes an ID token; refresh-token registration can add a refresh token. section 14.2

Listing 14.7 The response of the OpenID configuration request
{
    "issuer": "http://localhost:8080",
    "authorization_endpoint": 
    "http://localhost:8080/oauth2/authorize",                     #1
    "token_endpoint": "http://localhost:8080/oauth2/token",       #2
    "token_endpoint_auth_methods_supported": [
        "client_secret_basic",
        "client_secret_post",
        "client_secret_jwt",
        "private_key_jwt"
    ],
    "jwks_uri": "http://localhost:8080/oauth2/jwks",              #3
    "userinfo_endpoint": "http://localhost:8080/userinfo",
    "response_types_supported": [
        "code"
    ],
    "grant_types_supported": [
        "authorization_code",
        "client_credentials",
        "refresh_token"
    ],
    "revocation_endpoint": "http://localhost:8080/oauth2/revoke",
    "revocation_endpoint_auth_methods_supported": [
        "client_secret_basic",
        "client_secret_post",
        "client_secret_jwt",
        "private_key_jwt"
    ],
    "introspection_endpoint": 
      "http://localhost:8080/oauth2/introspect",                  #4
    "introspection_endpoint_auth_methods_supported": [
        "client_secret_basic",
        "client_secret_post",
        "client_secret_jwt",
        "private_key_jwt"
    ],
    "subject_types_supported": [
        "public"
    ],
    "id_token_signing_alg_values_supported": [
        "RS256"
    ],
    "scopes_supported": [
        "openid"
    ]
}

The OpenID configuration document advertises the token endpoint, supported client-authentication methods, and supported grant types. section 14.2

How Spring Security in Action, Second Edition covers it

How deep it goes
Explains the POST request, authentication, required parameters, matching rules, and token response, but not endpoint implementation.
Examples
Uses a localhost cURL request with HTTP Basic authentication and a JSON response containing an access token and ID token.
What it assumes
Assumes an authorization code, registered client credentials, redirect URI, and code verifier are already available.
What you can do after
Apply it via an HTTP POST request that submits matching authorization-code parameters and authenticates the registered client.
How it connects
Connects authorization codes, authorization servers, clients, redirect URIs, PKCE, access tokens, ID tokens, and resource servers.

Also explained in

Compare how 3 books explain token endpoint →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.