Custom OAuth
Casdoor รองรับผู้ให้บริการแบบกำหนดเอง อย่างไรก็ตาม ผู้ให้บริการแบบกำหนดเองต้องปฏิบัติตามกระบวนการมาตรฐานของ OAuth 3-legged และค่าที่ส่งกลับของ Token URL และ UserInfo URL ต้องสอดคล้องกับรูปแบบที่ Casdoor กำหนด
Overview
Custom OAuth providers allow you to integrate any OAuth 2.0 compliant authentication service with Casdoor, even if it's not officially supported. This is useful when you want to integrate with:
- Internal enterprise OAuth servers
- Self-hosted authentication systems
- Third-party services not yet officially supported by Casdoor
Multiple Custom Providers Support
Casdoor supports up to 10 different custom OAuth providers simultaneously. When creating custom providers, you can choose from the following types:
- Custom - The first custom provider
- Custom2 through Custom10 - Additional custom providers
This allows you to integrate multiple custom OAuth services without conflicts. Each custom provider maintains its own separate configuration and user data fields.
Creating a Custom Provider
To create a new custom provider, navigate to the provider page of Casdoor, and select one of the custom types ("Custom", "Custom2", "Custom3", etc.) in the Type field. จากนั้นคุณจะต้องกรอก Client ID, Client Secret, Auth URL, Scope,Token URL, UserInfo URL, และ Favicon

Auth URLเป็นที่อยู่หน้าเว็บ OAuth สำหรับการเข้าสู่ระบบของผู้ให้บริการแบบกำหนดเองหากคุณกรอก
https://door.casdoor.com/login/oauth/authorizeเป็นAuth URLแล้ว เมื่อผู้ใช้เข้าสู่ระบบด้วยผู้ให้บริการแบบกำหนดเองนี้ เบราว์เซอร์จะเปลี่ยนเส้นทางไปยังhttps://door.casdoor.com/login/oauth/authorize?client_id={ClientID}&redirect_uri=https://{your-casdoor-hostname}/callback&state={State_generated_by_Casdoor}&response_type=code&scope={Scope}หลังจากที่การอนุญาตเสร็จสิ้นแล้ว ผู้ให้บริการแบบกำหนดเองควรเปลี่ยนเส้นทางไปยัง
https://{your-casdoor-hostname}/callback?code={code}หลังจากขั้นตอนนี้ Casdoor จะรู้จักพารามิเตอร์ code ใน URL
Scopeเป็นพารามิเตอร์ scope ที่ใช้เมื่อเข้าถึงAuth URLและคุณควรกรอกตามที่ผู้ให้บริการแบบกำหนดเองกำหนดToken URLเป็นจุดสิ้นสุด API สำหรับการรับ accessTokenเมื่อคุณได้รับ code ในขั้นตอนก่อนหน้านี้ Casdoor ควรใช้มันเพื่อรับ accessToken
หากคุณกรอก
https://door.casdoor.com/api/login/oauth/access_tokenเป็นToken URLแล้ว Casdoor จะเข้าถึงมันโดยใช้คำสั่งต่อไปนี้curl -X POST -u "{ClientID}:{ClientSecret}" --data-binary "code={code}&grant_type=authorization_code&redirect_uri=https://{your-casdoor-hostname}/callback" https://door.casdoor.com/api/login/oauth/access_tokenผู้ให้บริการแบบกำหนดเองควรส่งคืนข้อมูลอย่างน้อยต่อไปนี้:
{
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6Ixxxxxxxxxxxxxx",
"refresh_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6xxxxxxxxxxxxxx",
"token_type": "Bearer",
"expires_in": 10080,
"scope": "openid profile email"
}UserInfo URLเป็นจุดสิ้นสุด API สำหรับการรับข้อมูลผู้ใช้ผ่าน accessTokenหากคุณกรอก
https://door.casdoor.com/api/userinfoเป็นUserInfo URLแล้ว Casdoor จะเข้าถึงมันโดยใช้คำสั่งต่อไปนี้curl -X GET -H "Authorization: Bearer {accessToken}" https://door.casdoor.com/api/userinfoผู้ให้บริการแบบกำหนดเองควรส่งคืนข้อมูลอย่างน้อยต่อไปนี้:
{
"name": "admin",
"preferred_username": "Admin",
"email": "admin@example.com",
"picture": "https://casbin.org/img/casbin.svg"
}Faviconเป็น URL ของโลโก้สำหรับผู้ให้บริการแบบกำหนดเองโลโก้นี้จะถูกแสดงบนหน้าเข้าสู่ระบบของ Casdoor ร่วมกับผู้ให้บริการเข้าสู่ระบบบุคคลที่สามอื่นๆ