API 認証と JWT 検証

The platform's external authentication model — which host and route admit FGAI-HMAC-SHA256, which admit an OIDC bearer token, and the exact refusal for the other scheme — is stated once in External authentication model. This page covers the second half of that model: how a receiving service validates a bearer token it IS declared to accept.

JWT bearer authentication applies to browser/BFF flows and explicit service-audience workload contracts. It is not the CLI or public tenant-control-plane credential. Human bearer tokens, including platform-admin tokens, are never CLI credentials; platform administration remains private to the admin-console web app.

See CLI authentication for the signed public-API contract.

Authorization Code + PKCE フロー

FlexGalaxy.AI のファーストパーティアプリとサードパーティ統合のどちらでも、標準フローは Authorization Code with PKCE (S256) です。

  1. アプリは PKCE の code_verifier(暗号論的乱数、43〜128 文字)を生成し、code_challenge = BASE64URL(SHA256(code_verifier)) を導出します。

  2. The user agent is redirected to the realm authorization endpoint, https://auth.flexgalaxy.ai/auth/realms/<realm>/protocol/openid-connect/auth:

    ?response_type=code
      &client_id=<your-client-id>
      &redirect_uri=<your-registered-redirect-uri>
      &scope=openid+profile+email
      &state=<csrf-token>
      &code_challenge=<challenge>
      &code_challenge_method=S256
    
  3. ユーザーは DotID で認証します(PassPort、必要なら MFA を併用)。

  4. DotID は ?code=<auth-code>&state=<csrf-token> を付けて登録 URI にリダイレクトします。state が送信時と一致することを確認してください。

  5. Your application exchanges the code for tokens at https://auth.flexgalaxy.ai/auth/realms/<realm>/protocol/openid-connect/token:

    POST <realm-token-endpoint>
    Content-Type: application/x-www-form-urlencoded
    
    grant_type=authorization_code
    &code=<auth-code>
    &redirect_uri=<same-uri-as-step-2>
    &client_id=<your-client-id>
    &client_secret=<secret>           # confidential clients only
    &code_verifier=<original-verifier>
    
  6. DotID は access_token、id_token、そして offline_access スコープを要求した場合は refresh_token を返します。いずれも JWT です。

The access_token is presented only to the browser/BFF or explicitly registered service-audience surface as Authorization: Bearer <token>. It is not pasted into or stored by the FGAI CLI. The id_token is for your own application to learn who the user is. The refresh_token is exchanged at the same /token endpoint with grant_type=refresh_token.

Realm

DotID issues tokens from named realms on the platform Keycloak. Each realm issues its own JWTs from its own signing key.

Realm

対象ユーザー

issuer クレーム例

flexgalaxy

The single tenant entry realm — account-root users, workforce members of accounts, and the platform-level workforce

https://auth.flexgalaxy.ai/auth/realms/flexgalaxy

Every account and organization is resolved inside flexgalaxy — tenancy rides token claims (account_id, user_type, org membership), never a realm name. The legacy per-account (acc-*) and per-org (idc-*) realm model was retired: those realms no longer exist and a token claiming an acc-*/idc-* issuer cannot be validly issued today. The platform additionally operates dedicated gate realms for its own surfaces (fgai-admins for platform administration, staging-access for the staging gate, insider-doc-viewers for the insider portal) — your service accepts those only if it is one of those platforms. Account-owned service users are non-interactive and use the Account boundary. These identity populations are isolated and are never merged by matching email.

Tenant binding: account_id and user_type claims

flexgalaxy realm が発行する access token は、認証済み subject の tenant binding を説明する 2 つの claim、account_id と user_type を持ちます。

{
  "iss": "https://auth.flexgalaxy.ai/auth/realms/flexgalaxy",
  "sub": "9e0f6f96-2f57-4f49-84ef-8d4d12d4f5e1",
  "account_id": "11111111-1111-1111-1111-111111111111",
  "user_type": "root"
}
  • account_id — the DotID account UUID the subject is bound to. It is emitted for both account-root users and workforce members of an account. It means "this user belongs to this tenant" — nothing more. It is not the account name and not a realm name.

  • user_type — subject がその account にどのようにバインドされているか:

    • root — account の root user。

    • workforce — account の workforce メンバー。

