Amazon Cognito OAuth 2.0 Grants

  • Tue Jan 17 2023
  • Admin

Amazon Cognito OAuth 2.0 Grants: Supported Types and How They Work

If you're looking to use Amazon Cognito for authentication and authorization in your web or mobile app, you'll need to understand the different types of OAuth 2.0 grants supported by the service. In this blog post, we'll take a look at each of those grant types and explain how they work.

Three Types Of Grants

Amazon Cognito supports the following three types of OAuth 2.0 grants:

  • Authorization code grant
  • Implicit grant
  • Client credentials grant

Authorization Code Grant

The Authorization Code Grant is a secure authorization method used to provide end-users with access tokens. It works by not exposing the access token, but rather providing an authorization code instead. This code is then used by the end user to request an access token from Amazon Cognito, which is then passed back to the application. This provides an additional layer of security, as the application never has direct access to the user's credentials.

  • An application makes an HTTP GET request to https://AUTH_DOMAIN/oauth2/authorize
  • User is redirected to the IDP authentication page or native pool hosted UI for login
  • User authenticates with their IDP/User pool
  • Cognito verifies the user credentials and redirects user to the URL that was specified in the original redirect_uri query parameter. A code query parameter is also set that specifies the authorization code generated for the user by Cognito
  • The custom application that’s hosted at the redirect URL can now extract the authorization code from the query parameters and exchange it for user pool tokens
  • The custom application uses the access token to make requests to the resource server


T12: Automated Security Monitoring For Your AWS Account

T12 provides comprehensive automated security monitoring for your AWS, Azure and GCP Accounts. Create an account and get started today for free: t12.io

Implicit Grant

Amazon Cognito's Implicit Grant is an OAuth2-based authorization flow that provides access to user pool resources without the need for additional authentication. It is designed to improve the user experience and reduce the number of requests to obtain an access token.

The Implicit Grant flow makes use of an id_token, which is a JSON Web Token (JWT) containing identity information about a user, such as their name or email address. This id_token is used in exchange for the desired resource, often times an API endpoint.

The Implicit Grant flow also allows for other types of tokens such as access tokens, refresh tokens and session tokens, depending on the application's requirements. Compared to Authorization Code Grant, Implicit Grant is less secure since it exposes user pool access tokens directly to end users. However, if Authorization Code Grant cannot be used then Implicit Grant can be beneficial due to its faster request time and improved user experience over Basic Authentication.

  • An application makes an HTTP GET request to https://AUTH_DOMAIN/oauth2/authorize
  • User is redirected to the IDP authentication page or native pool hosted UI for login
  • User authenticates with their IDP/User pool
  • Cognito verifies the user credentials and redirects user to the URL that was specified in the original redirect_uri query parameter. An access_token query parameter along with few others (id_token, expires_in and token_type) are passed in the redirect
  • The custom application that’s hosted at the redirect URL can now extract the access_token and id_token from the query_parameters
  • The custom application uses the access token to make requests to the resource server


T12: Automated Security Scanning For Your AWS Accounts

Is your AWS Account secure? Find out today by running a free security assessment: t12.io

Client Credentials Grant

This specific grant is designed for machine-to-machine interactions; It is much simpler and more straightforward than other authorization flows, allowing machines to communicate securely without the need for user interaction.

With Amazon Cognito Client Credentials Grant, you can use two different types of authentication: public client authentication and confidential client authentication. When using public client authentication, developers don’t need to keep any secure information on the device. Instead, they are able to use a publicly available token issued by a third party such as AWS Identity Provider.

On the other hand, when using confidential client authentication, developers must store a secure client ID and secret on the device. This allows them to identify themselves to Amazon Cognito and receive an access token in return.

  • An application makes an HTTP POST request to https://AUTH_DOMAIN/oauth2/token
  • The Cognito auth server returns a JSON object with an access_token field along with few others(expires_in, token_type)
  • Application uses the access token to make requests to the resource server