Custom name and role claim name - Xabaril/Acheve.TestHost GitHub Wiki

Name and Role claim names

In .Net Core, in order to maintain backwards compatibility with .Net Standard and the Full Framework, there are 2 claim types with special treatment: name and role.

Name

Name claim type will be used when you request a claimsPrincipal.Identity.Name property. By default the infrastucture use the value of ClaimTypes.Name property which is http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name.

If your identity provider use another type for this claim you should change the default value. For example, if you use IdentityServer to issue the JWT tokens, by default it uses the "name" type for this claim.

Role

Role claim type will be used when you call claimsPrincipal.IsInRole("Administrator"). By default the infrastucture use the value of ClaimTypes.Role property which is http://schemas.microsoft.com/ws/2008/06/identity/claims/role.

If your identity provider use another type for this claim you should change the default value.

In the TestServerOptions, you can configure the claim type your application will use. By default it will use the default claim names used in the framework.

services.AddAuthentication(TestServerDefaults.AuthenticationScheme)
    .AddTestServer(options =>
    {
        options.NameClaimType = "name";
        options.RoleClaimType = "role";
    });