Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Native applications

The printer's phone app is a public client installed on Ava's phone. It signs her in through the system browser rather than a page it controls, redeems codes with PKCE and no secret, and keeps its refresh token 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 code 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 OAuth 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 session 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 authorization 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

The same sign-in page shown in a web view the printer app controls, and in the browser, which the app can neither inspect nor alter.

A public client on every phone

Every copy of the app is identical, so anything built into it, including a client secret, 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 HTTPS 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-app

Compare 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 token response gives the app an access token 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: revoke 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.

A developer wants to show the photo service's sign-in page in a web view inside the printer app. What is the main problem? 1 of 3

Choose one answer.

Why does the app's token request include a PKCE verifier but no client authentication? 2 of 3

Choose one answer.

The printing company wants its servers to build Ava's photo book while the app is closed. A developer suggests the app upload its photo service refresh token to them. What goes wrong? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity