liveBook · Manning

Authorization code flow

As explained in Software Security for Developers

The authorization code flow is an OAuth flow in which a client obtains an authorization code through user authorization and exchanges it for an access token.

The authorization code flow lets a client access a user's backend data without receiving the user's credentials. The user authenticates at an identity provider (IdP), which returns a one-time authorization code; the client exchanges that code for an access token and presents the token to the resource server. Sending the token directly through the redirect would expose it to browser history or logs. section 12.2.1 section 12.4

The flow coordinates four actors:

  • The user requests protected data from the client application. section 12.2.1
  • The client redirects the user to the IdP, where the user logs in. section 12.2.1
  • The IdP redirects back with a unique, one-time authorization code. section 12.2.1
  • The client sends the code to the IdP's token endpoint, receives an access token, and uses it to call the resource server. section 12.2.1

ACME shopping list

For ACME, the client discovers the IdP's authorization and token endpoints, redirects the browser to /oauth2/authorize?response_type=code, receives a callback containing code=..., and uses cURL at /oauth2/token with grant_type=authorization_code to obtain an access token. The client then presents that token when requesting the shopping list. section 12.3

How Software Security for Developers covers it

How deep it goes
Explains actors, redirects, one-time codes, token exchange, and token validation, while deferring protocol internals.
Examples
Uses an ACME shopping-list scenario, localhost OIDC endpoints, browser redirects, YAML configuration, and cURL token requests.
What it assumes
Introduces the user, client, identity provider, and resource server before explaining the authorization-code exchange.
What you can do after
Apply it via browser redirects and cURL to obtain an access token without placing that token in the redirect.
How it connects
Connects OAuth2 and OpenID Connect with single sign-on, identity providers, resource servers, access tokens, JWTs, and token introspection.

Also explained in

Compare how 8 books explain authorization code flow →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Security for Developers. The section links point to the parts of the book it draws on.