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
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 inOpens Arrowly with this process written as notes: change what differs in your team, and it redraws the diagram.
The steps, in plain words
| # | Step | Why it's there |
|---|---|---|
| 1 | User clicks “Sign in” | Starts the flow from the app. |
| 2 | App creates a code_verifier (random secret) and its hashed form, the code_challenge | PKCE: proves later that the same app finishes the flow. |
| 3 | Redirect to /authorize with the challenge | The user signs in on the provider's page, never in the app. |
| 4–5 | Login and consent | The provider authenticates the user and records the permissions granted. |
| 6 | Redirect back with an authorization code | Short-lived, single-use, useless without the verifier. |
| 7 | App posts the code and the verifier to /token | Back-channel exchange. |
| 8 | Server checks the verifier against the challenge | An intercepted code alone can't be exchanged. |
| 9 | Access token (and often a refresh token) | The access token is short-lived; the refresh token gets new ones. |
| 10–12 | App 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 expiredblock 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.
opt access token expired
App->>AS: POST /token with refresh_token
AS-->>App: New access token
endDraw 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 diagramQuestions
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.