liveBook · Manning

Grant type

As explained in Spring Security in Action, Second Edition

A grant type is an OAuth 2 protocol flow by which a client obtains a token from an authorization server.

A grant type is an OAuth 2 flow through which a client obtains an access token from an authorization server. The client then uses that token to request protected resources from a resource server. Short token lifetimes limit the impact of a lost token. section 13.1

Choose the flow according to whether a user authenticates and how the client is deployed:

  • Use the authorization code grant type when a user must authenticate; add PKCE to reduce the risk of stolen authorization codes and client credentials. section 13.3 section 13.6
  • Use the client credentials grant type when one backend service needs an access token without a user authenticating. section 13.3 section 16.3
  • Use refresh tokens when the application needs a new access token without requiring the user to authenticate again. section 13.6
  • Avoid implicit and password grant types; they are deprecated because they were found insufficiently secure. section 13.3

Backend service calling another backend

A proxy or backend client obtains an access token with the client credentials grant type, then sends authenticated requests to the other application. In Spring Security, a client manager executes the configured grant flow and obtains the token. section 16.3

Figure 13.3 The simplest explanation of the OAuth 2 authentication procedure involves the client obtaining a token from the authorization server. This token is then used to gain authorization for requests sent to the backend application, or resource server.

Trace the basic sequence: client obtains a token from the authorization server, then presents it when requesting authorization from the resource server. section 13.1

How Spring Security in Action, Second Edition covers it

How deep it goes
Defines the main flows and their security roles, but defers detailed protocol mechanics and implementation steps.
Examples
Contrasts user authentication, backend service authentication, token renewal, and deprecated implicit or password flows.
What it assumes
Assumes OAuth 2 participants and tokens, while establishing the roles of clients, authorization servers, and resource servers.
What you can do after
Evaluate which OAuth 2 grant type fits a user login, service integration, or access-token renewal requirement.
How it connects
Connects authorization servers, clients, resource servers, access tokens, authorization code, PKCE, client credentials, and refresh tokens.

Also explained in

Compare how 2 books explain grant type →

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.