JWT authentication development for APIs and apps

A JSON Web Token (JWT) is a compact, URL-safe way to pass signed claims between systems, and it is widely used for API and app sign-in. We build token-based authentication that follows the standards: correct signing, strict validation, short lifetimes, sensible storage and a plan for logout and revocation.
JWT
  • Access and refresh tokens for APIs and apps
  • Strict validation of issuer, audience and expiry
  • Storage choices for browsers and mobile apps
  • Logout and revocation planned, not bolted on

When JWT is the right choice

Signed tokens suit systems where a service must check a credential without a lookup:

  • A resource server must verify a signed, self-contained token. OAuth 2.0 says access tokens can be self-contained and verifiable.
  • Several services or audiences accept tokens from one issuer. Asymmetric signatures and audience restrictions fit this case.
  • You grant delegated API access with a limited scope and lifetime.
  • Claims must cross a trust boundary in a standard format.

When JWT is not the right choice

Signed tokens have costs worth weighing:

  • You need instant revocation. A signed token stays valid until it expires, so you need short lifetimes plus something like an identifier denylist.
  • You run a single web application. Server-side sessions with an opaque identifier keep the meaning on the server, and logging out invalidates the session there.
  • You would put sensitive data in the token. A signed token is readable by anyone who holds it. Use encryption, or keep the data out of the token.
  • An opaque reference token would do. OAuth 2.0 allows an unguessable reference to authorisation data instead of a signed token.

What we build with JWT

Typical projects, described in general terms.

Sign-in for APIs

Login endpoints that issue short-lived access tokens, and refresh tokens that are used only with the authorisation server.

Strict validation

Verifying signature, algorithm, issuer, audience and expiry on every request, and rejecting anything unexpected.

Token storage

Platform keychains on mobile and cookie-based options on the web, instead of storing tokens where scripts can read them.

Logout and revocation

Short lifetimes, refresh handling and an identifier denylist so a logged-out token stops working.

Multi-service tokens

One issuer and several APIs, with asymmetric signing and audience claims that stop one service reusing another's token.

Reviews and fixes

Auditing an existing JWT setup for the common mistakes and fixing them in stages.

What a JWT is

A JWT carries claims as a JSON object, either as the payload of a signed JWS or as the content of an encrypted JWE. It has three parts, a header, the claims and a signature, each encoded and joined by dots. The standard defines optional registered claims: issuer, subject, audience, expiry, not-before, issued-at and a unique identifier. Signing algorithms include HMAC with a shared secret, RSA and ECDSA. OAuth 2.0 describes access tokens, which grant access to protected resources, and refresh tokens, which are used only with the authorisation server. Bearer tokens are sent in the Authorization header.

What a safe implementation needs

  • Reject the unsecured algorithm: the verifier chooses the permitted algorithms from its own configuration, never from the token's header, and each key is used with exactly one algorithm. That prevents key-confusion attacks.
  • Validate the claims: check issuer, audience and expiry on every request. The audience check is mandatory in the best-practice RFC, and a recipient not named in the audience must reject the token.
  • Short lifetimes: the OAuth bearer token guidance says servers should issue tokens valid for one hour or less, restricted by audience and scope, and never place them in page URLs.
  • Storage: OWASP advises against keeping session identifiers, JWTs or refresh tokens in local storage, because scripts can read them. Cookies with the httpOnly flag mitigate this on the web, and the Keychain on iOS or Keystore on Android are the mobile advice.
  • Logout and keys: a denylist keyed on the token identifier, not the raw token. A shared signing secret must be long and random, and never a password.

How we work

  1. Decide whether tokens are the right tool: sessions, opaque tokens or JWTs, based on how many services check them and how fast you must revoke
  2. Fix the rules in writing: algorithms, lifetimes, claims and where tokens live
  3. Test the failures: expired, wrong audience, wrong algorithm and revoked tokens all get rejected
  4. Hand over properly: the token design documented, with notes on key rotation and what to do if a key is exposed

Related technologies

Technologies that appear alongside JWT in our case studies. Select one to see our work with it.

Frequently asked questions

Is a JWT encrypted?

Not by default. A JWT is usually a signed JWS, so its contents are readable and tamper-evident. Encryption (JWE) is optional, so keep sensitive data out of the payload unless it is encrypted.

Can a logged-out user's token be cancelled?

Not by expiry alone. A signed token stays valid until it expires, so the server must keep something like a denylist of token identifiers, and use short lifetimes.

Where should an app keep the tokens?

OWASP advises against local storage and session storage for JWTs and refresh tokens. It names httpOnly cookies as a mitigation on the web, and the Keychain or Keystore on mobile.

Which signing method should be used?

One supported algorithm per key, configured on the verifier. OWASP prefers signatures over shared-secret MACs, because with a shared secret every service that can validate tokens can also create them. HMAC suits a single service that both issues and verifies, with a long random secret.

How can we work together?

There are three ways, on the same terms:

  • Dedicated team, best for ongoing work: interview the developers, then they work on your project full or part time.
  • Fixed scope, best when requirements are clear: we agree the scope and the price up front, and deliver against it.
  • Time and material, best when the scope will change: you pay for the time used and can change priorities as the work goes on.

Whichever you choose, we sign an NDA before work starts, you own the code we write, and every change is reviewed in your repository.

Can I interview the developers before we start?

Yes. For a dedicated team you meet the developers in an online call and interview them before they join your project.

Designing or reviewing token-based sign-in?

Tell us what your clients are, how many services check a token and how fast you need logout. We will say what design fits and what to fix.

Tell us about your project

Tell us what you need built, fixed or improved. We come back with questions, a suggested approach and an estimate.