CLOUD CONCEPT

OAuth 2.0

OAuth 2.0 is an authorization framework that lets applications obtain limited access to protected resources using access tokens rather than a resource owner's credentials.

Cloud Concepts Hub →

What is OAuth 2.0

OAuth 2.0 separates the application requesting access, the server issuing tokens, and the API enforcing permissions. In cloud applications, it enables scoped API access for users and workloads, but bearer tokens must be protected because possession is generally sufficient to use them.

OAuth 2.0 defines how a client obtains authorization to access a protected resource. Its principal roles are the resource owner, client, authorization server, and resource server. For example, a user authorizes a reporting application to read invoices, an authorization server issues an access token, and an invoice API accepts that token only for permitted operations. The client does not need to collect the user's password for the invoice system.

A common implementation uses bearer access tokens. The client sends a request with an Authorization header whose value is Bearer followed by the access token. A bearer token normally does not require the caller to prove possession of a separate cryptographic key, so a stolen token can be replayed until it expires or is otherwise rejected. Use HTTPS for authorization, token exchange, and API requests. Do not place access tokens in URLs, application logs, analytics events, or source code.

For browser and mobile applications, use the authorization code flow with Proof Key for Code Exchange, or PKCE. The application starts an authorization request, the user authenticates with the authorization server, and the application exchanges the returned code for tokens using its PKCE verifier. PKCE protects against intercepted authorization codes. Public clients cannot safely keep a client secret; embedding one in a mobile application or JavaScript bundle does not make it confidential. Validate redirect URIs strictly and use appropriate request correlation and CSRF protections, commonly including the state parameter. Avoid the legacy implicit and resource owner password credentials flows.

For service-to-service access without a user, a confidential client can use the client credentials grant. For example, a scheduled reporting job can authenticate to a token endpoint and receive an access token restricted to invoice-reading permissions. This represents the application's own authorization, not delegated authority from a signed-in user. Store client credentials in a managed secret store and rotate them rather than hard-coding them.

The resource server must validate the token before accepting a request. OAuth 2.0 does not require access tokens to be JSON Web Tokens, or JWTs. For a JWT access token, verify its signature with trusted issuer keys, restrict accepted algorithms, and validate the issuer, expiration, intended audience or applicable client binding, and required scopes. For an opaque token, an authorization server may provide an introspection endpoint. Merely decoding a JWT is not validation, and a signed JWT is not necessarily encrypted.

Scopes express permissions such as invoices.read, but they do not replace application-level authorization. A valid token with a read scope must not automatically allow access to every customer's invoices. The API must also enforce tenant boundaries, resource ownership, and business rules. Invalid or expired credentials generally produce HTTP 401, while valid credentials lacking sufficient permission generally produce HTTP 403.

Short access-token lifetimes reduce the window for replay but increase token renewal traffic. Refresh tokens can obtain replacement access tokens without repeating interactive authorization; protect them more carefully, and use rotation where supported. Revoking a refresh token does not guarantee that every API immediately rejects an already-issued access token, particularly when JWT validation is performed locally.

OAuth 2.0 is authorization, not an identity protocol. OpenID Connect adds an authentication layer and ID tokens; an ID token is not a substitute for an API access token. On AWS, a common design uses Amazon Cognito user pools to issue tokens and Amazon API Gateway to validate them and enforce scopes before invoking application code. This differs from AWS IAM authorization: an OAuth bearer token does not generally replace the AWS credentials and Signature Version 4 signing required for AWS service API calls.

Key aspects of OAuth 2.0

OAuth 2.0 enables limited token-based access when applications choose appropriate grants, protect tokens, validate them correctly, and enforce resource-level permissions.

Separation of authorization roles

The client requests access, the authorization server issues tokens, and the resource server enforces access. This separation lets multiple APIs trust a central issuer without handling users' passwords themselves.

Bearer-token security

Possession of a bearer token is generally enough to exercise its permissions. Use HTTPS, prevent token leakage, and keep access-token lifetimes short enough to limit replay exposure.

Scoped and resource-specific access

Request only the scopes the application needs and issue tokens intended for the correct resource server. APIs must additionally enforce ownership, tenant isolation, and business rules.

Grant selection by client type

Use authorization code with PKCE for interactive public clients and client credentials for suitable machine-to-machine clients. A client secret embedded in a browser or mobile application cannot be treated as confidential.

Token validation and lifecycle

Validate tokens rather than merely parsing them, including issuer, expiration, intended recipient, and permissions. Plan for signing-key rotation, renewal, and the limits of revoking tokens that APIs validate locally.

Authorization distinct from authentication

OAuth access tokens authorize access to APIs; OpenID Connect ID tokens convey authentication information to clients. Neither should be confused with AWS IAM credentials used to sign AWS service requests.

Cloud services for OAuth 2.0

Amazon Cognito user pools can issue access tokens after user authorization or confidential-client authentication. Clients present those tokens to Amazon API Gateway, where a supported authorizer validates them and enforces configured scopes before forwarding requests. AWS Lambda backends then apply resource ownership and tenant-specific authorization. When token formats or validation rules require custom handling, a Lambda authorizer can perform those checks. AWS Secrets Manager protects client secrets used by confidential workloads. Together, these services separate token issuance, credential storage, gateway enforcement, and application-specific permission decisions.

Amazon Cognito image Amazon Cognito

Amazon Cognito user pools provide OAuth 2.0 authorization and token endpoints, including authorization code and client credentials flows. Configure application clients, resource-server scopes, and token lifetimes to match the application's access requirements; identity pools serve a different purpose by providing temporary AWS credentials.

Open Amazon Cognito →
Amazon API Gateway image Amazon API Gateway

HTTP API JWT authorizers validate supported JWT access tokens and can enforce route scopes. REST APIs can use Cognito user pool authorizers with method scopes, while Lambda authorizers support custom token validation and authorization logic.

Open Amazon API Gateway →
AWS Lambda image AWS Lambda

A Lambda authorizer can implement custom bearer-token checks, including introspection of opaque tokens when the issuer supports it. Backend Lambda functions can enforce ownership and tenant rules using trusted authorization context, with authorizer caching configured to avoid reusing decisions beyond their intended scope.

Open AWS Lambda →
AWS Secrets Manager image AWS Secrets Manager

Secrets Manager can store OAuth client secrets used by confidential backend applications. Workloads retrieve these secrets using IAM permissions; any rotation process must coordinate changes with the authorization server rather than assuming that storing the secret rotates it automatically.

Open AWS Secrets Manager →