IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

Providing two claims of the same type, turns claim into array

Open farshidmirza opened this issue 9 years ago • 13 comments

  • [x] I read and understood how to enable logging

Issue / Steps to reproduce the problem

name claim is not standard when I ask fro userinfo from clinet

{
  "sub": "10",
  "name": [ "user.name", "User Name" ],
  "AspNet.Identity.SecurityStamp": "240dc561-37ff-4eb9-a58a-f760d1b9abaa",
  "role": [ "CSM_User", "dev", "admin", "SuperAdmin", "Admin", "LdapUser", "TranslationAdmin" ],
  "UnitCode": "3120002566",
  "JobTitle": "Kidemli Yazilim Uzmani",
  "JobPhone": "0212 999 9349",
  "given_name": "User",
  "family_name": "Name",
  "birthdate": "03/06/1978",
  "email": "[email protected]",
  "gender": "male"
}

name claim mest be a string

http://openid.net/specs/openid-connect-core-1_0.html#StandardClaims

Relevant parts of the log file

<log goes here>

farshidmirza avatar Aug 24 '17 07:08 farshidmirza

Well - you give us the wrong data. If there are two claims of the same type, they become an array.

leastprivilege avatar Aug 24 '17 08:08 leastprivilege

Yes but it must create just one name claim. it must be a restriction I think

farshidmirza avatar Aug 24 '17 12:08 farshidmirza

Why can't the user have two names? Or two emails? There is a reason we do certain things.

brockallen avatar Aug 24 '17 13:08 brockallen

I am investigating on this issue but as I see Application user has name claim and UserName field and Get user claim method return user name as name claim

farshidmirza avatar Aug 24 '17 13:08 farshidmirza

In this code :

public async Task GetProfileDataAsync(ProfileDataRequestContext context)
        {
            string sub = context.Subject.GetSubjectId();

            ApplicationUser user = await _userManager.FindByIdAsync(sub);
            ClaimsPrincipal principal = await _claimsFactory.CreateAsync(user);

            List<Claim> cs = principal.Claims.ToList();

            context.IssuedClaims = cs;
        }

_claimsFactory.CreateAsync change UserName to name claim

farshidmirza avatar Aug 24 '17 14:08 farshidmirza

dear @brockallen
this is a rule http://openid.net/specs/openid-connect-core-1_0.html#StandardClaims

farshidmirza avatar Aug 24 '17 14:08 farshidmirza

Where does it say you can't have more than one?

brockallen avatar Aug 24 '17 19:08 brockallen

you right but dotnet security team believes that it cannot be more than one :)

farshidmirza avatar Aug 24 '17 20:08 farshidmirza

I don't follow.

brockallen avatar Aug 24 '17 23:08 brockallen

this behavior is by design. closing.

leastprivilege avatar Sep 03 '17 09:09 leastprivilege

I think this behavior does lead to issues.

We've had to interact with other OpenID Connect providers who expect name to be a String as per the standard. In our case adding Windows login to User who has a name set, will also automatically return the Windows username along with the existing name claim.

i.e. name: ['WindowsLogon', 'Firstname Surname']

Does anyone know where this automatic inclusion of claims takes place, is there some-point I could intercept or config I could change?

domisginger avatar Jan 29 '18 11:01 domisginger

Having now seen this issue https://github.com/aspnet/Identity/issues/1394 I think its the problem of ASP.NET Core Identity not Identity Server.

Also adding for future readers adding this line into Startup.cs below AddIdentityServer() and above AddMvc resolved everything services.AddIdentityServerUserClaimsPrincipalFactory<ApplicationUser, IdentityRole>();

domisginger avatar Jan 29 '18 11:01 domisginger

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 13 '20 18:01 lock[bot]