Skip to main content

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​

FieldDescription
phonePhone number
countryCodeCountry calling code
firstNameFirst name
lastNameLast name
regionGeographic region
locationLocation or address
affiliationOrganization or company
titleJob title
homepageURL of a personal website
bioBiography
tagTag
languagePreferred language
genderGender
birthdayDate of birth
educationEducation
idCardID card number
idCardTypeType 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:

  • OIDC and Custom to Custom10: 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 gender and city

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.

  1. In the Casdoor admin console, go to Identity > Providers and open the OAuth provider.
  2. 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.
  3. 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​

ProviderFieldClaim
OktafirstNamegiven_name
OktalastNamefamily_name
Oktalanguagelocale
Azure AD B2Cphoneextension_PhoneNumber, a custom claim of the user flow
Azure AD B2CtitlejobTitle
Azure AD B2Clocationcity
OIDCfirstNamegiven_name
OIDClastNamefamily_name
DingTalktitletitle

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:

  1. Casdoor fetches the user information from the provider.
  2. Casdoor fills the standard fields.
  3. Casdoor applies the mapping and fills the mapped fields from the claims.
  4. 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:

KeyDefault claimDescription
emailVerifiedemail_verifiedThe email address is verified if the claim is true
phoneVerifiedphone_number_verifiedThe 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.

See also​