Authentication and authorization architecture

A UML sequence diagram of sign-in with OpenID Connect and PKCE, an API call with an access token, and a policy service that allows or refuses.

By ArchynoSecurity and identityUpdated November 29, 2026Diagrams: 1Elements: 7Relationships: 11

Licensed under CC BY 4.0: reuse and change it, and credit Archyno

Created with Archyno

Use this template

It opens in the editor as an editable model. No account is needed to change and export it. A free account saves it. Keep the credit to the author.

Open and customize

When this architecture fits

Use it for a web or mobile app with its own API, where users sign in through an identity server: your own, or a hosted one. It keeps two questions apart. Authentication asks who you are and happens once. Authorization asks what you may do and happens on every call.

What happens, step by step

Read the diagram from the top. The password goes to the identity server only.

  • The app starts the authorization code flow with PKCE, so a stolen code is useless without the app's secret value.
  • The user enters a password and a second factor on the identity server's own page.
  • The app swaps the code for an ID token, for itself, and an access token, for the API.
  • The API checks the signature, the issuer, the audience and the expiry of the token.
  • Then it asks the policy service. The answer is 200 or 403. A missing or bad token is 401.

Change these parts first

The flow stays the same in most systems. The decisions around it do not.

  • Token lifetime: short for access tokens, longer for refresh tokens, and a way to end both.
  • The model of rights: roles, attributes, relationships, or a mix.
  • Where the check runs: a service as here, a library in the API, or the database.

Common mistakes

An ID token is not a key to the API. Hiding a button is not authorization, because the call still works. A check of the role without a check of the owner lets any user read another user's order by its number. And tokens in the browser's local storage can be read by any script on the page.

What is in this model

APILifeline
Holds the data. Checks the token on every call.
Identity serverLifeline
Checks who the user is and issues the tokens (OpenID Connect).
Policy serviceLifeline
Decides what this user may do, from roles and attributes.
UserLifeline
The person who signs in.
Web appLifeline
The client. It never sees the password.
alt [allowed]Combined fragment
No description.
alt [refused]Combined fragment
No description.