Sign users in to your own native app
Let your own mobile or desktop app sign users in with its own screens, without opening a browser.
APIOAuth 2.0 for First-Party Applications (draft)
Your organization’s own mobile or desktop app can show its own sign-in screens and walk users through the realm’s sign-in steps: username and password, then a one-time code if the realm asks for one. At the end it gets a code and exchanges it for tokens, as any app does. No browser opens.
Before you start:
- Who can do it: a realm administrator, in a group that holds
RealmOwner(Delegated administration).RealmViewercan read the settings but not change them. - Where: today this is done through the API; Call the API shows how to get
$CVYUH_SESSION. - First: be sure the app is truly your organization’s own.
Set it up
Section titled “Set it up”-
Allow first-party sign-in in the realm:
Terminal window curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \-H "Content-Type: application/json" \-d '{ "firstPartyAppsAllowed": true }' -
Register the app and mark it as yours with
firstParty:Terminal window curl 'https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client?id=field-app' \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \-H "Content-Type: application/json" \-d '{"status": "active","clientName": "Field App","tokenEndpointAuthMethod": "none","firstParty": true,"grantTypes": ["authorization_code", "refresh_token"],"scopes": ["openid", "profile", "offline_access", "field:read"],"defaultScopes": ["openid", "field:read"],"allowedResources": ["https://field.example.com/api"],"defaultAudience": "https://field.example.com/api"}' -
Optionally, offer a stronger sign-in by name: map an
acrvalue to a sign-in chain, as in Step up for sensitive actions.
How the app signs a user in
Section titled “How the app signs a user in”- The app starts at
POST https://foobar.cvyuh.com/oauth2/authorize-challengewith what a browser sign-in carries: scopes, the API it wants, and its PKCE challenge. - The realm answers
insufficient_authorizationwith the next step to show, and anauth_sessionto send back with the answers. - The app repeats until the realm answers with a
code. A failed sign-in isaccess_denied. - The app redeems the code at the token endpoint.
The user sees the app’s own screens, one for each step the realm asks for: a two-step sign-in takes two screens. There’s no consent page, because the app and the realm are one party. The exception is offline access, which the user must have allowed earlier through the browser sign-in.
Good to know
Section titled “Good to know”- Each
auth_sessionis answered once, by this app only, within ten minutes. - A sign-in begun with a DPoP proof must use the same key throughout.
- The session is real: signing out ends it.
- An agent’s client is always refused, whatever it is marked.
Check it worked
Section titled “Check it worked”Sign in through the app as a test user. A wrong password should be refused, and a right one should end in a code.
Each step is on the user’s trail as with a browser sign-in (LOGIN_STARTED, MODULE_COMPLETED, then LOGIN or
LOGIN_FAILED), and a wrong password counts toward Lockout. Find them in
Audit → Authentication in the dashboard.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Fix |
|---|---|---|
unauthorized_client, “may not sign a person in without a browser” | firstPartyAppsAllowed is off, or the client isn’t firstParty | Do steps 1 and 2 |
unauthorized_client for an agent’s client | An agent never signs a person in this way | Use Let an agent act for a user |
unauthorized_client, “may not use the authorization code grant” | The realm or the client lacks authorization_code | Add it to the client’s grantTypes |
An old auth_session is refused | It was answered already, or ten minutes passed | Start the sign-in again |
| No refresh token | Offline access must first be allowed through the browser sign-in | Have the user allow it once in the browser |
Undo it
Section titled “Undo it”Set the client’s firstParty to false, or the realm’s firstPartyAppsAllowed to false to stop it for every app.
Related
Section titled “Related”- First-party app sign-in: the capability, its settings and errors.
- Authorization code with PKCE: the code the app redeems.
- Step up for sensitive actions: a stronger sign-in by name.