Diagram example

OAuth 2.0 login sequence diagram

The authorization code flow with PKCE is the usual way for a web or mobile app to sign a user in through an identity provider. The diagram below shows each request in order; copy the Mermaid code into your design doc or README.

Updated

Authorization code flow with PKCE Edit and export
sequenceDiagram
  autonumber
  actor U as User
  participant App as Client app
  participant AS as Authorization server
  participant API as Resource API
  U->>App: Click "Sign in"
  App->>App: Create code_verifier and code_challenge
  App->>AS: Redirect to /authorize with code_challenge
  AS->>U: Login and consent screen
  U->>AS: Sign in and approve
  AS-->>App: Redirect back with authorization code
  App->>AS: POST /token with code and code_verifier
  AS->>AS: Check that the verifier matches the challenge
  AS-->>App: Access token (and refresh token)
  App->>API: GET /me with Bearer access token
  API-->>App: Profile data
  App-->>U: Signed in

Opens Arrowly with this process written as notes: change what differs in your team, and it redraws the diagram.

The steps, in plain words

#StepWhy it's there
1User clicks “Sign in”Starts the flow from the app.
2App creates a code_verifier (random secret) and its hashed form, the code_challengePKCE: proves later that the same app finishes the flow.
3Redirect to /authorize with the challengeThe user signs in on the provider's page, never in the app.
4–5Login and consentThe provider authenticates the user and records the permissions granted.
6Redirect back with an authorization codeShort-lived, single-use, useless without the verifier.
7App posts the code and the verifier to /tokenBack-channel exchange.
8Server checks the verifier against the challengeAn intercepted code alone can't be exchanged.
9Access token (and often a refresh token)The access token is short-lived; the refresh token gets new ones.
10–12App calls the API with Authorization: Bearer …The API validates the token and returns the user's data.

Adapting it to your system

  • OpenID Connect: the token response also carries an ID token. Add it to step 9: AS-->>App: ID token, access token, refresh token.
  • Backend for frontend: if a server exchanges the code, add a participant between the browser and the authorization server and move steps 7–9 to it.
  • Token refresh: add an opt access token expired block with the refresh call before the API request.
  • Keep the participants' display names generic (Authorization server, Resource API) unless the doc is about a specific provider.
Refresh block to append
  opt access token expired
    App->>AS: POST /token with refresh_token
    AS-->>App: New access token
  end

Draw your own flow from notes

Describe your login or integration in a few sentences. Arrowly draws the sequence diagram and gives you the Mermaid code to tweak. 3 free diagrams a day.

Draw my sequence diagram

Questions

Is PKCE only for mobile apps?

No. It was designed for apps that can't keep a secret (mobile, single-page apps), and current OAuth security guidance recommends it for every client using the authorization code flow.

Why not show the tokens' contents?

A sequence diagram is about who talks to whom. Put token fields in a table next to it; the diagram stays readable.