OIDC handler bug in user info response handling for multiple claims of same type
Imagine user info endpoint returns this:
{"sub":"88421113","email":"[email protected]","email_verified":true,"role":["role1","role2"]}
This line: https://github.com/aspnet/Security/blob/dev/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectHandler.cs#L788
Adds the role claim with this as the value: [ "role1", "role2" ].
It should break the array into multiple claims. Here's an extension method that already does this: https://github.com/IdentityModel/IdentityModel2/blob/dev/src/IdentityModel/Client/JObjectExtensions.cs#L12
Any comment? This makes the userinfo feature pretty much unusable...
Triage is tomorrow, we'll take a look.
@PinpointTownes thoughts?
Assigning to @troydai for further investigation.
@muratg IMHO, it's clearly worth fixing this bug (it also impacted a bunch of ASOS/OpenIddict users and my recommendation was to use the identity token to flow "array" claims instead of using the userinfo endpoint, since Wilson fully supports that).
Note: @brockallen's approach is simple and fine, but it doesn't preserve the claim value type. It's not critical but it's something to remember before reusing his snippet as-is. You might want to take a look at how it's implemented in Wilson, instead: https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/master/src/System.IdentityModel.Tokens.Jwt/JwtPayload.cs#L307
@brockallen do you know an existing authentication server and client application can return claims in this way? It is helpful for me to build a repo quickly. Otherwise, I'll try to build a similar example or mock an auth server.
@PinpointTownes You cannot solely use the id_token to flow claims because spec:
5.4. Requesting Claims using Scope Values The Claims requested by the profile, email, address, and phone scope values are returned from the UserInfo Endpoint, as described in Section 5.3.2, when a response_type value is used that results in an Access Token being issued. However, when no Access Token is issued (which is the case for the response_type value id_token), the resulting Claims are returned in the ID Token.
@troydai IdentityServer does
here's the host: https://github.com/IdentityServer/IdentityServer4
and here's a client using hybrid flow and userinfo https://github.com/IdentityServer/IdentityServer4.Samples/tree/dev/Clients/src/MvcHybrid
@leastprivilege thanks.
As of today i am still getting this issue. Is there some workaround or approach changed. Using IdentityServer4 with AspNetCore 2.0.
From: OnUserInformationReceived event in IdentityServer4
options.Events = new OpenIdConnectEvents()
{
OnUserInformationReceived = context =>
{
//context.User
return Task.FromResult(0);
}
};
Value of context.User:
{{
"given_name": "User",
"family_name": "FName",
"address": "delhi",
"role": [
"localadmin",
"globaladmin"
],
"sub": "d5f1a5b2-f50b-4884-a1cb-ecc3d610d242"
}}
ERROR: InvalidCastException: Cannot cast Newtonsoft.Json.Linq.JArray to Newtonsoft.Json.Linq.JToken.
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler
InvalidCastException: Cannot cast Newtonsoft.Json.Linq.JArray to Newtonsoft.Json.Linq.JToken.
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler+
@leastprivilege @brockallen @troydai Any words ?
I found another workaround for this using a custom ClaimAction derived class suggested by @Tratcher in another thread. But i do believe that a system claim action should be provided in base asslembly to support this type of operation.
@Yadavvineet can you share this aproach for I have the same issue