JWT (JSON Web Token) 登録クレーム、OpenID Connectクレーム、カスタムクレーム、検証ルール、セキュリティのベストプラクティスの完全なリファレンスです。
| クレーム | 説明 |
|---|---|
iss | Identifies the principal that issued the JWT. Typically the auth server URL. |
sub | Identifies the principal that is the subject of the JWT — usually the user ID. |
aud | Identifies the recipients that the JWT is intended for. The API must check this. |
exp | The time after which the JWT MUST NOT be accepted. Critical for security. |
nbf | The time before which the JWT MUST NOT be accepted. Useful for deferred activation. |
iat | The time at which the JWT was issued. Used to determine the age of the token. |
jti | Unique identifier for the JWT. Prevents token replay attacks when combined with a blocklist. |
| クレーム | 説明 |
|---|---|
name | End-user's full name in displayable form. |
given_name | Given name(s) or first name of the end-user. |
family_name | Surname(s) or last name of the end-user. |
email | End-user's preferred email address. |
email_verified | True if the end-user's email has been verified by the Provider. |
picture | URL of the end-user's profile picture. |
locale | End-user's locale as a BCP 47 language tag. |
zoneinfo | End-user's time zone from the IANA Time Zone Database. |
updated_at | Time the end-user's information was last updated. |
nonce | String value used to associate a Client session with an ID Token and to mitigate replay attacks. |
at_hash | Hash of the Access Token value. Used to validate the access_token. |
auth_time | Time when the end-user was authenticated. |
| クレーム | 説明 |
|---|---|
scope | OAuth 2.0 scopes granted to the token. Defines what resources the token can access. |
roles | Non-standard but widely used. Application roles assigned to the user. |
permissions | Fine-grained permissions. Used by Auth0, AWS Cognito, and others. |
azp | The client_id of the OAuth 2.0 Client that requested the token. Used with OIDC. |
acr | Level of authentication that occurred. Values defined by the deployment. |
amr | How the user was authenticated (password, OTP, biometric, etc.). |
| クレーム | 説明 |
|---|---|
tenant_id | Multi-tenant app custom claim. Identifies the tenant/organization. |
org_id | Organization identifier used by Auth0, WorkOS, and similar platforms. |
plan | User's subscription tier. Common in SaaS billing-based access control. |
| クレーム | 説明 |
|---|---|
Verify exp | Reject any token where exp < current time (in UTC seconds). Add small clock skew (30–60s). |
Verify iss | Must exactly match the expected issuer URL. Reject mismatches. |
Verify aud | Must contain your API's identifier. Reject tokens issued for other audiences. |
Verify signature | NEVER trust a JWT without verifying its cryptographic signature using the correct key/JWKS. |
Check nbf | If nbf is present, reject tokens used before this time. |
Check alg | Explicitly specify expected algorithm. Reject 'none' algorithm. Prefer RS256 or ES256 over HS256 for public APIs. |
| クレーム | 説明 |
|---|---|
HS256 | Fast; uses a single shared secret for sign & verify. Only suitable when both parties are trusted (e.g., server-to-server). |
HS512 | Like HS256 but with 512-bit hash output. Marginally stronger for symmetric use cases. |
RS256 | Most widely supported asymmetric algorithm. Sign with private key, verify with public key. Use this for public APIs and OIDC. |
RS512 | RS256 with SHA-512. Stronger hash but same RSA security level. Marginally slower. |
ES256 | Compact, fast asymmetric algorithm. Smaller keys than RSA for equivalent security. Recommended for new systems. |
PS256 | More secure padding than RS256 (probabilistic). Required by FAPI (Financial-grade API) and advanced OIDC profiles. |
EdDSA | Modern elliptic curve algorithm. Fastest, smallest signatures. Use with jose library. Not universally supported yet. |
JWTはドットで区切られた3つのBase64URLエンコードされた部分で構成されます: ヘッダー.ペイロード.署名
eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2F1dGguZXhhbXBsZS5jb20iLCJzdWIiOiJ1c2VyXzEyMyIsImF1ZCI6Imh0dHBzOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoxNzM1Njg5NjAwLCJpYXQiOjE3MzU2MDMyMDAsInNjb3BlIjoicmVhZDp1c2VycyJ9.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
alg: RS256アルゴリズムとトークンタイプ
typ: JWTクレーム — データ
iss: https://auth.example.com暗号化検証
sub: user_123aud: myappexp: 1735689600iat: 1735686000私たちの JWTエンコーダー/デコーダー でJWTトークンのエンコード/デコードをお試しください
exp(有効期限)はトークンが期限切れになる時刻で、この時刻以降は受け入れてはなりません。nbf(開始時刻)はトークンが有効になる時刻で、この時刻以前は受け入れてはなりません。iat(発行時刻)はトークンが発行された時刻を記録し、トークンの経過時間を判断するのに役立ちます。3つすべてNumericDate形式(Unixエポックからの秒数)を使用します。
アクセストークンは短命にすべきです:ほとんどのアプリで5〜60分、APIで1〜24時間。リフレッシュトークンは長くなる可能性があります:数日から数週間。有効期限を短くすることで、トークン盗難による被害を最小限に抑えられます。JWTペイロードはbase64urlエンコード(暗号化ではない)され、誰でもデコードできるため、機密データを保存しないでください。
sub(主体)はJWTが表す主体(通常はユーザーID)を識別します。発行者のコンテキスト内で一意である必要があります。変更される可能性があるユーザー名やメールアドレスではなく、安定した再割り当て不可能な識別子(UUIDや数値IDなど)を使用してください。
はい、ステートレス認可の場合は含めます。カスタムクレームにロール/権限を含めてください(例:'roles': ['admin', 'user'])。ただし、トークンを軽量に保ちましょう — すべてを含めないでください。細かい権限については、JWTにセッションIDを含め、サーバー側で権限を参照するリファレンストークンパターンを検討してください。