Langsung ke konten

Referensi

OpenID Connect

Tidak memakai PHP? Identvia adalah penyedia OpenID Connect standar. Gunakan pustaka tersertifikasi apa pun dan arahkan ke issuer di bawah.

Salin prompt untuk agen AI Anda

Memakai agen coding? Prompt ini mengarahkannya ke dokumentasi ini dan mencantumkan aturan yang wajib diikutinya. Tinjau kode yang ditulisnya seperti kode lainnya.

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.

Penemuan

Issuerhttps://id.identvia.com
Penemuanhttps://id.identvia.com/.well-known/openid-configuration
Otorisasihttps://id.identvia.com/oauth/authorize
Tokenhttps://id.identvia.com/oauth/token
Userinfohttps://id.identvia.com/oauth/userinfo
JWKShttps://id.identvia.com/oauth/jwks.json
Pencabutanhttps://id.identvia.com/oauth/revoke
Akhiri sesihttps://id.identvia.com/oauth/logout

Aturan yang ditegakkan Identvia

  • Hanya alur kode otorisasi (response_type=code). Tanpa implicit atau hybrid.
  • PKCE dengan S256 wajib untuk klien publik (aplikasi satu halaman, seluler, dan native) dan disarankan untuk semua klien. Aplikasi sisi server yang mengautentikasi dengan client secret boleh tidak memakainya, dan juga boleh tidak mengirim nonce, sebagaimana diizinkan OpenID Connect.
  • URI pengalihan cocok persis, karakter demi karakter. Tanpa wildcard atau fragmen. http://localhost hanya di lingkungan Development.
  • Kode otorisasi sekali pakai dan kedaluwarsa setelah 60 detik. Memakai ulang membatalkan token yang dihasilkannya.
  • ID token ditandatangani RS256. Access token berlaku 10 menit. Refresh token (scope offline_access) berputar setiap pakai; memutar ulang yang lama membatalkan seluruh rantai.
  • Callback menyertakan iss (RFC 9207). Periksa.
  • sub bersifat pairwise: setiap aplikasi melihat ID berbeda dan stabil untuk orang yang sama.

1. Permintaan otorisasi

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

Opsional: prompt=none|login|consent, max_age, login_hint.

2. Permintaan token

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=…

Klien publik mengirim client_id di tubuh, bukan rahasia.

Response
{
  "token_type": "Bearer",
  "access_token": "eyJ…",
  "expires_in": 600,
  "id_token": "eyJ…",
  "refresh_token": "…",          // hanya dengan offline_access
  "scope": "openid email profile"
}

3. Validasi ID token

  1. Verifikasi tanda tangan dengan kunci JWKS yang kid-nya cocok. Terima hanya RS256.
  2. iss sama dengan https://id.identvia.com; aud berisi client ID Anda; azp, jika ada, adalah client ID Anda.
  3. exp di masa depan dan iat tidak (izinkan satu menit selisih).
  4. nonce sama dengan yang Anda kirim.
  5. Jika Anda mengirim max_age, periksa auth_time.

Klaim

ScopeKlaim
openidsub, auth_time, amr
emailemail, email_verified (hanya jika pengguna membagikannya)
profilename, given_name, family_name, picture, updated_at (hanya yang dibagikan pengguna)
offline_accessRefresh token

Pengguna memilih apa yang dibagikan di layar persetujuan, jadi scope yang diminta mungkin kembali tanpa klaimnya. Tangani itu.

Aplikasi native dan desktop

Daftarkan lingkungan sebagai Aplikasi Native & desktop di portal pengembang. URI pengalihan dapat menggunakan:

  • Skema URI penggunaan pribadi dalam bentuk domain-terbalik (RFC 8252 §7.1), misalnya com.example.app:/oauth/identvia. Skema pendek seperti myapp: ditolak.
  • Tautan Aplikasi HTTPS yang D声klaim (Tautan Universal iOS / Tautan Aplikasi Android).
  • Loopback http://127.0.0.1:{port}/… atau http://[::1]:{port}/…. Port mana pun cocok; jalur harus cocok persis (RFC 8252 §7.3).

iOS lebih tua dari 17.4: ASWebAuthenticationSession tidak selalu mengembalikan https:// callback dengan andal. Lebih baik menggunakan skema penggunaan pribadi pada versi tersebut; gunakan Tautan Universal mulai iOS 17.4 dan seterusnya.