Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

JWTs, sessions, and OAuth solve different problems. A session keeps an application’s authenticated state between requests; a JWT is a portable format for claims; OAuth 2.0 delegates limited access to a protected service. They can be combined, but none is a drop-in replacement for the others. In a browser app, a sound design starts by separating authentication (who the user is) from authorization (what a client or user may access), then choosing where state and tokens live.

The three roles, in one view

Imagine assembling a superhero team. The metaphor is useful only if each hero keeps a distinct job: the session is the team’s continuing roster and current state, a JWT is a signed or encrypted mission brief carrying claims, and OAuth 2.0 is the permission arrangement that lets a team member access a protected resource. These are not interchangeable protocol components.

Mechanism What it is Primary question it answers Typical browser use
Session Application state maintained across requests “Which authenticated state belongs to this browser?” A cookie carries a session identifier; the server looks up session state
JWT Compact, URL-safe claims representation “What claims can the recipient verify or process?” A token passed to an API, sometimes as an OAuth access token
OAuth 2.0 Authorization framework for delegated, limited access “May this client access that protected service, and with what scope?” Authorization Code flow, commonly with PKCE

Authentication establishes an identity. Authorization decides what that identity or client may do. OAuth’s central purpose is delegated authorization, not a universal user-login protocol.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What a session actually does

State across many HTTP requests

HTTP requests are independent. A session gives the application continuity: after a successful sign-in, later requests can be associated with the same authenticated state, permissions, and server-side data. The application may store a user ID, login time, expiration, anti-forgery state, and other information in a server-side session record.

#1 Best Overall
Yubico - Security Key C NFC - Basic Compatibility - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key C NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key C NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key C NFC via USB-C and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

The cookie is the carrier, not the session

In a common browser design, the server sends a cookie containing an opaque session identifier. The browser returns that cookie on matching requests, and the server uses the identifier to find the session. A cookie is therefore a transport and storage mechanism; it is not synonymous with the session itself. A cookie can carry other values, and a session can be represented through mechanisms other than a browser cookie.

Lifecycle and revocation

Because the server controls the session record, it can expire or revoke a login immediately by deleting or invalidating that record. Set cookie attributes appropriate to the application: Secure to require HTTPS, HttpOnly to block JavaScript access, and an intentional SameSite policy. Regenerate the session identifier when privilege changes, especially after login, to prevent session-fixation attacks. Your framework’s exact configuration names differ, so verify the defaults and explicitly set the policy you need.

Cookie authentication also requires cross-site request-forgery defenses for state-changing requests. SameSite restrictions reduce some cross-site sending, but they are not a substitute for an anti-CSRF design when your application’s request patterns require one.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What a JWT is—and what it is not

A claims format

RFC 7519 defines a JSON Web Token as “a compact, URL-safe means of representing claims to be transferred between two parties.” Claims are statements such as an issuer, subject, audience, expiration time, or application-specific permission. The format is useful when one service needs to transmit verifiable claims to another without a database lookup on every request.

Rank #2
Yubico - YubiKey 5C NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5C NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5C NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5C NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts

Signing does not hide the payload

A JWT can be integrity-protected with a digital signature or a keyed message-authentication code, encrypted for confidentiality, or both through the JOSE family of representations. A signed JWT normally lets anyone holding the token decode its payload. The signature helps a recipient detect alteration and, under the key and issuer assumptions, verify authenticity; it does not make claims secret. Put no passwords, payment data, private profile details, or other sensitive information in a merely signed, readable token. RFC 7519 cautions that claims can contain privacy-sensitive information and must be protected against disclosure.

A token format is not a login architecture

JWT does not define how a user signs in, where tokens are stored, how refresh works, how logout is implemented, or how an API decides which issuer to trust. An application can use JWTs, opaque tokens, server-side sessions, or a mixture. Calling a JWT “the login” confuses a representation with the surrounding authentication and session design.

Validate, do not merely decode

