Use this page for request-level auth handling after you choose an authentication pattern. For the high-level comparison of embedded, Azure OIDC, and API auth, use Authentication.
Supported implementation paths
Recommended flow
1
Establish sign-in context
Complete the Azure OIDC sign-in flow or embedded token exchange and confirm that the returned session belongs to the expected tenant user.
2
Store only active access state
Keep short-lived access credentials in a controlled runtime store. The current web client persists access and refresh tokens through state storage; if your integration does the same, ensure the store is not exposed to untrusted code. Do not store long-lived secrets in browser local storage.
3
Call protected capabilities
Attach the active Narrative-issued internal access token to protected runtime requests and keep tenant scope checks close to the request boundary.
4
Handle expiry with one bounded refresh
If the platform returns
401 Unauthorized, request a fresh access token once and retry the failed request once.5
Sign out and clear state
Clear client auth state, attempt server-side revoke where supported, and force the next access attempt through sign-in again.
Azure OIDC auth flow
Azure OIDC auth applies when the user signs in through the configured Azure AD OIDC flow instead of receiving an Embed Token from a tenant application. This is the current non-embedded sign-in path supported by the platform.Azure OIDC implementation guidance
- Azure AD handles credential collection; the platform receives verified identity claims via the callback.
- Narrative-managed email registration requires explicit Terms of Service and Privacy Policy acknowledgement before a new user can complete registration.
- Treat the returned access credential as short-lived runtime state.
- Re-authenticate if sign-in fails or if refresh cannot restore a valid session.
API request handling
Request pattern
Protected Narrative SDK APIs accept only Narrative-issued internal access tokens. Do not send raw identity-provider access tokens directly to these endpoints.JavaScript
Controlled refresh pattern
JavaScript
Token lifecycle handling
Acquisition
- Start only after a successful embedded token exchange or Azure OIDC sign-in.
- Bind the credential to the expected tenant and user context.
- Do not reuse bootstrap or sign-in artifacts as long-lived API credentials.
Refresh
- Refresh only when a protected request returns
401 Unauthorized. - Attempt a single controlled refresh and a single retry.
- If refresh requires backend participation, keep that logic on the server side.
Expiry
- Expect access tokens to expire regularly.
- Remove expired credentials from runtime state as soon as refresh fails.
- Do not continue retry loops beyond the single refresh attempt.
Sign-out
- Clear persisted and memory-held credentials and any cached auth metadata.
- Treat server-side revoke as best-effort. The current web client clears local state first and may ignore revoke failure on logout.
- Force the next protected action through sign-in again.
Error handling baseline
Security requirements
- Use HTTPS end-to-end.
- Keep refresh or signing secrets off the browser.
- Keep access tokens scoped to the current user and tenant.
- Do not mask repeated authentication failures with silent retries.