カスタムOAuth
Casdoorはカスタムプロバイダーをサポートしています。 ただし、カスタムプロバイダーは3-legged 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}`認証が完了した後、カスタムプロバイダーは以下にリダイレクトする必要があります
https://{your-casdoor-hostname}/callback?code={code}このステップの後、CasdoorはURL内のcodeパラメータを認識します。
ScopeはAuth URLにアクセスするときに持ち運ばれるスコープパラメータであり、カスタムプロバイダーの要件に従って入力する必要があります。Token URLはaccessTokenを取得するためのAPIエンドポイントです。前のステップで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はaccessTokenを介してユーザー情報を取得するためのAPIエンドポイントです。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のログインページに他のサードパーティのログインプロバイダーと一緒に表示されます。