Base64url-decoding a JWT proves only that its text can be parsed. Before accepting it, validate it for the expected use and trusted issuer. Check the signature with the intended key, enforce an allowed algorithm policy, and verify claims such as issuer (iss), audience (aud), expiration (exp), not-before (nbf) when used, and any required subject or scope. Account for clock skew deliberately and reject unexpected token types or claims. Follow the threat-oriented guidance in RFC 8725; do not let an algorithm value supplied by an attacker choose your verification behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What OAuth 2.0 authorizes

Delegated access to a protected service

RFC 6749 describes OAuth 2.0 as a framework in which a client obtains limited access to a protected HTTP service, either with a resource owner’s approval or on its own behalf. The client, authorization server, and resource server have distinct roles. An access token expresses the granted authorization, often constrained by scope, audience, and lifetime.

Rank #3
Yubico - YubiKey 5 NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-A or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5 NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5 NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5 NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts

OAuth is not the identity layer

OAuth by itself does not standardize a user identity claim set or tell an application that a person has logged in. If your application needs standardized authentication and identity claims from an authorization server, use OpenID Connect on top of OAuth. Do not treat receiving an OAuth access token as proof of a user’s identity unless the specific identity protocol and validation rules say so.

Access tokens do not have to be JWTs

An authorization server may issue an opaque access token whose meaning is known only to the resource server, or a JWT that the resource server validates locally. OAuth does not require either format. A deployment can also use a JWT internally while keeping a browser’s own login as a cookie-backed session.

How the mechanisms work together

Browser login plus an external API

Suppose your web application signs a user in and then calls a separate calendar service. The application can maintain its own browser login with a server-side session and cookie. Separately, it can run an OAuth authorization flow to obtain a scoped access token for the calendar API. The session answers “which local user is making this request?”; OAuth answers “what access has the calendar service delegated?”; the access token’s format—JWT or opaque—is a separate decision.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

JWT access token at a resource server

When an API receives a JWT access token, it validates the token against the authorization server’s documented issuer, keys, audience, algorithm policy, and claims. It then applies authorization rules to the resulting scopes or roles. A valid signature alone is not a blanket permission grant: the token must also be intended for that API and still be within its lifetime.

Rank #4
Yubico - Security Key NFC - Basic Compatibility - Multi-Factor Authentication (MFA) Key, Connect via USB-A or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key NFC via USB-A and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

Logout and revocation are architecture decisions

Deleting a local session cookie does not automatically revoke an OAuth token already issued to another service. Likewise, a short-lived JWT may remain cryptographically valid until it expires unless the resource server checks revocation or token status. Design logout, refresh-token rotation, session expiration, and provider-side revocation as explicit flows rather than assuming one mechanism controls all state.

Current OAuth security guidance

Authorization Code flow and PKCE

RFC 9700, the IETF’s Best Current Practice for OAuth 2.0 Security published in January 2025, updates earlier OAuth specifications. For public clients using Authorization Code flow, PKCE is required to prevent an intercepted or injected authorization code from being redeemed by an attacker. Confidential clients are recommended to use PKCE as well, because it adds protection against code misuse without replacing client authentication.

In a PKCE exchange, the client creates a high-entropy code_verifier, sends a derived code_challenge in the authorization request, and sends the verifier when redeeming the code. The authorization server releases tokens only when the values match. Use the authorization server’s current documentation for exact endpoint parameters and redirect-URI rules.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Patterns that should not be casual defaults

Do not select the Resource Owner Password Credentials grant or implicit-style browser patterns merely because they look simpler. Their status and deployment advice are addressed in RFC 9700; review that document and your provider’s current guidance before making an implementation choice. Prefer a modern Authorization Code design with PKCE where it fits the client type.

Best Value
Yubico - YubiKey 5C - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB, FIDO Certified - Protect Your Online Accounts (5C)
  • POWERFUL SECURITY KEY: The YubiKey 5 is a versatile physical passkey that protects your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5 secures 100+ of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5 via USB and tap it to authenticate. No batteries, no internet connection, and no extra fees required.
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Browser architectures in the 2026 guidance

