Cloud concept · Updated

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.

In short

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.

Cloud Concepts Hub →

6 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.

01
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.

02
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.

03
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.

04
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.

05
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.

06
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 CognitoAmazon 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.

Amazon API GatewayAmazon 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.

AWS LambdaAWS 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.

AWS Secrets ManagerAWS 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.

OAuth 2.0 exam questions

Real practice exam questions on OAuth 2.0, with the correct answer and its explanation. Answer them with every option in the exam simulator.

DVA-C02

A company is developing a native mobile application that uses an Amazon Cognito user pool for employee sign-in. The application must obtain bearer access tokens to call an API on behalf of the signed-in employee. Sign-in occurs in the system browser, which redirects to the application's registered custom URI scheme. Redirect URI validation and state parameter checks are already implemented.

A security review identifies that another application on the device could intercept the redirect containing the authorization code. The company does not operate a backend token broker, and secrets embedded in the mobile application cannot be considered confidential.

Which implementation prevents an application that intercepts only the authorization code from exchanging it for tokens?

Show answerCORRECT ANSWER

Use the authorization code grant with PKCE and an app client without a secret. Generate a random code verifier for each authorization request, send its S256 challenge in the request, and supply the original verifier when exchanging the code over HTTPS.

PKCE binds the authorization code to a verifier retained by the initiating application. Cognito checks that the verifier supplied during token exchange matches the original challenge. An application that intercepts only the code cannot redeem it without the verifier, and the mobile application does not need a client secret.

Practice OAuth 2.0 in a full exam

Questions on OAuth 2.0 in each practice exam, with every answer option and an explanation for each:

Start a free practice exam

What is OAuth 2.0

3 min read

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.

Learn OAuth 2.0 in lessons

3 short lessons on OAuth 2.0 in 1 certification course.

Open the lessons