Authentication vs authorization: modern implementation patterns in 2026
Authentication verifies who users are. Authorization determines what they can do. In 2026, the line between managed services and custom implementation has shifted — here's how to choose.
Executive summary
Authentication verifies who users are. Authorization determines what they can do. In 2026, the line between managed services and custom implementation has shifted — here's how to choose.
Last updated: 3/19/2026
Executive summary
Authentication (authn) and authorization (authz) are often conflated, but they solve different problems. Authentication verifies identity — who the user is. Authorization verifies permissions — what the user can do. In production systems, getting either wrong creates security vulnerabilities; getting both right creates the foundation for multi-tenant SaaS, enterprise features, and regulatory compliance.
The implementation landscape in 2026 has shifted dramatically from five years ago. Managed identity services have matured, OAuth 2.1 has emerged with stronger security defaults, and the decision between buying versus building authentication is no longer about capability — managed services win on features — but about control, compliance, and long-term vendor dependence.
This post covers the modern patterns for implementing authentication and authorization, and how to choose between managed services and custom implementation.
OAuth 2.1, PKCE, and the death of implicit flow
OAuth 2.0, published in 2012, showed its age as security researchers discovered vulnerabilities in its most widely-deployed flows. OAuth 2.1, published as a draft in 2026, deprecates problematic flows and codifies security best practices that were previously optional.
What changed in OAuth 2.1
Deprecated flows:
- Implicit flow: Previously recommended for single-page apps (SPAs), now deprecated due to token exposure in URL fragments and lack of refresh token support
- Resource Owner Password Credentials flow: Deprecated except for legacy migrations; directly handling user passwords creates PCI and GDPR scope expansion
- Token reuse across request types: Previously allowed; OAuth 2.1 requires separate tokens for different grant types
New security requirements:
- PKCE is mandatory: Proof Key for Code Exchange (PKCE) is required for all public clients (SPAs, mobile apps), preventing authorization code interception attacks
- Refresh token rotation: Single-use refresh tokens with automatic rotation to detect token leakage
- Sender-constrained tokens: Tokens bound to the client via mutual TLS or certificate-bound tokens, preventing token theft replay attacks
PKCE: the default for all OAuth clients
PKCE adds a dynamically created cryptographically random key called a code verifier and its transformed value called a code challenge. On the initial authorization request, the client sends the code challenge; when exchanging the authorization code for a token, the client must prove possession of the code verifier.
PKCE flow for SPAs:
- Client generates
code_verifier(random 43-128 character string) - Client computes
code_challenge = BASE64URL(SHA256(code_verifier)) - Client redirects to authorization server with
code_challenge - Authorization server stores
code_challengetemporarily - On token exchange, client sends
code_verifier - Authorization server verifies
code_verifiertransforms to storedcode_challenge
This prevents authorization code interception attacks where a malicious actor injects themselves between the client and authorization server.
Managed identity services: Auth0 vs Clerk vs others
Auth0 (Okta): the enterprise default
Auth0, acquired by Okta in 2021, remains the default choice for enterprise SaaS products requiring sophisticated identity management.
Auth0 strengths:
- Protocol coverage: OAuth 2.1, OIDC, SAML, WS-Federation — comprehensive coverage for enterprise federation
- Enterprise directory integration: Active Directory, LDAP, SAML identity providers — critical for selling to enterprises
- Feature depth: Breached password detection, anomaly detection, adaptive MFA, passwordless authentication
- Customization: Extensive UI customization, branded login pages, custom email templates
- Scalability: Handles global scale with multi-region deployment
Auth0 trade-offs:
- Pricing complexity: Per-user pricing becomes expensive at scale; feature tiers create pricing uncertainty
- Vendor lock-in: Proprietary APIs make migration expensive; switching costs increase with integration depth
- Overhead: Features you may not need (SSO, MFA, passwordless) are bundled into pricing tiers
Choose Auth0 when: Selling to enterprise customers, requiring SSO or directory integration, needing compliance certifications (SOC 2, ISO 27001), or when authentication complexity justifies specialized tooling.
Clerk: the modern SPA-native alternative
Clerk emerged in the early 2020s as a modern authentication alternative focused on developer experience for React/Next.js applications.
Clerk strengths:
- Framework integration: First-class React, Next.js, and Remix support with hooks and components
- JWT signing: Your application receives JWTs signed by Clerk, eliminating network dependency on Clerk for authentication verification
- Simplicity: Lower complexity ceiling than Auth0; easier to understand and debug
- Pricing transparency: Per-application pricing (MAU-based) rather than complex per-user tiers
- Speed: Fast implementation time for authentication basics
Clerk trade-offs:
- Enterprise features: Less mature enterprise directory integration and federation than Auth0
- Protocol coverage: OIDC and OAuth 2.1; fewer legacy protocol options (SAML, WS-Federation)
- Smaller ecosystem: Fewer third-party integrations and community resources
Choose Clerk when: Building a modern SPA with React/Next.js, not selling to enterprises requiring SSO, prioritizing developer experience over enterprise feature depth, or when pricing predictability matters.
Other options
AWS Cognito:
- Best when deeply integrated in AWS ecosystem (Lambda triggers, API Gateway integration)
- Pricing can be lower at very high scale
- Configuration complexity and developer experience lag behind Auth0/Clerk
Firebase Authentication:
- Strong mobile app support, real-time database integration
- Less flexible for custom OIDC/SAML flows
- Vendor lock-in to Firebase ecosystem
Supabase Auth:
- Open-source alternative to Firebase Authentication
- Row-level security integration with PostgreSQL
- Less mature enterprise features than Auth0
Descope, WorkOS, Stytch:
- Emerging alternatives with specific strengths (passwordless focus, B2B SaaS focus, API-first design)
- Evaluate for specific use cases where their focus aligns with your requirements
When to build vs buy authentication
Buy authentication when:
You should use a managed identity service when authentication is not your core competency and you have budget for vendor dependency.
Specific buy signals:
- You need SOC 2, ISO 27001, or HIPAA compliance certifications; managed services provide third-party audits faster than building your own
- You're selling to enterprise customers requiring SSO or directory integration; Auth0's enterprise federation features represent years of engineering work
- You need passwordless, biometric, or hardware key authentication; building this securely requires specialized cryptography expertise
- You're a small team; authentication security vulnerabilities are existential risks, and managed services distribute this risk
Build authentication when:
You should build custom authentication when managed services create more risk than they mitigate, or when your requirements are sufficiently differentiated.
Specific build signals:
- Your authentication requirements are highly differentiated (proprietary biometric protocols, custom regulatory schemes)
- You have strict data residency requirements that prevent using managed services (data must remain in specific geographic jurisdictions)
- You're building an authentication/identity product yourself; managed services are competitive threats, not infrastructure
- You have cryptographic expertise on staff and security audit processes; building authn/authz is a deliberate capability investment, not a shortcut
Hybrid approach: Use managed services for the hard parts (password hashing, MFA, OAuth protocol implementation) while implementing custom authorization logic based on your domain model.
Session management in 2026
JWTs vs opaque tokens
JWTs (JSON Web Tokens):
Self-contained tokens that encode claims (user ID, permissions, expiration) in the token itself. The client presents the JWT; the resource server verifies the signature.
Advantages:
- Stateless verification; no database lookup required for token validation
- Performance at scale; token validation is cryptographic verification, not network I/O
- Microservices friendly; any service can verify the token without consulting a central authority
Disadvantages:
- Cannot revoke individual tokens without short expiration or token blocklist
- Token bloat; claims are encoded in every request, including unnecessary data
- Private claims in JWTs are visible to the client (unless encrypted)
Opaque tokens:
Random strings that reference session data stored server-side. The resource server must introspect the token via network call to the authorization server.
Advantages:
- Immediate revocation; delete session data from store, token becomes invalid
- Smaller token size; only a reference string, not the full claims payload
- Claims are opaque to the client
Disadvantages:
- Stateful verification; requires network I/O or cache lookup for every request
- Single point of failure; authorization server availability becomes a performance bottleneck
- Cross-service complexity; microservices must either all call the same introspection endpoint or use a shared cache
Recommendation: Use JWTs for performance at scale, accepting the trade-off of revocation granularity. Implement short-lived access tokens (15 minutes) with long-lived refresh tokens (30 days) to balance performance and security.
Token storage: cookies vs localStorage vs session storage
HttpOnly cookies:
Server-set cookies that cannot be accessed by JavaScript, reducing XSS attack surface.
Advantages:
- Automatic CSRF protection when combined with SameSite attribute
- Not accessible via XSS, reducing token theft risk
- Automatic inclusion in requests; no manual token management
Disadvantages:
- Subdomain cookie sharing can create unintended access across subdomains
- Older browser compatibility concerns for SameSite=None;Secure
localStorage/sessionStorage:
Client-side storage accessible to JavaScript.
Advantages:
- Explicit control over token inclusion in requests
- No cross-subdomain leakage; scoped to origin
Disadvantages:
- Accessible to XSS attacks; any malicious JavaScript can read tokens
- Manual token management required for requests
Recommendation: Use HttpOnly cookies with SameSite=Strict for first-party applications. Use localStorage only when necessary (e.g., mobile apps, cross-origin requests) and implement rigorous XSS mitigation.
Authorization modeling: RBAC vs ABAC vs ReBAC
Role-Based Access Control (RBAC)
Users are assigned roles; roles are assigned permissions. This is the most common authorization model.
RBAC example:
- User
alice@example.comis assigned roleeditor - Role
editorhas permissionposts:create,posts:update,posts:delete - User
alice@example.comcan create, update, and delete posts
RBAC strengths:
- Simple to understand and implement
- Sufficient for most applications
- Easy to audit and explain to non-technical stakeholders
RBAC weaknesses:
- Doesn't scale to complex permission requirements (e.g., user can edit their own posts but not others')
- Role explosion when modeling fine-grained permissions (e.g.,
editor_of_own_posts,editor_of_all_posts)
Attribute-Based Access Control (ABAC)
Permissions are granted based on attributes of the user, resource, and environment.
ABAC example:
- User with
department=engineeringcan createpostswithtarget_audience=internal - User with
role=editorANDpost.owner == user.idcan update posts - User can access resource if
current_time < resource.expiryANDuser.security_level >= resource.classification
ABAC strengths:
- Flexible and expressive; can model complex permission logic
- Fine-grained control without role explosion
- Context-aware permissions (time-based, location-based, device-based)
ABAC weaknesses:
- Complex to implement and reason about
- Harder to audit and debug; permission grants depend on dynamic evaluation
- Performance impact if policy evaluation requires database lookups
Recommendation: Start with RBAC for simplicity. Introduce ABAC selectively for specific complex permissions (e.g., user can edit their own resources). Implement ABAC as an extension layer on top of RBAC, not a wholesale replacement.
Relationship-Based Access Control (ReBAC)
Permissions are granted based on relationships between entities in a graph. This is emerging as the dominant model for collaborative applications.
ReBAC example:
- User
aliceisownerofdocument:123 ownerrelationship grants permissiondocuments:edit- User
bobhasviewerrelationship todocument:123 viewerrelationship grants permissiondocuments:view
This models naturally collaborative permissions: workspace members, document collaborators, team members, organization owners.
ReBAC strengths:
- Natural fit for collaborative applications
- Flexible relationship modeling without hardcoding roles
- Supports complex permission inheritance (e.g., organization admin inherits all workspace permissions)
ReBAC weaknesses:
- Requires graph database or relationship-aware authorization engine (e.g., Oso, OpenFGA)
- More complex mental model than RBAC
- Less mature ecosystem and tooling
Recommendation: Consider ReBAC for collaborative SaaS applications (document editors, project management tools, team communication platforms). Use RBAC for simpler applications without complex collaboration models.
Decision prompts for engineering teams
- If your authentication provider disappeared tomorrow, could your engineering team rebuild authentication within a sprint, or would it require months of work and security audits?
- Are you storing user passwords, or have you completely outsourced password hashing to a managed service?
- When a user's permissions change, how long before those changes take effect — immediately, or after their JWT expires (potentially hours later)?
- For your most sensitive operations, does authorization require only a valid session, or are you checking permissions on every sensitive action?
Building an application with authentication and authorization requirements that go beyond email/password login? Talk to Imperialis about OAuth 2.1 implementation, permission modeling, and managed identity service selection.
Sources
- OAuth 2.1 draft — IETF, 2026 — accessed March 2026
- PKCE RFC 7636 — IETF, 2026 — accessed March 2026
- Auth0 documentation — Auth0, 2026 — accessed March 2026
- Clerk documentation — Clerk, 2026 — accessed March 2026
- NIST SP 800-63B — Digital Identity Guidelines, 2026 — accessed March 2026