Signed JWT structure and validation of JSON-based web tokens before an authorization decision.

JSON Web Token: Structure, Validation, and Authorization

A JWT carries claims as a JSON object in a compact format that can be signed or encrypted. Use a vetted library to validate a received token before treating its claims as trustworthy. These web tokens can pass identity or other assertions between services, but the format itself does not grant access to a resource.

JSON Web Tokens: Claims and Compact Forms

A JSON Web Token is a container for claims: statements such as an issuer, subject, intended audience or expiration time. RFC 7519 defines the format and registered claim names. Applications decide which claims their particular token profile requires and how to use them. JSON Web Tokens can be signed, encrypted, or both, depending on the application profile.

A common signed form uses a compact JSON Web Signature (JWS): header.payload.signature. Each part is base64url encoded and the three parts are separated by periods. The header identifies cryptographic parameters, the payload holds claims, and the last part provides a signature or message authentication code. The latter protects integrity using a shared key; an asymmetric signature uses a signing key and a corresponding verification key.

A signed JSON token can be decoded without knowing the signing key. Base64url is an encoding, not encryption; it should not be used to hide sensitive claims. An encrypted JWT uses JSON Web Encryption (JWE); its compact form has five parts. Do not assume every JWT has three sections or that every readable token is encrypted.

Read a Payload Without Trusting It

The following objects illustrate a decoded header and payload. They are not a usable credential or a complete signed token:

{"alg":"RS256","typ":"JWT"}
{"iss":"https://issuer.example","sub":"user-42","aud":"orders-api","exp":2000000000}

Here iss identifies the issuer, sub the subject, aud the intended audience and exp an expiration time expressed as seconds since the Unix epoch. The algorithm in the header is a claim about how the token was protected, not permission for the receiver to accept any algorithm it names. Decoding these fields helps inspection; it proves neither authenticity nor that the subject may read an order.

From Issuance to a Request

Consider an application with an identity service and an orders API. The issuer creates and signs claims for the API. The client sends the resulting bearer credential in an HTTPS request’s Authorization: Bearer header. RFC 6750 describes bearer-token transport: possession is enough to present such a token, so protect it in transit and storage.

The API receives the request and validates the signed web token using a trusted configuration. Such JSON-based security tokens should be accepted only in the context for which they were issued. It should not take a key URL or algorithm supplied by an untrusted token as an independent source of trust. Configure the issuer’s expected key source and permitted algorithms in the verifier, and reject failures. RFC 8725 explains algorithm and key validation concerns.

Next, compare the issuer and audience against values expected by this API. Enforce exp whenever present and nbf when present; a token with a future not-before time is not yet valid. Although expiration is optional in the base specification, an application profile can require it and reject tokens without it. Apply only the clock-skew allowance your profile permits.

Finally, apply authorization rules. A valid signature and acceptable claims can identify the subject and intended recipient; they do not establish that the subject owns a particular order. Look up the requested order and check the verified identity and applicable permissions against the operation. Return an appropriate denial if that check fails.

Acceptance Order

For a protected endpoint, verify cryptography with the configured key and allowed algorithm, validate the expected issuer, audience and time claims, then authorize the requested action against application policy. Only then return the resource.