Custom Provider for Casdoor
Casdoor supports custom providers. However, the custom providers must follow the standard process of 3-legged OAuth, and the return values of Token URL
and UserInfo URL
must conform to the format specified by Casdoor.
To create a new custom provider, navigate to the provider page of Casdoor, and select “Custom” in the Type field. You will then need to fill in Client ID
, Client Secret
, Auth URL
, Scope
,Token URL
, UserInfo URL
, and Favicon
.
Auth URL
是自定义提供商的 OAuth 登录页面地址。If you fill in
https://door.casdoor.com/login/oauth/authorize
as theAuth URL
, then, when a user logs in with this custom provider, the browser will first redirect tohttps://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}
After this step, Casdoor will recognize the code parameter in the URL.
Scope
is the scope parameter carried when accessing theAuth URL
, and you should fill it in as per the custom provider's requirements.Token URL
is the API endpoint for obtaining the accessToken.Once you obtain the code in the previous step, Casdoor should use it to get the accessToken.
If you fill in
https://door.casdoor.com/api/login/oauth/access_token
as theToken URL
, then Casdoor will access it using the following commandcurl -X POST -u "{ClientID}:{ClientSecret}" --data-binary "code={code}&grant_type=authoritiation_code&redirect_uri=https://{your-casdoor-hostname}/callback" https://door.casdoor.com/api/login/oauth/access_token
The custom provider should return at least the following information:
{
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6Ixxxxxxxxxxxxxx",
"refresh_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6xxxxxxxxxxxxxx",
"token_type": "Bearer",
"expires_in": 10080,
"scope": "openid profile email"
}UserInfo URL
is the API endpoint for obtaining user information via the accessToken.If you fill in
https://door.casdoor.com/api/userinfo
as theUserInfo URL
, then Casdoor will access it using the following commandcurl -X GET -H "Authorization: Bearer {accessToken}" https://door.casdoor.com/api/userinfo
The custom provider should return at least the following information:
{
"name": "admin",
"preferred_username": "Admin",
"email": "admin@example.com",
"picture": "https://casbin.org/img/casbin.svg"
}Favicon
是自定义提供商的标识URL。This logo will be displayed on Casdoor's login page together with other third-party login providers.