RFC 10017, OAuth 2.0 for Browser-Based Applications, published in August 2026, discusses several ways to arrange browser code, a backend, and an authorization server. Choose among them using these concrete axes rather than a slogan such as “stateless is always better.”

  • Token visibility: decide where access and refresh tokens are stored and which code can read them. Browser-accessible JavaScript has a different exposure profile from a backend-only store.
  • Session controls: define how browser state is established, protected, expired, renewed, and revoked.
  • Backend availability: determine whether operating a backend component is feasible for your team, deployment, and latency budget.
  • Threat model: account for cross-origin requests, injected script risk, redirect handling, and request-forgery exposure.
  • Lifetime and revocation: decide how quickly access must be revoked and how access-token, refresh-token, and browser-session lifetimes interact.

Backend-for-frontend (BFF)

In a BFF architecture, the browser uses a cookie-backed session with your backend. The backend performs the OAuth exchange and keeps access and refresh tokens away from browser-accessible application code, then calls the resource server on the browser’s behalf. This can reduce token exposure in the front end, but it adds backend deployment, session storage, scaling, monitoring, and CSRF responsibilities. It is a trade-off, not a universal winner.

Direct browser-to-resource-server designs

A browser can also obtain and present tokens directly when the authorization server and resource server support that model. You must then make token storage, script exposure, redirect handling, cross-origin policy, and renewal behavior explicit. Compare the resulting risk and operational burden with a BFF instead of assuming that avoiding a backend automatically improves security.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A practical selection checklist

  1. Classify the requirement. Is it local browser continuity, a portable claim, delegated API access, or standardized user identity? Choose session, JWT, OAuth, or OpenID Connect for that requirement rather than for fashion.
  2. Map trust boundaries. List the browser, your application, authorization server, and each resource server. For every token, record who issues it, who reads it, its audience, and its lifetime.
  3. Choose browser storage deliberately. If tokens stay on a backend, design a hardened cookie session and CSRF controls. If browser code handles tokens, document the script-injection, cross-origin, and refresh-token risks and minimize token lifetime and scope.
  4. Implement Authorization Code with PKCE where applicable. Register exact redirect URIs, generate an unpredictable state value, use a protected code verifier, and reject mismatches or unexpected callbacks.
  5. Validate every received JWT. Pin the expected issuer, audience, algorithms, keys, and required claims according to RFC 8725. Never equate successful decoding with validity.
  6. Plan expiration and revocation. Set separate policies for browser sessions, access tokens, and refresh tokens. Decide what logout invalidates locally and what requires provider-side revocation.
  7. Test failure paths. Exercise expired sessions, replayed authorization codes, wrong audiences, altered signatures, missing scopes, CSRF attempts, revoked credentials, and clock differences.

Common design mistakes and their fixes

“JWT is always better than sessions”

JWTs can reduce a lookup in some architectures, but they also make revocation, key rotation, claim privacy, and token size your responsibilities. Sessions offer centralized state and straightforward invalidation. Select based on trust boundaries and operational needs, not a blanket performance or security claim.

“A cookie is insecure, so use local storage”

Cookie and browser-storage choices have different attack surfaces. Cookies can be protected with Secure, HttpOnly, SameSite, server-side session controls, and CSRF defenses. Browser-readable storage exposes tokens to scripts running in the application’s origin. Evaluate the whole threat model instead of treating one storage mechanism as universally safe.

“The OAuth access token tells me who logged in”

An access token is for the resource server and its granted authorization. Use OpenID Connect when you need an identity protocol, and validate identity claims according to that protocol. Keep authorization checks tied to the token’s audience and scopes.

“If the signature verifies, accept every claim”

Verification must include context: trusted issuer, intended audience, permitted algorithm, time claims, token type, and required scopes. A correctly signed token issued for another API or purpose is still the wrong credential for your endpoint.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Key takeaways

  • A session is application state maintained across requests; its cookie identifier is only the carrier.
  • A JWT is a claims format. Signing protects integrity and authenticity under its key assumptions; encryption is what provides confidentiality.
  • OAuth 2.0 delegates limited authorization to protected services. OpenID Connect supplies the standardized identity layer when login claims are required.
  • OAuth access tokens may be JWTs or opaque values, and a browser session can coexist with either.
  • Modern OAuth deployments should follow RFC 9700, including PKCE for public Authorization Code clients, and browser designs should consider the architectures and trade-offs in RFC 10017.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.