Token claims and access decisions
Encoding is not secrecy
A JWT contains claims: issuer (iss), subject (sub), audience (aud), expiration (exp) and other profile-specific fields. A compact signed JWT has encoded header and payload plus a signature; encoding does not hide their contents. Encryption is a separate protection. Some access tokens are opaque and need provider-supported introspection instead of JWT parsing. A valid token is evidence for an identity or delegation, not an unrestricted permission.
A narrow validation profile
The classroom API expects issuer https://issuer.example, audience reports-api, an EdDSA signature using the configured public key and required iss, aud, exp, sub, nbf claims. Configure these expectations independently of the token, require the intended token type or mutually exclusive validation rules, and reject failures. The library checks expiration against its clock and rejects tokens not yet valid. In deployment use provider metadata, bounded trusted key rollover and explicit clock tolerance; never select arbitrary trust sources from token data.
Library example
In PyJWT 2.13.0, use the configured public key and an explicit algorithm list. The code below is a fragment for the local validator; public_key and token are supplied by the isolated test harness. A successful decode returns verified claims, not an access decision. Treat InvalidTokenError as a rejection and never log raw tokens.
claims = jwt.decode(token, public_key, algorithms=["EdDSA"], issuer="https://issuer.example", audience="reports-api", options={"require": ["iss", "aud", "exp", "sub", "nbf"]})Authorization after validation
Suppose the valid classroom token identifies reader-1 with reports:read. The API still checks that the account is active, the local entitlement includes report reading, and the requested record belongs to the reader’s tenant. A valid token for another service or expired token is rejected before this policy step. A correctly signed token without the expected access-token type is also rejected by this teaching profile. Do not rely on the client to enforce these rules.
Offline test plan
Run the included validator using local ephemeral test keys. Predict rejection of expired, wrong-audience, wrong-issuer, missing-claim and unrelated-key fixtures; predict acceptance of the valid token followed by separate allow or deny policy outcomes. Record only case IDs, outcomes and reasons. The lab uses a narrow synthetic profile, not a complete OIDC client, SAML verifier or production OAuth resource server. Read RFC 8725 and the actual provider’s profile before release.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Token claims and access decisions — knowledge check
Apply federation and token validation principles to fictional scenarios.
Does signed JWT encoding hide claims?
Where does the accepted algorithm list come from?
What should happen to an expired token?
What does an accepted signature prove by itself?
A valid reader token requests another tenant record. What should happen?