Skip to main content

Token inspector

A decoded token with its claims explained: audience, scopes, the actor chain and the key that it is bound to.

PatternReadyView source
Works with
Reactshadcn/ui
Runs on sample data, with the neutral theme of shadcn/ui.

A teaching tool. It decodes a token in the browser and says, in one line each, what the claims that matter mean. The applications in this catalog use it in their "How this works" panel.

Installation​

The command adds the file to your project, with the shadcn/ui components that it uses. Your project needs shadcn/ui.

pnpm dlx shadcn@latest add https://examples.lumoauth.dev/r/token-inspector.json

Usage​

Pass a token. Pass verified only when your server checked the signature.

components/debug-token.tsx
import { TokenInspector } from '@/components/token-inspector';

export function DebugToken({ token, verified }: { token: string; verified?: boolean }) {
return <TokenInspector token={token} verified={verified} title="Token for the invoices API" />;
}

The inspector decodes. It does not verify. A browser cannot be trusted with that check, so do it on your server:

app/api/token/verify.ts
import { AccessTokenError, createAccessTokenVerifier } from '@lumoauth/agent';

const verifier = createAccessTokenVerifier({
issuer: 'https://app.lumoauth.dev/orgs/acme-corp/api/v1',
resource: 'https://api.acme.example/invoices',
});

export async function isVerified(token: string) {
try {
await verifier.verify(token);
return true;
} catch (error) {
if (error instanceof AccessTokenError) return false;
throw error;
}
}

Show a token only to the person or the agent that it belongs to, and only in a tool for developers. An access token is a credential.

Where the data comes from​

What the pattern showsCall
The claimsThe token itself. Nothing is sent anywhere.
The signature checkverifyAccessToken() or createAccessTokenVerifier() of @lumoauth/agent, on your server
An opaque tokenToken introspection, POST /oauth/introspect

States​

Runs on sample data, with the neutral theme of shadcn/ui.
  • Not checked. Without verified, the badge says that nobody checked the signature.
  • Expired, with a signature that is not valid.
  • Not a JWT. An opaque token has no claims to read.

Props​

PropTypeDefaultDescription
tokenrequiredstringA JWT: an access token or an ID token.
verifiedbooleanThe result of the signature check that your server made. Leave it out when the token was not verified.
titlestring'Token'A name for the token.
classNamestringClass name for the panel.