Skip to content
Workforce IdentityMarkdown

Sign users in to a single-page app

Register a browser app that holds no secret, so users sign in through the realm and the page calls the realm directly.

APIRFC 6749, RFC 7636

An app that runs entirely in the browser, such as a dashboard with no server of its own, can’t keep a secret: anything in the page can be read by whoever opens it. You register it as a public client. It gets the same sign-in as a web app, proves it started the sign-in with PKCE alone, and calls the realm’s token, revocation and userinfo endpoints straight from the page.

Before you start:

  • Who can do it: a realm administrator, in a group that holds RealmOwner (Delegated administration). RealmViewer can 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: the realm offers the scopes the app needs (step 1 of Sign users in to a web app).
  1. Register the app as a public client:

    Terminal window
    curl 'https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client?id=ops-dashboard' \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{
    "status": "active",
    "clientName": "Ops Dashboard",
    "tokenEndpointAuthMethod": "none",
    "grantTypes": ["authorization_code", "refresh_token"],
    "redirectUris": ["https://ops.example.com/callback"],
    "postLogoutRedirectUris": ["https://ops.example.com/"],
    "scopes": ["openid", "profile", "offline_access", "ops:read"],
    "defaultScopes": ["openid", "ops:read"],
    "allowedResources": ["https://ops.example.com/api"],
    "defaultAudience": "https://ops.example.com/api"
    }'

    tokenEndpointAuthMethod: none makes it public; leave out clientSecret. refreshTokenRotation needs no setting, since a public client always rotates.

  2. If the page runs on a different site from its return address, list that site in webOrigins, keeping + for the return addresses’ own sites:

    Terminal window
    curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/ops-dashboard \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "webOrigins": ["+", "https://ops-app.example.com"] }'

    A site is written exactly as a browser sends it: scheme and host, a port only if it isn’t the default, no path. When the page runs on the same site as its return address, skip this step.

  3. Give the app its settings: the client ID ops-dashboard and the issuer https://foobar.cvyuh.com/oauth2. There’s no secret.

  • The page redeems the code at https://foobar.cvyuh.com/oauth2/token with its PKCE verifier and no secret.
  • The realm lets the page read the answer because the app’s site is one of its webOrigins. By default that’s the site of each registered return address (webOrigins: ["+"]). A page on any other site can’t read the answer. See Browser apps.
  • Each refresh token works once. Every refresh returns a new one, and if an old one is ever used again, the realm ends the whole family. That is how a stolen refresh token is caught.
  • A public app can never use client credentials.

Every sign-in must carry a PKCE challenge using the S256 method. A request without one, or with plain, is refused.

Users see the same as for a web app: the realm’s sign-in page, consent the first time, then back in the app.

Sign in from the page as a test user, and watch the token call in the browser’s developer tools: it should succeed with no CORS error. A CORS error means the page’s site isn’t in webOrigins.

Each sign-in is on the user’s trail as a LOGIN record and a TOKEN_ISSUED record for the client; a refresh token used twice is a TOKEN_ISSUED record with result FAILED and the reason “the refresh token was already used”. Find them in Audit → Authentication in the dashboard.

SymptomCauseFix
A CORS error on the token callThe page’s site isn’t in webOriginsAdd it exactly as the browser sends it (step 2)
invalid_client at the token endpointThe page sent a secret, or the client isn’t registered with noneSend no secret; register tokenEndpointAuthMethod: none
invalid_grant, “already used”, and the user is signed outTwo tabs refreshed with the same token, or a copy was usedRefresh from one place in the page; if neither, treat it as theft
The user is sent to sign in once a dayThe refresh family’s lifetime ran outExpected; see Keep apps signed in

PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/ops-dashboard with { "status": "inactive" } turns the app off.