ルール:

  • Account-root ステータスは厳密に user_type == "root" から導出してください。 account_id が存在するだけで root と推論してはいけません — workforce ユーザーも account_id を持ちますが、root ではありません。「account_id を持つ」を「root である」と扱うと、すべての workforce メンバーを root 相当に静かに昇格させてしまいます。

  • caller の tenant を解決するために account_id を使用します(per-request scoping および PDP principal context の構築時)。email、username、または realm name から account identity を導出しないでください。

  • Unbound flexgalaxy users(例: platform admins)は いずれの claim も受け取りません。account_id がない場合、caller は tenant にバインドされていません。user_type がない、または root でない場合、caller を account root として扱わないでください。代わりに適切な platform-admin、workforce、service-user、または workload-identity path にリクエストをルーティングしてください。

これらの claims は identity context であり、authorization grant ではありません。検証済み token がどの tenant に属するか、および subject がその account の root であるかを service に伝えます。caller が特定の service action を実行してよいとは示しません。first-party service は、policy controlled な account/resource operation では引き続き DotID PDP を呼び出す必要があります。

受信した JWT の検証

A receiving service accepts a JWT only where the declaration in External authentication model admits one: a bearer surface, or a route the route table marks fgai-hmac+bearer, bearer or workload-jwt. Public tenant routes on the API edge implement the signed AK/SK and STS path (temporary ASIA credentials, available to any principal via sts assume-role); JWT support on another audience does not satisfy that public contract, and on an HMAC-only route the service refuses the bearer rather than validating it.

具体的には、JWT 検証器は次を行う必要があります:

  1. トークンのヘッダ/ペイロードから iss クレームを抽出する。

  2. Verify the issuer is the platform realm — exact match: https://auth.flexgalaxy.ai/auth/realms/flexgalaxy. Reject any other issuer. Do not prefix-match realm families: the legacy acc-*/idc-* families no longer exist, and an exact match is what rejects a rogue realm that merely shares a prefix.

  3. realm の JWKS を取得します。取得元は <issuer>/protocol/openid-connect/certs です。鍵はキャッシュしてください(DotID は定期的にローテーションするため、Cache-Control ヘッダを尊重します)。

  4. JWKS に対して署名を検証します。トークンの kid ヘッダで鍵を突き合わせます。

  5. 標準クレームを検証します: exp(期限切れでない)、nbf(存在する場合、not before を満たす)、iat(時計のずれを踏まえた妥当性チェック)、aud(サービスの audience identifier と一致)。

  6. 認可ロジックが依存するサービス固有クレームを検証します(例:realm_access.roles、groups)。

DotID's own services implement exactly this pattern. There is exactly one customer-facing issuer, so a validator is a single exact-match check on flexgalaxy — there is no open-acceptance or prefix-allowlist variant to choose between, and none to mix.

AuthorizeRequest / AuthorizeResponse の形

service から DotID Policy Decision Point(PDP)を呼び出す場合は、固定の request/response contract を使用します。

PDP 呼び出しが認可ステップです。JWT 検証は「このトークンは本物で、有効期間内で、DotID によって発行され、このサービス向けか?」に答えます。PDP は「この principal は、この account 内のこの resource に対して、この action を実行できるか?」に答えます。

トークンに account_id があるからといって PDP を省略しないでください。DotID はポリシー評価を一元化しているため、すべてのファーストパーティサービスが managed policies、permission sets、permission boundaries、service control policies、delegated administration、resource policies、root-user account ownership について同じ動作を確認できます。各サービスがこれらのチェックをローカルで再実装すると、サービス間でポリシーの動作が乖離します。

最小限のリクエスト:

{
  "principal": {
    "account_id": "11111111-1111-1111-1111-111111111111",
    "user_id": "u-12345",
    "user_type": "iam",
    "ic_session": false,
    "ps_id": null
  },
  "action": "licensing:Device:Read",
  "resource": "frn:11111111-1111-1111-1111-111111111111:licensing:device/dev-12345",
  "context": {
    "source_ip": "203.0.113.42",
    "request_time": "2026-05-25T11:00:00Z"
  }
}

