Client credentials, the device flow and refresh tokens
Client credentials for services, the device flow for TVs and command lines, never the password grant, and safe refresh tokens.
Diagrams in this video · 2Free in archhy
The diagrams, full size
Copy any of them into archhy, free, and change it for your own system.
After this lesson you can
- Use client credentials for service-to-service calls
- Walk the device authorization flow on the diagram
- Explain why the password grant must not be used
- Keep refresh tokens safe in a public client
Transcript
Client credentials, the device flow and refresh tokens
Space Llama here. So far, every flow had a person with a browser. Today, flows with no person, or no keyboard. Client credentials, the device flow, and the refresh token that keeps it all going.
Client credentials
When a backend job calls another service on its own behalf, there's no person to log in. The client authenticates directly at the token endpoint. With a secret, or better, a signed JSON Web Token, or mutual Transport Layer Security. It gets an access token. No redirect, no consent screen, and usually no refresh token. When it expires, the client just asks again.
The device flow
A smart TV or a terminal has no comfortable browser. The device flow, RFC 8628, moves the login to your phone. One. The device asks the device authorization endpoint, with its client ID and scope. Two. It gets two codes back: a device code to keep, and a short user code to show you. Three. The device shows you the user code, and a web address. Four. On your phone, you open the address, enter the code, log in and approve. Five. Meanwhile, the device polls the token endpoint. It hears authorization pending until you approve, and slow down if it polls too fast. Then the tokens arrive.
The password grant? Don't.
One flow you should never use: the resource owner password credentials grant. It lets an app collect your username and password, and trade them for a token. It teaches people to type passwords into apps, and it breaks multi-factor sign-in and single sign-on. RFC 9700 says it must not be used.
Refresh tokens
Access tokens should be short-lived, often just minutes. A refresh token lets the client get a new access token from the token endpoint, without sending you back through the login. Because it lives longer, it's the more valuable thing to steal. So for public clients, a refresh token must be sender-constrained, bound to a key the client holds, as DPoP, Demonstrating Proof of Possession, does. Or it must be rotated. Each use returns a new one, and replaying an old one is detected.
Which flow?
Let's recap with archhy's cheat sheet. A web app with a backend: the code flow with PKCE, the Proof Key for Code Exchange, and a secret or private key. Single-page, mobile and desktop apps: the code flow with PKCE, through the system browser. Service to service: client credentials. And a TV, console or command line: the device flow.
Your turn in archhy
Open these flows in archhy and change them for your own system. The link is below, with archhy's full article. Next lesson: OpenID Connect, and how an app finds out who signed in. See you there. More videos on the channel. Alpaca Mango. I'll be there. I'm always there. Mate.
Draw it in archhy
Open this lesson's diagram in archhy, ready to change for your own system. Free, in the browser.






