How to map a user attribute to a standard OIDC claim in keycloak

I have a docker container with Keycloak.
I am trying to understand how the authentication works, especially with regards to claims mapping.

I have created a realm and in Realm Settings > User Profile I have created a new custom attribute

With this simple configuration, after login from my AspNet Core Razor application, I am able to receive the claim phone_number in token (access_token, id_token, depending on my configuration). The phoneNumber attribute also appear in registration form as well, which is good.

{
  "exp": 1726218720,
  "iat": 1726218420,
  "auth_time": 1726218420,
  "jti": "86a79a1a-ccd2-478b-9b98-6d67e94207a6",
  "iss": "http://localhost:9001/realms/web-portal",
  "aud": "account",
  "sub": "d7af94a3-a675-4dd1-b58f-8d2baa29c1f1",
  "typ": "Bearer",
  "azp": "web-portal-client",
  "sid": "8391d1be-584f-4f3c-91c4-55979a57e635",
  "acr": "1",
  "allowed-origins": [
    "http://localhost:9999"
  ],
  "realm_access": {
    "roles": [
      "offline_access",
      "default-roles-web portal",
      "uma_authorization"
    ]
  },
  "resource_access": {
    "account": {
      "roles": [
        "manage-account",
        "manage-account-links",
        "view-profile"
      ]
    }
  },
  "scope": "openid profile offline_access phone email",
  "email_verified": true,
  "name": "Tenant Admin",
  "phone_number": "123456789",
  "preferred_username": "[email protected]",
  "given_name": "Tenant",
  "family_name": "Admin",
  "email": "[email protected]"
}

However, because my client is requesting the standard phone scope

  builder.Services
    .AddAuthentication(options => {
        options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
    })
    .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => {
        // omitted for brevity
    })
    .AddOpenIdConnect(options => {
        options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        options.Authority = $"{tokenConfiguration.Authority}/realms/{tokenConfiguration.Realm}";
        options.RequireHttpsMetadata = tokenConfiguration.RequireHttpsMetadata;
        options.ClientId = tokenConfiguration.ClientId;
        options.ClientSecret = tokenConfiguration.ClientSecret;
        options.ResponseType = OpenIdConnectResponseType.Code;
        options.UsePkce = true;

        options.Scope.Clear();
        options.Scope.Add("openid");
        options.Scope.Add("profile");
        options.Scope.Add("email");
        options.Scope.Add("phone");
        options.Scope.Add("offline_access");
        options.MapInboundClaims = false;

        options.SaveTokens = true;

        options.ClaimActions.MapJsonKey("email_verified", "email_verified");
        options.ClaimActions.MapJsonKey("phone_verified", "phone_verified");
        options.GetClaimsFromUserInfoEndpoint = true;
        options.TokenValidationParameters = new TokenValidationParameters {
            NameClaimType = "name",
            RoleClaimType = "roles"
        };
  });

I expected to automatically receive two standard claims:

  • phone_number
  • phone_number_verified

Is this correct? I am new to keycloak and mainly trying to match the knowledge I have with other IdPs. I have also checked this question which is very similar but has no answer.

2

Maybe I missunderstood, but you could try following steps to get a “phone_number_verified” claim.

  1. Add both phoneNumber and phoneNumberVerified attribute to userprofile.

  2. Go to Client scopes, click “phone” scope, switch to Mappers tab then click phone number verified. Make sure this is set to the phoneNumberVerified attribute.

  3. Add the user with this attribute value to true or false.Then after login. The accessToken will contains this “phone_number_verified” claim.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật