Mobile and desktop
Sign users in to a native mobile or desktop application with onefold as a public client, using the system browser, PKCE and a redirect URI the application can receive.
A native application signs users in the same way a web application does, with two differences: it is a public client, and its redirect URI is one the application itself can receive.
Prerequisites
- An application with Public Client turned on
- A redirect URI registered for it, as below
Set up
Make it a public client
Anything shipped to a device can be extracted from it, so a native application must not hold a client secret. Turn on Public Client on the application's OAuth2 tab. A public client authenticates at the token endpoint with its client ID alone.
Choose a redirect URI
Register a redirect URI the application can receive.
| Kind | Example | Notes |
|---|---|---|
| The application's own scheme | com.example.app://callback | Write the scheme://host form. com.example.app:/callback, with one slash, is refused. |
An https link the operating system opens in your application | https://app.example.com/callback | An App Link or Universal Link |
| A loopback address | http://127.0.0.1:53682/callback | For desktop applications. Register the exact URI, including the port. |
Redirect URIs are matched exactly, so a loopback redirect needs a fixed port that you register.
Authorization
Open the authorization request in the system browser, not in an embedded web view. The system browser has the user's existing onefold session and their passkeys, and keeps their credentials out of your application.
Use PKCE with S256 on every sign-in, with a new verifier each time. Any application on a
device can claim the same custom scheme. PKCE is what stops another application from using a
code it intercepts.
Callback
The operating system hands the redirect to your application. Read code and state from the
URL, check state, and accept the iss parameter.
Token handling
Exchange the code at the token endpoint with client_id,
code, redirect_uri and code_verifier. Do not send a client_secret.
Store the refresh token in the platform's secure storage: the Keychain on Apple platforms, the Keystore on Android, or the operating system's credential store on desktop. Keep the access token in memory.
Refresh as a public client the same way: client_id and
refresh_token, and no secret. Save the new refresh token each time.
User identity
Verify the ID token and use sub as the user's
identifier.
Session handling
Your application decides how long a user stays signed in. To sign out, revoke the refresh token and delete what you stored.
Production notes
- Register separate applications for development and production builds.
- Do not embed a client secret, an API key or a webhook secret in a shipped application.
- If your application has a backend, call the backend with the access token and let the backend verify it. See Protect your API.