What is a JWT, and what does it consist of? A JSON Web Token is a compact, signed token used to carry identity and authorization claims between parties. It has three Base64URL-encoded parts separated by dots: - Header: token type and signing algorithm, e.g. {"alg":"RS256","typ":"JWT","kid":"key1"}. - Payload: claims such as sub (user ID), iss (issuer), aud (audience), exp (expiry), iat (issued at), roles or scopes, and custom claims. - Signature: created over header and payload with a secret (HMAC) or private key (RSA or ECDSA). It proves integrity and authenticity. The payload is readable by anyone, so it must not contain secrets. Same credentials on a laptop and a mobile — one JWT or two? Two separate JWTs. Each login is a separate authentication event, so the server issues a new token for each device or session. They have different iat, exp and jti values (and therefore different signatures), even if the user claims are the same. Usually each device also gets its own refresh token, which allows features such as "log out from this device" or "sign out of all sessions" by revoking specific refresh tokens. A token could technically be copied between devices, but that is token theft, not normal behaviour. What is a refresh token? A long-lived credential used only to obtain new access tokens when the short-lived access token expires, without asking the user to sign in again. It is sent only to the token endpoint, stored securely, usually saved server-side (often as a hash) so it can be revoked, and ideally rotated on every use, with reuse detection to catch stolen tokens. What is the TTL of a refresh token? There is no single standard value; it is a security versus convenience decision. Common choices: - Access token: 5–60 minutes (often 15). - Refresh token: hours to days for sensitive apps (banking may use a few hours with an idle timeout), 7–30 days for typical web apps, longer (for example 90 days, sliding) for mobile apps. - Many providers use both an idle timeout (expires if unused for N days) and an absolute maximum lifetime. Microsoft Entra ID refresh tokens, for example, default to a 90-day sliding window, with a 24-hour lifetime for single-page applications.
Ravindra Wadile · · 0 likes