ต่อระบบ
OIDC สำหรับทุกภาษา
endpoint, scope, authorization code flow ทีละขั้น และวิธีตรวจ access token
Pi Auth เป็น OpenID Connect provider มาตรฐาน ภาษาใดก็ตามที่มีไลบรารี OIDC — Go, Python, .NET, PHP, แอปมือถือ — ล็อกอินผู้ใช้และอ่าน claim ของ tenant กับสิทธิ์ชุดเดียวกับที่ SDK Next.js ใช้ได้
Endpoint
ทุกอย่างประกาศไว้ใน discovery document; ด้านล่างคือ path ที่ใช้บ่อย เปลี่ยน origin เป็น Pi Auth ของคุณ
| Endpoint | Path |
|---|---|
| Discovery | /.well-known/openid-configuration |
| Authorization | /api/auth/oauth2/authorize |
| Token | /api/auth/oauth2/token |
| UserInfo | /api/auth/oauth2/userinfo |
| JWKS | /api/auth/jwks |
| สิทธิ์ที่มีผล (เมื่อได้ perms_ref) | /api/v1/me/permissions |
Scope
| Scope | เพิ่มอะไร |
|---|---|
openid | บังคับ — ออก id_token |
profile | name, picture |
email | email, email_verified |
offline_access | refresh token เพื่อต่ออายุ access token โดยไม่ต้องล็อกอินใหม่ |
tenant | tid, tslug, mid, trole, org, pos, groups, attrs ใน access token |
permissions | perms (หรือ perms_ref) ของแอปที่ระบุใน resource |
ทำ flow เองทีละขั้น
Redirect ไป /authorize
ใช้
response_type=code, PKCE (S256),stateและnonceแบบสุ่ม และ resource indicator เพื่อให้ access token ออกสำหรับแอปของคุณGEThttps://auth.suphark.com/api/auth/oauth2/authorize ?response_type=code &client_id=AOWrBtppsYLxThsohmXWS7JjCknWiog9 &redirect_uri=https://pdf.suphark.com/auth/callback &scope=openid profile email offline_access tenant permissions &state=…&nonce=… &code_challenge=…&code_challenge_method=S256 &resource=urn:pi:app:AOWrBtppsYLxThsohmXWS7JjCknWiog9แลก code
confidential client ยืนยันตัวด้วย client_secret; public client อาศัย PKCE อย่างเดียว
POST /api/auth/oauth2/tokengrant_type=authorization_code &code=… &redirect_uri=https://pdf.suphark.com/auth/callback &client_id=…&client_secret=… &code_verifier=… &resource=urn:pi:app:AOWrBtppsYLxThsohmXWS7JjCknWiog9ตรวจ access token
- ลายเซ็นกับ JWKS (cache ไว้; key หมุนทุก 90 วัน)
issตรงกับ origin ของ Pi Auth,audตรงกับurn:pi:app:<client_id>,expยังไม่หมด (เผื่อ ~60 วินาที)- ตรวจว่า
nonceใน id_token ตรงกับที่ส่งไป
ใช้ claim
ใช้
mid(membership) เป็น key ข้อมูลของคุณ ตรวจสิทธิ์ด้วยpermsและแสดงorg.path/pos.codeที่ UI ต้องการ รายการเต็มอยู่ใน Pi Auth ทำงานอย่างไรต่ออายุก่อนหมด
POST /api/auth/oauth2/tokengrant_type=refresh_token&refresh_token=…&client_id=…&client_secret=…
การเลือกองค์กร
ผู้ใช้ที่เป็นสมาชิกหลายองค์กรจะเลือกตอนล็อกอิน และโทเค็นผูกกับที่เลือก ถ้าแอปรู้อยู่แล้วว่าให้บริการ tenant ไหน ส่ง tenant_hint=<slug> ไปกับ authorize request (หรือใช้ auth subdomain ของ tenant): สมาชิกที่ active ของ tenant นั้นจะถูกสลับให้ — แม้มี session ของ Pi Auth อยู่แล้ว — และข้ามหน้าเลือก ถ้าไม่ได้เป็นสมาชิก โทเค็นจะเป็นของ tenant ที่ active อยู่ จึงต้องเทียบ tslug กับ tenant ที่ขอเสมอ (SDK Next.js ทำให้และล้มเหลวด้วย TENANT_MISMATCH)
ออกจากระบบ
ล้าง session cookie ของแอปเอง; session ของ Pi Auth อยู่ต่อจนหมดอายุหรือออกจากระบบที่นั่น เมื่อ session ถูกถอนในคอนโซล (โดยสมาชิกหรือผู้ดูแล) Pi Auth ส่ง event session.revoked และ SDK รับ OIDC back-channel logout token มาตรฐานที่ /auth/backchannel-logout ด้วย