byteNative
Backend

JWT & OAuth2

Secure authentication and authorisation to industry standard.

What is JWT & OAuth2?

JWT and OAuth2 are the established building blocks used to implement secure sign-in and authorisation on the web, and they solve two distinct jobs. OAuth2 governs the flow through which an application gains access on a user's behalf without ever seeing their password. A JWT is the compact, signed token that then travels with every request and can be checked without a round trip to the database. On top of them we build logins, cross-system single sign-on and finely graded permissions to industry standard.

More in the documentation

How we use it

We use this when a login comes from third parties like Google or an API should be secured statelessly. Our services verify the signed token locally, so not every request needs a round trip to the database. With several services working together, this gives us a shared single sign-on without logging in twice.

ts
import jwt from "jsonwebtoken";

const token = jwt.sign({ sub: user.id }, secret, { expiresIn: "15m" });

const payload = jwt.verify(token, secret);
console.log(payload.sub);
sign and verify a short-lived access token

Good to know

A JWT, once issued, cannot easily be revoked before it expires, because it is deliberately checked statelessly. So we keep the lifetime of access tokens short and renew them via a separate refresh token, which can be blocked if needed.

00Backend

More tools we work with in the same area.

Which technology fits you?

You don't have to decide that, it's our job. Tell us about your plans.