OAuth providers
An OAuth provider lets users sign in to Casdoor with an account at an external identity provider, such as Google, GitHub, or WeChat. The icon of the provider appears on the sign-in and sign-up pages of the applications that use it.
Supported providers
| Provider | Logo | Provider | Logo | Provider | Logo | Provider | Logo |
|---|---|---|---|---|---|---|---|
| ADFS | Alipay | Amazon | Apple | ||||
| Auth0 | Azure AD | Azure AD B2C | Baidu | ||||
| Bilibili | Bitbucket | Box | Casdoor | ||||
| Cloud Foundry | Dailymotion | Deezer | DigitalOcean | ||||
| DingTalk | Discord | Tiktok | Dropbox | ||||
| Eve Online | Fitbit | Gitea | |||||
| Gitee | GitHub | GitLab | |||||
| Heroku | InfluxCloud | Infoflow | |||||
| Intercom | Kakao | Lark | Lastfm | ||||
| Line | Mailru | Meetup | |||||
| Microsoft | Naver | Nextcloud | Okta | ||||
| OneDrive | Oura | Patreon | PayPal | ||||
| Salesforce | Shopify | Slack | |||||
| SoundCloud | Spotify | Steam | Strava | ||||
| Stripe | Telegram | TikTok | Tumblr | ||||
| Twitch | Typetalk | Uber | |||||
| VK | WeCom | ||||||
| WePay | Xero | Yahoo | Yammer | ||||
| Yandex | Zoom | SMS | |||||
| Battle.net | OIDC |
Each provider type has its own guide in this section. For a provider that isn't listed, use the OIDC type if it supports OpenID Connect (OIDC), or a custom OAuth provider otherwise.
Add an OAuth provider
-
At the identity provider, register an OAuth application:
- Set its callback URL, which the provider may call the redirect URI, to the callback URL of Casdoor:
https://<your-casdoor-host>/callback. - Choose the scopes, which determine the user data that Casdoor receives.
- Copy the client ID and the client secret. Keep the client secret private.
The callback URL at the provider is the URL of Casdoor, not the URL of your own application. See Redirect URL and callback URL.
- Set its callback URL, which the provider may call the redirect URI, to the callback URL of Casdoor:
-
In the Casdoor admin console, go to Identity > Providers and add a provider.
-
Set Category to
OAuthand select the Type, such asGoogleorGitHub. -
Enter the Client ID and the Client secret from the identity provider.
-
Save the provider.
Add the provider to an application
- Open the edit page of the application and go to the Providers tab.
- Add the provider and choose whether users can sign up, sign in, and unlink with it. See Add providers to an application.
- Save the application.
How Casdoor links accounts
When a user signs in with an OAuth provider, Casdoor first looks for the Casdoor user that is already linked to the identity at the provider. If there is none, it checks the fields of the Binding rule of the provider, set on the Providers tab of the application, in order, and links the first user that matches. You can therefore add an OAuth provider to an existing user base without linking accounts by hand.
| Rule | Links the user when |
|---|---|
Email | The provider reports the email address as verified, and a user of the organization has the same email address. That user must have a verified email address, or must not have been created by a sign-up through an application |
Phone | The provider reports the phone number as verified, and a user of the organization has the same phone number and country code |
Name | A user of the organization has the same username, without regard to case |
The default Binding rule is Email, Phone, and Email, Phone, Name for DingTalk, where Name only matches the unionid from the address book of your organization, not the nickname. For other providers, add Name only if usernames at the provider and in Casdoor belong to the same people. An empty Binding rule turns off linking. If the existing user has multi-factor authentication (MFA) turned on, Casdoor asks for the second factor before the sign-in completes.
Whether an email address or a phone number counts as verified depends on the provider type. For example, Google reports the email_verified claim, the OIDC type reads email_verified and phone_number_verified, and GitHub, GitLab, and DingTalk count every email address that they return as verified. A custom provider reads the user mapping keys emailVerified and phoneVerified. See Map OAuth claims to user fields.
Sign up with a provider
If no user matches and the application allows sign-up with the provider, Casdoor creates a user:
- Casdoor converts the email address to lowercase.
- If another user of the organization already has the email address, the sign-up fails with
Email already exists. If another user has the phone number with the same country code, it fails withPhone already exists. Casdoor doesn't create a second user with the same email address or phone number. Only the Binding rule decides whether the sign-in belongs to the existing user. - The email address of the new user is verified if the provider reports it as verified. The
email_verifiedclaim of the tokens that Casdoor issues therefore follows the provider.
Map additional user fields
Casdoor reads the username, the email address, and the avatar from the provider. To fill in more fields, such as the phone number or the job title, map the claims of the provider to user fields. See Map OAuth claims to user fields.
Use the access token of the provider
After an OAuth sign-in, Casdoor stores the access token of the provider on the user. Your application can read it from /api/get-account and call the API of the provider, such as the GitHub API or the Google Drive API, on behalf of the user. Only the user and the administrators of the organization can see the token. See Get the access token of an external provider.
Route requests through a proxy
If the identity provider is reachable only through a proxy, turn on Enable proxy on the provider. Casdoor then sends the requests of the sign-in flow through the SOCKS5 proxy that socks5Proxy in conf/app.conf sets. Some provider types always use the proxy, whatever this setting: GitHub, Google, Facebook, LinkedIn, Steam, Line, Amazon, Instagram, TikTok, Twitter, Uber, and Yahoo.
A provider that belongs to an organization other than admin, built-in, and the trusted organizations sends the requests of the sign-in flow only to Internet addresses, and Enable proxy has no effect on it. The provider types in the list above are the exception: they always use the proxy. See Which addresses a provider can reach.