SecurityOAuthOAuth 2.1authorization code flowscopesdelegated authorization

OAuth 2.0

Definition

OAuth 2.0 (RFC 6749) defines how a client obtains access tokens from an authorization server, with the resource owner's consent, to call a resource server within limited scopes; OAuth 2.1 consolidates it with PKCE and current security practice.

In practice

The standard flow for apps acting for a user is the authorization code flow with PKCE: the browser is redirected to the authorization server, the user logs in and consents to scopes, a one-time code comes back, and the client exchanges it over the back channel for an access token and usually a refresh token. Client credentials cover machine-to-machine calls; the device grant covers TVs and CLIs.

OAuth is authorization, not login: an access token is not proof of who the user is, which is why OpenID Connect exists. Scopes cap what the client may do; the API still checks what the user may access. OAuth 2.1 drops the implicit and password grants and requires exact redirect URI matching; RFC 9700 is the current security best practice.

Example

A calendar app requests scope=calendar.read; after consent it calls GET /events with Authorization: Bearer eyJ..., and a request without that scope gets 403 with error="insufficient_scope".