Skip to main content
Use this when your product runs on the user’s device: a command-line tool, a desktop app, or a mobile app. Anything shipped to a device can be inspected, so these apps have no client secret. PKCE proves that the app that started the sign-in is the one finishing it. You need a CLI, desktop, or mobile app from the OAuth apps page. You can ship its client ID in your app. It is not a secret. The consent screen always shows a caution for these apps, even after your app is verified, because any program on the device could present your client ID. Ask users to start sign-in from your app.

Pick a redirect URI

The host and path must match what you registered. localhost and 127.0.0.1 are different hosts, so use the same one in both places.

Sign in from a CLI

This example starts a temporary local server, prints the sign-in link, waits for the callback, and exchanges the code. It ignores any request that doesn’t carry its state, so only the real callback ends the wait. It gives up after five minutes, which is how long the consent screen stays valid, and it closes each connection after replying so the process can exit as soon as sign-in finishes. It needs Node.js 20 or later and no dependencies.
login.mjs
The token request has no client_secret. Everything else matches a server app, so refreshing, errors, and disconnecting work as described for web products, without the secret.

Store tokens on the device

Keep the refresh token in the operating system’s credential store: Keychain on macOS and iOS, Credential Manager on Windows, encrypted storage on Android, or the Secret Service on Linux. Avoid plain files, shell history, and logs.

Several devices

A person can sign in on more than one device. Every device gets its own tokens, and devices that asked for the same scopes share one connection, so:
  • Signing in on a new device does not sign out the others.
  • Disconnecting, from your app or from the user’s Connected apps page, signs out every device.
  • Each device must keep its own refresh token up to date. Reusing a refresh token more than a minute after it was replaced ends the connection for every device.