liveBook · Manning

Authorization code flow

As explained in ASP.NET Core in Action, 3e

An authorization code is a short-lived intermediary credential that a client exchanges, together with appropriate authentication, for an access token.

The authorization code flow lets an application obtain an access token without handling the user’s service credentials. The user signs in with the provider, approves requested access, and returns with a short-lived authorization code. section 25.1.3

The flow proceeds in a small chain of handoffs:

  • Redirect the user to the provider, such as Facebook, for sign-in. section 25.1.3
  • Show a consent screen describing the data the application wants to access. section 25.1.3
  • Redirect back to the application with an authorization code. section 25.1.3
  • Exchange the code and a client-provider secret for an access token, then call the provider API. section 25.1.3

Dog photos from Facebook

A user asks dogphotos.com to retrieve dog photos from Facebook. Facebook handles sign-in and consent; dogphotos.com receives the authorization code, exchanges it for an access token, and uses that token to retrieve the photos. section 25.1.3

Figure 25.5 Using OAuth 2.0 to authorize dogphotos.com to access your photos on Facebook
CH25_F05_Lock3

Follow the sequence of redirects, consent, code exchange, and API access in the OAuth 2.0 flow diagram. section 25.1.3

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains the redirect, consent, callback, code exchange, and API call, but does not detail implementation code.
Examples
Uses dogphotos.com retrieving a user’s Facebook photos after consent and token exchange.
What it assumes
Assumes only a basic understanding of signing in, consent, redirects, tokens, and API calls.
What you can do after
Understand how to delegate API access through a provider without giving the application provider credentials.
How it connects
Connects authorization code flow with OAuth 2.0, access tokens, consent, provider APIs, and OpenID Connect.

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 ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.