Користувацький OAuth
Casdoor підтримує користувацькі провайдери. Однак, користувацькі провайдери повинні слідувати стандартному процесу 3-стороннього OAuth, і повернені значення 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}`When PKCE is enabled, Casdoor automatically appends the necessary security parameters:
&code_challenge={code_challenge}&code_challenge_method=S256Після завершення авторизації користувацький провайдер повинен перенаправити на
https://{your-casdoor-hostname}/callback?code={code}Після цього кроку Casdoor розпізнає параметр code в URL.
Scope- це параметр області, який передається при доступі доAuth URL, і ви повинні заповнити його відповідно до вимог користувацького провайдера.Enable PKCEcontrols whether to use Proof Key for Code Exchange (PKCE) when authenticating with your custom provider. PKCE adds an extra security layer by proving that the client requesting the token is the same one that initiated the authorization flow. When enabled, Casdoor generates a unique cryptographic code verifier for each authentication attempt and includes the correspondingcode_challenge(SHA-256 hash of the verifier) andcode_challenge_method=S256in the authorization request. The code verifier is then sent to your provider's token endpoint during token exchange. Enable this if your OAuth provider requires or recommends PKCE.Token URL- це API-кінцева точка для отримання accessToken.Отримавши код на попередньому кроці, 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_tokenWhen PKCE is enabled, the request includes the code verifier:
curl -X POST -u "{ClientID}:{ClientSecret}" --data-binary "code={code}&grant_type=authorization_code&redirect_uri=https://{your-casdoor-hostname}/callback&code_verifier={code_verifier}" 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",
"phone": "+1234567890"
}The
phonefield is optional. If provided, it will be automatically saved to the user's phone number in Casdoor.Favicon- це URL логотипу користувацького провайдера.Цей логотип буде відображений на сторінці входу Casdoor разом з іншими сторонніми провайдерами входу.