本文へスキップ

参考

OpenID Connect

PHP 以外? Identvia は標準の OpenID Connect プロバイダです。認定ライブラリを issuer に向けてください。

AI エージェント用のプロンプトをコピー

コーディングエージェントを使っていますか?このプロンプトはエージェントをこのドキュメントに案内し、守るべきルールを示します。エージェントが書いたコードも、ほかのコードと同じようにレビューしてください。

You are helping me add "Sign in with Identvia" to my app (PHP). Identvia is an OpenID Connect provider.

Read these first (they are plain Markdown and are the source of truth; prefer them over anything you remember):
- https://id.identvia.com/developers/docs/quickstart.md
- https://id.identvia.com/developers/docs/oidc.md
- https://id.identvia.com/developers/docs/security.md
- Discovery: https://id.identvia.com/.well-known/openid-configuration

Stack: plain PHP 8.1+ (no framework). Use the official SDK identvia/identvia-php (composer require identvia/identvia-php, or the zip with vendor/ from https://id.identvia.com/developers/docs/php for hosts without Composer). Create identvia.php (config), login.php (redirectToSignIn), callback.php (handleCallback, then session_regenerate_id(true) and store sub) and logout.php. Read secrets from environment variables or a config file outside the web root.

Requirements:
1. Authorization code flow with PKCE (S256 only), a random state and a nonce per sign-in. No implicit flow.
2. Validate the ID token: RS256 signature from the JWKS, iss = https://id.identvia.com, aud contains my client_id, exp/iat, and the nonce.
3. Identify users by sub (it is pairwise: different for every app). Treat email as optional, because the person may choose not to share it.
4. Redirect URIs must match exactly. Keep the client secret and refresh tokens server-side; never log tokens.
5. Ask only for the scopes I need (openid, plus email/profile if used). Handle the user canceling (error=access_denied) gracefully.

Optional, only if I ask for AI-agent access later:
- AgentPass (agents acting for a user with single-use, holder-bound passes): https://id.identvia.com/developers/docs/agentpass.md
- MCP server for agent clients: https://id.identvia.com/developers/docs/mcp.md
- Token exchange, rich authorization requests and CIBA: https://id.identvia.com/developers/docs/delegation.md

Before writing code, tell me which files you will add or change. Don't invent endpoints or options that aren't in the docs; if something is unclear, ask me.

ディスカバリ

issuerhttps://id.identvia.com
ディスカバリhttps://id.identvia.com/.well-known/openid-configuration
認可https://id.identvia.com/oauth/authorize
トークンhttps://id.identvia.com/oauth/token
Userinfohttps://id.identvia.com/oauth/userinfo
JWKShttps://id.identvia.com/oauth/jwks.json
取り消しhttps://id.identvia.com/oauth/revoke
セッション終了https://id.identvia.com/oauth/logout

Identvia が強制するルール

  • 認可コードフローのみ(response_type=code)。Implicit / ハイブリッドなし。
  • パブリッククライアントでは S256 の PKCE が必須です(シングルページ、モバイル、ネイティブアプリ)。すべてのクライアントでの利用を推奨します。client secret で認証するサーバーサイドアプリは省略でき、OpenID Connect の規定どおり nonce も省略できます。
  • リダイレクト URI は文字単位で完全一致。ワイルドカードやフラグメントなし。http://localhost は Development 環境のみ。
  • 認可コードは一回限りで 60 秒で期限切れ。再利用すると発行済みトークンを取り消します。
  • ID トークンは RS256 署名。アクセストークンは 10 分。リフレッシュ(スコープ offline_access)は使用のたびにローテーション;古いものを再送するとチェーン全体を取り消し。
  • コールバックに iss(RFC 9207)が含まれます。確認してください。
  • sub は pairwise:同じ人でもアプリごとに異なる安定 ID。

1. 認可リクエスト

HTTP
GET https://id.identvia.com/oauth/authorize
  ?response_type=code
  &client_id=oid_…
  &redirect_uri=https%3A%2F%2Fexample.com%2Fcallback
  &scope=openid%20email%20profile
  &state=<random, 32+ bytes>
  &nonce=<random, 32+ bytes>
  &code_challenge=<BASE64URL(SHA256(code_verifier))>
  &code_challenge_method=S256

任意: prompt=none|login|consent、max_age、login_hint。

2. トークンリクエスト

HTTP
POST https://id.identvia.com/oauth/token
Authorization: Basic base64(client_id:client_secret)
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=…&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&code_verifier=…

パブリッククライアントはシークレットの代わりに本文で client_id を送ります。

Response
{
  "token_type": "Bearer",
  "access_token": "eyJ…",
  "expires_in": 600,
  "id_token": "eyJ…",
  "refresh_token": "…",          // offline_access がある場合のみ
  "scope": "openid email profile"
}

3. ID トークンを検証

  1. JWKS の一致する kid の鍵で署名を検証。RS256 のみ受理。
  2. iss は https://id.identvia.com と一致;aud に client ID が含まれる;azp があれば client ID。
  3. exp は将来で、iat はそうでないこと(1 分のずれを許容)。
  4. nonce は送信したものと一致。
  5. max_age を送った場合は auth_time を確認。

クレーム

スコープクレーム
openidsub、auth_time、amr
emailemail、email_verified(ユーザーが共有する場合のみ)
profilename、given_name、family_name、picture、updated_at(ユーザーが共有するもののみ)
offline_accessリフレッシュトークン

同意画面で共有内容を選ぶため、要求したスコープでもクレームが欠けることがあります。対応してください。

ネイティブおよびデスクトップアプリ

開発者ポータルで環境をネイティブ&デスクトップアプリとして登録します。リダイレクトURIは次のように使用できます:

  • プライベート使用URIスキーム の逆ドメイン形式 (RFC 8252 §7.1)、例: com.example.app:/oauth/identvia。myapp: のような短いスキームは拒否されます。
  • HTTPSアプリリンクを主張しました (iOSユニバーサルリンク / Androidアプリリンク)。
  • ループバック http://127.0.0.1:{port}/… または http://[::1]:{port}/…。任意のポートが一致します; パスは正確に一致する必要があります (RFC 8252 §7.3)。

iOS 17.4未満: ASWebAuthenticationSessionはhttps:// コールバックを信頼性高く返しません。これらのバージョンではプライベート使用スキームを優先してください; iOS 17.4以降はユニバーサルリンクを使用してください。