Native applications
The printer's phone app is a public clientAn OAuth client, such as code running in a browser or an app on a phone, that cannot keep a credential secret because the people using it can inspect it. It relies on protections such as PKCE instead of a client secret. installed on Ava's phone. It signs her in through the system browser rather than a page it controls, redeems codes with PKCEProof Key for Code Exchange, pronounced pixie: the client creates a secret for each authorization attempt, sends only a hash of it at the start, and proves it holds the secret when redeeming the code, so a stolen authorization code is useless to anyone else. and no secret, and keeps its refresh tokenA longer-lived credential that a client sends to the authorization server, never to an API, to get new access tokens without asking the person again. in the platform's secure storage.
Signing in through the browser
The printer's phone app lets Ava order prints from her phone. It is installed from an app store, runs on her device, and is registered with the photo service as its own public client, photo-printer-app. When she taps Connect photo account, the app needs what the website needed, an authorization codeA short-lived, single-use value that the authorization server sends back to a client through the browser. The client swaps it for tokens in a direct request to the authorization server; APIs never accept it. from the photo service, but it has no server-side callback page and no secret it can keep.
It also has an option the website never had. An app controls its own screens, so it could show the photo service's sign-in page inside one of them. That option is the first thing to rule out.
Mobile and desktop platforms let an app display web content in a web view, a browser component embedded in the app and controlled by it. A web view is convenient, and for OAuthA framework that lets a person give an application limited access to their resources at another service, using tokens instead of sharing their password. OAuth is about access; OpenID Connect adds sign-in. it is the wrong tool. The app that hosts it can read and change the page. It can record what Ava types into the sign-in form, including her photo account password, copy the photo service's sessionThe ongoing connection between later requests and an earlier sign-in, so you are not asked for your password on every click. It is often tracked with a cookie holding an unpredictable session identifier. cookies, and even approve the consent screen on her behalf. The whole point of the exchange is that the printer never handles her photo account credentials, and a web view hands them straight back.
It is worse for Ava in quieter ways too. A web view keeps its own cookies, separate from her browser, so she signs in from scratch even when she is already signed in to the photo service in her browser. And the app decides what to draw around the page. There is no address bar she can trust to show which site she is typing into, so a careful person has no way to check, and everyone else learns that typing a password into an unidentified page is normal.
Current guidance for native apps therefore requires the authorizationDeciding whether a requested action is permitted, such as whether a signed-in account may delete a particular photo. Authentication says which account is asking; authorization decides what it can do. request to run in an external user agent, normally the system browser, which the app can neither inspect nor alter. Switching to the browser app works. Most platforms also offer something smoother, an in-app browser tab, which appears over the app but is still the browser, with the browser's cookies and security checks and outside the app's control. ASWebAuthenticationSession on Apple platforms and Custom Tabs on Android are examples, and the guidance recommends them where they are available. Authorization servers may go further and refuse sign-ins they detect coming from a web view.
Embedded in the app and controlled by it
- Can record what Ava types, including her password
- Can copy session cookies and approve consent for her
- Its own cookies: she signs in from scratch
- No address bar she can trust
Or an in-app browser tab
- The app can neither inspect nor alter the page
- The browser's cookies and security checks
- The browser shows which site she is typing into
What current guidance requires
A public client on every phone
Every copy of the app is identical, so anything built into it, including a client secretA shared secret that a confidential client uses to prove itself to the authorization server, much like a password for an application. It belongs on a backend, never in code sent to browsers or phones., can be extracted from any one copy. The photo service registers photo-printer-app as a public client with no secret, and requires PKCE from it. The authorization request has the same shape as the website's, with the app's client ID, its own redirect URI, and a challenge made from a fresh verifier.
The response then has to find its way from the browser back into the app. The Redirect URIs and client metadata lesson described the three ways installed applications receive it: a claimed HTTPSHTTP protected by TLS, so traffic is encrypted and checked for changes while it travels. It protects the connection, but does not prove that the site at the other end is honest. address that the operating system has verified belongs to the app, a private-use URI scheme, and a loopback address on desktop systems. The phone app uses its claimed address, https://app.printer.example/oauth/callback. When the browser reaches it, the system hands the response to the app, which checks state and the issuer against its pending attempt exactly as the website does.
The app then redeems the code itself. All domains, tokens and keys in these examples are fictional.
POST /token HTTP/1.1
Host: auth.photos.example
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code
&code=demo-code-12
&redirect_uri=https%3A%2F%2Fapp.printer.example%2Foauth%2Fcallback
&code_verifier=btl_training_verifier_for_the_phone_app_only_2026
&client_id=photo-printer-appCompare it with the website's request. There is no Authorization header, because the app has no credential to authenticate with. It names itself with client_id, and the verifier is the only proof that this copy of the app started the attempt. A code intercepted on its way back, for example by another app that registered the same private-use scheme, is useless without it.
The missing credential has one more consequence. Any software can send a request that claims to be photo-printer-app, so the photo service cannot be sure which app it is dealing with. Current guidance says it should not approve such a request silently just because Ava approved the app before, and should treat the request as new unless it can confirm the app's identity. A claimed HTTPS redirect can serve as that confirmation, since only the genuine app can receive responses at that address.
Keeping tokens on the device
The tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. response gives the app an access tokenA token that a client presents to an API to use access it has been granted, usually limited in what it allows and how long it lasts. It authorizes API calls; it does not tell the client who signed in. and, when the photo service allows continued access, a refresh token. The app needs that refresh token next week, so it has to store it somewhere that survives the app being closed.
Apps have private files that other apps cannot read, but ordinary files are copied into backups and can be read by anything that gains access to the app's storage. The platforms offer better places. On Apple platforms that is the Keychain, which holds small secrets such as tokens, encrypted by the system, and can restrict an item to this device so that it is not restored onto a different phone from a backup. On Android, the app usually encrypts the token with a key held in the Android Keystore, which keeps the key itself out of the app's files, and stores only the encrypted value.
Because the app is a public client, the photo service also rotates its refresh tokens, the protection the lesson on the refresh token grant described for clients that cannot authenticate. The app saves each replacement in secure storage as soon as it arrives.
Signing out of the app works like Disconnect on the website: revokeCancelling a credential, token, certificate, or authenticator before it would expire, so that it is no longer accepted. Whether every copy stops working at once depends on how services check it. the refresh token at the photo service, then delete both tokens from storage. If Ava deletes the app without signing out, the refresh token remains valid at the photo service until it expires or she removes the app from her list of connected applications there.
One registration still covers every installation of the app. Some services go further, registering each installation as a separate client with credentials of its own, or asking the platform to attest that a request comes from a genuine, unmodified copy of the app. Advanced OAuth covers per-installation registration in Registering a client dynamically.
An app with a backend of its own
The app does more than talk to the photo service. Ava's print orders, saved photo books and delivery address live on the printing company's own servers, behind an API at https://api.printer.example, and the app calls that too. Two relationships are now in play, and keeping them apart avoids a tempting shortcut.
Toward the photo service, nothing changes because the printing company has servers. The app is still the public client photo-printer-app, it still uses PKCE, and the response still comes back to the app on the phone, at its claimed HTTPS address or, where that is not possible, at a private-use scheme. A loopback listener, which suits desktop programs, does not belong on a phone, where the app has claimed addresses and schemes for exactly this purpose.
Toward the app, the printing company's API is a resource server of its own. When the app places an order, it presents a token issued for api.printer.example, by whichever authorization server the printing company uses for its own accounts, or, in a simpler design, a session credential that the printing company's backend issued after signing her in as its own confidential client. Either way, the printer's API accepts only credentials meant for it.
The shortcut is for the app to send its photo service tokens to the printing company's servers, so that they can fetch the photos for a book while the app is closed. It breaks something on every side. The access token was issued for the photo API, so the printer's servers would be using a bearer credential they merely received, and the printer's API should never treat it as proof of who is calling, for the reasons Scopes and audiences gave. A refresh token issued to a public client would sit on a server the photo service knows nothing about, and as soon as both the app and the server refresh with it, rotation reports reuse and ends the connection for both.
When the printing company's servers need Ava's photos themselves, they get access of their own. The backend is registered with the photo service as a confidential client, as the printer's website already is, and either sends Ava through the photo service once to approve it, with the response returning to the backend, or, where the photo service allows it, exchanges a token from the app for one issued to the backend, using the token exchange described in Service-to-service access. The photo service then decides what the backend may have, the backend's tokens are bound to its own credential, and removing one connection does not silently break the other.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Sign a desktop app in through the system browser with PKCESign the printer app in through your real browser, redeem codes with only a verifier, receive one at a private-use scheme, stop silent approval, store the refresh token safely and sign out by revoking.