Join our Newsletter — 33% off our NHI Course
Home› FAQ› Authentication, Authorisation & Trust› What is an example of single-page application (SPA)…
Authentication, Authorisation & Trust

What is an example of single-page application (SPA) authentication in practice?

← Back to all FAQ
By NHI Mgmt Group Editorial Team Updated October 20, 2026 Domain: Authentication, Authorisation & Trust

In practice, single-page application (SPA) authentication usually relies on an external identity provider and browser-based OAuth flows rather than storing long-term credentials in the app. The app receives short-lived tokens and uses them to call APIs. Defenders should avoid exposing secrets in the browser, validate redirect handling, and limit token scope and lifetime.

What SPA authentication looks like in a real application

A practical SPA example is a React or Vue front end that redirects the user to an identity provider, completes an authorization code flow with PKCE, then receives short-lived tokens for API calls. The SPA does not keep passwords or long-lived secrets in browser storage. It acts as a token consumer, while the identity provider handles sign-in and session establishment.

This pattern works because the browser is a hostile storage and execution environment. The SPA should treat the identity provider as the source of truth for authentication state, then use the returned access token only for the API audience and scope the app actually needs. That keeps the front end thin and reduces the damage if script execution or browser state is compromised.

For a worked identity-flow reference, OAuth 2.0 and OpenID Connect Guide for Identity Teams is the most direct fit because it covers the grant types, PKCE, scopes, tokens and client types that shape SPA sign-in design.

Why SPAs use redirect-based sign-in instead of embedded passwords

In practice, the SPA usually starts unauthenticated, sends the user to the identity provider, and returns with an authorization response rather than asking the user to type a password into the application itself. That separation matters because it lets the identity layer manage MFA, risk checks, federation and recovery without putting those responsibilities into the SPA codebase.

The SPA then exchanges the authorization code for tokens and uses them to call APIs until the access token expires. If the app also needs user identity claims for UI decisions, it can rely on the ID token or userinfo endpoint, but it should not use those claims as a substitute for authorization checks on the API side. The real protection comes from verifying audience, issuer, expiry and scope at the resource server.

When teams choose a stronger browser flow, the decision often comes down to whether they can avoid storing reusable credentials in the client. NIST SP 800-63 Digital Identity Guidelines is useful here because it frames phishing-resistant authentication, authenticator assurance and modern browser-based sign-in requirements.

What usually goes wrong with SPA auth implementations

The common failure is treating the browser like a safe place for secrets. If a SPA stores refresh tokens, API keys or long-lived credentials in local storage, a script injection, malicious extension or compromised dependency can turn a login session into a durable compromise. Redirect handling can also become an attack path if the application accepts loose redirect URIs, fails to bind the response to the initiating client, or mishandles state and nonce values.

Another frequent mistake is over-trusting the front end. Even when the UI hides privileged actions, the API must still enforce authorization because the browser can be modified. A well-built SPA authentication design therefore pairs short-lived tokens with strict server-side checks, narrow scopes, and a refresh strategy that does not leave reusable secrets sitting in the browser.

For implementation detail on the risky parts of the browser flow, OpenID Connect Core 1.0 is the clearest protocol reference for how authorization responses, ID tokens and redirect-based authentication are supposed to work.

Risk and Threat Considerations

SPA authentication risk concentrates in the browser, where token theft, redirect abuse and session fixation can turn a normal sign-in flow into account compromise. The threat is not the SPA alone, but the combination of browser execution, token handling and weak redirect or scope design.

Failure mechanism: An attacker injects script, abuses an open redirect, steals a token from browser storage or intercepts a poorly protected authorization response, then reuses that bearer token until it expires or is revoked.

Impact: The attacker can impersonate the user against downstream APIs, expose data, perform actions within the granted scope, and potentially pivot if the token is over-scoped or long-lived.

That is why short token lifetime, PKCE, exact redirect matching and minimal browser storage are not optional details. They are the controls that keep a front-end authentication pattern from becoming a replayable bearer-token problem. MFA Guide is a useful companion when the SPA is part of a broader browser-based sign-in design that must resist phishing, relay and token theft.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

NIST SP 800-63, OWASP ASVS and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
NIST SP 800-63Digital Identity GuidelinesBrowser-based SPA sign-in depends on authentication assurance and phishing-resistant flows.
Recommendation — Use phishing-resistant browser authentication and enforce the appropriate assurance level for the app.
OWASP ASVSV10 — OAuth and OIDCSPA auth relies on OAuth/OIDC flow design, redirect handling and token processing.
V7 — Session ManagementSPA token handling and browser session lifetime are core session-management concerns.
V8 — AuthorizationThe SPA UI must not replace API-side authorization for token-bearing requests.
Recommendation — Apply OAuth/OIDC verification requirements to redirect handling, token validation and client flow choices. Constrain token lifetime, storage and revocation so browser sessions remain disposable. Enforce server-side authorization for every API action regardless of what the SPA shows.
NIST SP 800-53 Rev 5IA-5 — Authenticator ManagementSPA designs must avoid long-lived reusable secrets in the browser and manage credentials safely.
Recommendation — Manage credentials and token lifecycle so browser-exposed secrets are short-lived and revocable.

Practitioner Guidance

What to verify: Confirm that the SPA uses an authorization code flow with PKCE, that the redirect URI is exact, and that no long-lived credential is persisted in browser-readable storage. If the app depends on refresh tokens, verify the issuer’s browser-session controls and your revocation path before you treat the design as acceptable.

Decision rule: If the front end can reach a sensitive API with only a bearer token, assume token theft is the main compromise path and design for short lifetime, narrow scope and server-side authorization checks. If you cannot enforce those conditions, the better answer is usually to move more of the session state out of the browser and into the identity provider.

Practitioner takeaway: A good SPA authentication example is not “log in in the browser,” it is “delegate sign-in to an identity provider, keep the SPA stateless where possible, and make every browser-held token disposable.”

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 20, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org