One-time login tokens
Create secure single-use authentication links.
Use a one-time login token to establish a Unidy browser session for a person your application has already authenticated. A common use is opening the person's hosted Unidy profile from a custom application.
Navigate within ten seconds
Mint the token only when the customer chooses to navigate. It expires ten seconds after issuance and is consumed on redemption. After a failed or interrupted handoff, request a fresh token instead of retrying the same URL.
This is different from an emailed magic link. A one-time login token is not an email credential and is not intended to be stored for later use.
Choose the destination
| Destination | Use | Authentication result |
|---|---|---|
| A hosted Unidy page | The /one_time_login_tokens/unidy endpoint with an internal path. | Establishes the person's Unidy browser session and continues to the hosted page. |
| A registered application, with OAuth authorization skipped | The application handoff endpoint with skip_oauth_authorization: true. | Establishes the Unidy session, then redirects. It does not attach an authorization code or token for the destination application. |
| A registered application, with authorization enabled | The application handoff endpoint with skip_oauth_authorization: false. | Continues to Unidy's response_type=id_token authorization flow. This is not an Authorization Code exchange. |
For a new partner integration, use Authorization Code with PKCE to establish the partner's own application session. A handoff can establish the Unidy SSO session first, but the destination still needs its supported authentication flow.
Prerequisites
For the REST endpoints, obtain a user access token containing one_time_login_tokens:write. A client-credentials token cannot mint a login for an arbitrary person. The token is issued for the person authenticated by the request.
Obtain that token through the user's normal Authorization Code with PKCE sign-in, or the matching confidential-client flow. Request the minting scope before starting the handoff.
For an application destination, also obtain the target OAuth application's client ID and register the intended redirect URI on that application. URI matching follows the registered policy, including supported wildcard patterns; use an explicit callback whenever possible.
The SDK's jump operations authenticate with the user's SDK credentials and do not require this OAuth scope. Use the SDK authentication and session guide for that integration.
The SDK service-jump operation uses the application's internal identifier. The REST request below uses its OAuth client_id; these identifiers are not interchangeable.
Open a hosted Unidy page
Your backend makes the following request using the current person's access token:
POST /api/v1/one_time_login_tokens/unidy HTTP/1.1
Host: accounts.example.com
Authorization: Bearer USER_ACCESS_TOKEN
Content-Type: application/json
{"path":"/profile"}A successful request returns 201 with a token:
{"token":"b09cde26-9239-4b9d-9b0a-fb1264da4348"}The path must be an internal path beginning with a single slash. Values such as //other.example are rejected.
Return the token through your authenticated application's handoff endpoint, then navigate immediately:
async function openUnidyProfile() {
// Your endpoint authenticates the current user, protects this POST against
// CSRF as appropriate, and requests /one_time_login_tokens/unidy for them.
const response = await fetch('/api/unidy-profile-handoff', { method: 'POST' });
if (!response.ok) throw new Error('Could not open your Unidy profile.');
const { token } = await response.json();
if (typeof token !== 'string' || !token) {
throw new Error('Unidy did not return a handoff token.');
}
const target = new URL('/one_time_login', 'https://accounts.example.com');
target.searchParams.set('token', token);
window.location.assign(target.href);
}Call this from the customer's action and show any failure in your UI. Do not put the OAuth user access token in the navigation URL.
Continue to another application
The general endpoint accepts the target application's client ID, a registered redirect URI, optional scopes, and the authorization choice:
POST /api/v1/one_time_login_tokens HTTP/1.1
Host: accounts.example.com
Authorization: Bearer USER_ACCESS_TOKEN
Content-Type: application/json
{
"client_id": "TARGET_OAUTH_CLIENT_ID",
"redirect_uri": "https://shop.example.com/start-login",
"scopes": ["openid"],
"skip_oauth_authorization": true
}Redeem the returned token through /one_time_login as above. In this example, /start-login must initiate the shop's own supported OAuth sign-in. It receives a normal navigation after the Unidy session is established; the handoff does not itself create the shop's session.
If authorization is not skipped, the current handoff uses the ID-token response flow. Scopes default to openid and must belong to the target application. There is a current limitation when multiple scopes are forwarded in this branch. Use a single supported scope only if it satisfies the integration, or use the normal OAuth flow. Changing the skip flag is not an equivalent fix because it changes what authentication result reaches the application.
For that existing authorization-enabled integration, the destination normally receives #id_token=... in the fragment and must validate the ID token. When authorization is skipped, the scopes do not authorize the destination; its own OAuth request chooses the scopes.
Choose the application redirect at redemption
For an application handoff, an optional redirect_uri query parameter on /one_time_login overrides the URI stored when minting the token. URL-encode the complete value and keep it within that target application's registered redirect policy. The direct-redirect branch validates the override before redirecting; the authorization-enabled branch validates it during OAuth authorization.
Older instructions called this parameter redirect_url in one paragraph. Use redirect_uri; redirect_url is not the supported override. This option does not select the hosted-page destination: for that variant, set path when minting the token.
To return a customer to your app after a hosted profile edit, place the profile return parameters inside the /profile path supplied to the hosted-page endpoint.
Protect the handoff
- Treat the redemption URL as a credential. Do not email it, include it in analytics, or expose it to link scanners and prefetchers.
- Redact the
tokenquery parameter in logs. Referrer behavior depends on the browser and policy; configure a restrictive referrer policy for sensitive navigation. - Do not pre-generate tokens for a list of links. Mint on demand and navigate before the ten-second deadline.
- Request one handoff per navigation. The credential is consumed on redemption, but do not depend on an atomic concurrent-redemption guarantee.
- Grant minting access only to applications trusted to establish a browser session as that user. An administrator's handoff retains that administrator's account permissions.
Troubleshooting
| Response or outcome | Next step |
|---|---|
REST 401 | Check the user bearer token and WWW-Authenticate header. Do not depend on a JSON error body or a particular translation. |
REST 403 | Check the granted one_time_login_tokens:write scope and obtain a new access token if the grant changes. |
REST 400 for a non-user token | Use an access token issued for a signed-in user. |
422 application_not_found | Use the target application's OAuth client ID for the REST endpoint. |
422 invalid_redirect_uri | Check the target application's registered redirect policy. |
422 invalid_scope | Request scopes assigned to the target application. |
422 invalid_path | Supply a supported internal path for the Unidy-page variant. |
| Browser returns to login with an invalid-token message | Start again with a new token; check expiry, earlier redemption, scanners, and prefetching. An existing browser session can change the visible redirect outcome. |
| Destination opens but has no application session | Skipping authorization establishes only Unidy SSO. The destination must complete its own authentication. |