Map OAuth claims to user fields
This guide explains how to map the claims that an OAuth provider returns to the fields of a Casdoor user. Casdoor reads the basic profile, such as the username, the email address, and the avatar, on its own. User mapping fills in more fields, such as the phone number, the name, or the region.
Learning outcomes
- Map a claim of a provider to a user field.
- Know when Casdoor applies the mapping and which values it overwrites.
What you need
- An OAuth provider in Casdoor
- The names of the claims that the provider returns. See the documentation of the provider
Fields that you can map
| Field | Description |
|---|---|
phone | Phone number |
countryCode | Country calling code |
firstName | First name |
lastName | Last name |
region | Geographic region |
location | Location or address |
affiliation | Organization or company |
title | Job title |
homepage | URL of a personal website |
bio | Biography |
tag | Tag |
language | Preferred language |
gender | Gender |
birthday | Date of birth |
education | Education |
idCard | ID card number |
idCardType | Type of ID card |
Casdoor fills the standard fields id, username, displayName, email, and avatarUrl without mapping. For the OIDC type and the custom types, you can also map these standard fields and phone to other claims.
Provider types that support mapping
Casdoor can map only the claims that the provider type passes on to it. These types pass on the claims of the provider:
OIDCandCustomtoCustom10: all claims of the ID token and the user info response- Okta and Azure AD B2C: all claims of the user
- The types that Casdoor connects through the Goth library, such as Apple, Azure AD, Slack, Discord, and Gitea: the raw user data of the provider
- DingTalk: only
title, the job title from the corporate directory - WeChat: only its own IDs, such as
wechat_unionid - Kwai: only
genderandcity
Other types, such as Google and GitHub, pass on no claims, so a mapping has no effect for them.
Map a claim
The provider edit page shows User mapping for the OIDC type and the Custom to Custom10 types. It has one row per field, from ID to Title: the standard fields, phone, countryCode, firstName, lastName, region, location, affiliation, and title.
- In the Casdoor admin console, go to Identity > Providers and open the OAuth provider.
- In User mapping, enter the exact name of the claim in the response of the provider next to each field that you want to fill. Leave the other fields empty.
- Save the provider.
For example, to fill the first name from the claim given_name, enter given_name next to First name.
For other provider types, and for the fields without a row, such as homepage or bio, set the userMapping field of the provider through the API, for example with POST /api/update-provider. It is a JSON object from the user field to the claim name, such as {"title": "title"}.
Examples
| Provider | Field | Claim |
|---|---|---|
| Okta | firstName | given_name |
| Okta | lastName | family_name |
| Okta | language | locale |
| Azure AD B2C | phone | extension_PhoneNumber, a custom claim of the user flow |
| Azure AD B2C | title | jobTitle |
| Azure AD B2C | location | city |
| OIDC | firstName | given_name |
| OIDC | lastName | family_name |
| DingTalk | title | title |
For an enterprise identity provider, typical mappings carry organizational data:
title → jobTitle
affiliation → companyName
region → officeLocation
For a social provider, they carry profile details:
location → location
homepage → website
bio → about_me
Each provider has its own mapping. Configure it per provider, because providers name the same data differently.
How Casdoor applies the mapping
When a user signs in through the provider:
- Casdoor fetches the user information from the provider.
- Casdoor fills the standard fields.
- Casdoor applies the mapping and fills the mapped fields from the claims.
- Casdoor stores the claims that the provider type passes on in the user property
oauth_<provider-type>_extra, as JSON, including the claims that you haven't mapped.
The mapping fills only fields that are empty. It doesn't overwrite values that the user already has.
Verified email and phone
The OIDC and Custom types read two more keys of userMapping:
| Key | Default claim | Description |
|---|---|---|
emailVerified | email_verified | The email address is verified if the claim is true |
phoneVerified | phone_number_verified | The phone number is verified if the claim is true |
These keys have no row in User mapping. Without them, Casdoor reads the default claims of the ID token and the user info response. The values decide whether the Email and Phone binding rules can link the sign-in to an existing user, and whether the email address of a new user is verified. See How Casdoor links accounts.