Overview

Appendix B. OAuth2 grant types

OAuth2 is presented as a flexible authorization framework that helps applications authenticate and authorize users without forcing them to share passwords across services. The chapter frames the main challenge of modern web and cloud systems as enabling secure integration between different applications, often owned by different organizations, while limiting credential exposure. To address that challenge, OAuth2 uses several grant types, each designed for a different trust relationship and runtime environment.

The password grant and client credentials grant are the simplest flows because they are intended for trusted or closely related systems. In the password grant, a user’s credentials and the application’s own identity are sent to the authorization server, which returns an access token that the application later presents to protected services. In the client credentials grant, no user is involved; the application authenticates itself with its registered name and secret key to obtain a token for service-to-service access. Both approaches fit environments where the applications are controlled by the same organization and direct trust is acceptable.

The authorization code grant and implicit grant support less-trusted or browser-based scenarios. The authorization code grant is the most common for third-party integration because it keeps user credentials away from the external application: the user authenticates with the authorization server, receives a temporary code, and the client exchanges that code for an access token. The implicit grant is aimed at pure browser or JavaScript applications, but it exposes the access token directly to the client, making it more vulnerable and generally requiring short-lived tokens. The appendix also explains token refresh behavior, where expired access tokens can often be replaced using refresh tokens so users do not need to log in again, except in flows such as the implicit grant where refresh tokens are not supported.

Figure B.1. The OAuth2 service determines if the user accessing the service is an authenticated user.

Figure B.2. The client credential grant is for “no-user-involved” application authentication and authorization.

Figure B.3. The authentication code grant allows applications to share data without exposing user credentials.

Figure B.4. The implicit grant is used in a browser-based Single-Page Application (SPA) JavaScript application.

Figure B.5. The refresh token flow allows an application to get a new access token without forcing the user to re-authenticate.

FAQ

What is the main purpose of OAuth2 in microservice-based applications?OAuth2 provides a flexible authorization framework that lets applications authenticate and authorize users without forcing them to share their credentials with every application they use. It supports secure access to protected services through access tokens.
What are the four OAuth2 grant types covered in Appendix B?The four grant types are password, client credentials, authorization code, and implicit. Each one is used in different trust and application scenarios.
When is the OAuth2 password grant typically used?The password grant is used when the application and the services explicitly trust each other, usually because they are owned and managed by the same organization. The application can collect user credentials and authenticate directly with the OAuth2 service.
How does the password grant work in the EagleEye example?The user logs into the EagleEye application, which sends the user credentials plus the application name and secret key to the EagleEye OAuth2 service. The service authenticates both the user and the application, returns an access token, and protected services validate that token on each request.
What is the client credentials grant used for?The client credentials grant is used when no human user is involved in the transaction. It authenticates the application itself using only its registered name and secret key, then issues an access token for service-to-service calls.
What is the main difference between the password grant and the client credentials grant?In the password grant, both the user and the application are authenticated. In the client credentials grant, only the application is authenticated; there is no end user involved in the flow.
Why is the authorization code grant considered the most common OAuth2 flow?It is commonly used because it allows applications from different vendors to share data without exposing the user’s credentials to the calling application. It adds an extra step by issuing an authorization code first, rather than giving an access token immediately.
What role does the authorization code play in the authorization code grant?The authorization code is a temporary pre-access value returned after the user authenticates. The client application stores it and later exchanges it, along with its secret key, for an OAuth2 access token.
What is the implicit grant used for?The implicit grant is used for browser-based single-page applications or pure JavaScript clients that run entirely in the browser and do not rely on a server-side application to handle the flow.
How are expired OAuth2 access tokens refreshed?When an access token expires, the application receives a 401 response and then sends the refresh token to the OAuth2 server. The server validates the refresh token and issues a new access token without requiring the user to log in again.