最小限のレスポンス:

{
  "decision": "ALLOW",
  "reason": null,
  "matched_statement": "AllowDeviceRead",
  "evaluation_time_ms": 2
}

decision は常に ALLOW または DENY です。許可時の reason は null、拒否時は安定した機械可読コードです。matched_statement は一致したポリシーステートメントの Sid、一致したステートメントがない場合は null です。DotID は Java record フィールドを snake_case JSON 名でシリアライズします。

Discovering this resource (RFC 9728)

A 401 from a bearer-admitting surface — a browser host, or a machine route declared fgai-hmac+bearer, bearer or workload-jwt — names where to find this resource's OAuth 2.0 protected-resource metadata:

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://api.flexgalaxy.ai/.well-known/oauth-protected-resource"

A 401 from an HMAC-only machine route does NOT carry that challenge. It challenges the credential the route actually accepts:

HTTP/1.1 401 Unauthorized
WWW-Authenticate: FGAI-HMAC-SHA256 realm="dotid"

The distinction is deliberate: following an OAuth discovery pointer from a route that refuses OAuth bearer tokens sends a client to a credential exchange that cannot succeed there. The public metadata document still exists and is still anonymous — it just is not advertised by a route that will not accept what it describes.

Fetch that URL to get the RFC 9728 metadata document for the host you called:

curl -sS https://api.flexgalaxy.ai/.well-known/oauth-protected-resource
{
  "resource": "https://api.flexgalaxy.ai",
  "bearer_methods_supported": ["header"]
}

Those are the two fields a client needs; the document also carries the other RFC 9728 registry fields. The advertised URL is always https, always carries no port, and always names the host your request carried — a client may follow it as-is. The document is public: discovery precedes authentication, so it needs no credential.

FlexGalaxy.AI is multi-tenant, but tenancy is carried in token claims rather than separate realms: every account authenticates against the single platform realm, so the metadata document deliberately does not enumerate authorization servers. The authorization server is the platform realm — use its /.well-known/openid-configuration.

よくあるエラー

ステータス

意味

確認ポイント

401 Unauthorized

The credential is absent, invalid, or of the wrong family for this route.

On JWT-bearing browser/workload routes, verify the bearer token's iss/kid; on public API-edge routes, verify the FGAI-HMAC signature and required STS session token. external-auth-scheme-mismatch means the route does not admit the family you sent — read the external authentication model instead of retrying with the same credential.

403 Forbidden

トークン自体は有効でしたが、PDP が DENY を返しました。

レスポンス本文を確認してください。reason と、取得可能なら matched_statement が含まれ、拒否原因を追跡できます。

400 Bad Request(PDP)

principal オブジェクト、action、または resource FRN が不正です。

正式な resource 構文とパーサーは FRN format を参照してください。

400 Bad Request(DotID API)

API versioning mismatch — 廃止済みパスにリクエストが送信されました。

公開 developer API は /<capability>/v1/... を使用します。ファーストパーティ console API はそれぞれの gateway prefix を使用します。ADR に明確な gateway 例外が記載されていない限り、サービスローカルの実装パスは公開されません。

フェデレーション workload token

DotID は、外部 OIDC issuer(GitHub Actions、GitLab CI)からフェデレーションされた workload identity にも、RFC 8693 token exchange を通じて access token を発行します。サービスでの検証は、他の DotID 発行 JWT の検証と同一です。同じ realm JWKS、同じ iss / aud / exp ルールを使用します。唯一の違いは、トークンの sub が人間や service-user の ID ではなく DotID workload identity ID であり、トークンには監査の相関付けのために元の CI subject を記録する追加カスタムクレーム federated_subject が含まれることです。その形状は {issuer, sub} です。

federated_subject クレームは監査メタデータとしてのみ扱い、認可判断には決して使用しないでください。他の DotID 発行トークンと同様に、aud、sub、scope クレームが認可の境界です。

交換契約(サービスがこのトークンを 消費 する際の検証ではなく、CI がこのトークンを 取得 するために呼び出すエンドポイント)については、workload-federation.md を参照してください。