Can't get user information from Identity Server 3

I am trying to follow this tutorial on how to create an Identity Server client with hybrid thread. This is all well and good until I hit the goal of getting user information through the user information endpoint.

Notifications = new OpenIdConnectAuthenticationNotifications
{
    AuthorizationCodeReceived = async n =>
    {
        var userInfoClient = new UserInfoClient(new Uri(Constants.UserInfoEndpoint).ToString());
        var userInfoResponse = await userInfoClient.GetAsync(n.ProtocolMessage.AccessToken);

        var identity = new ClaimsIdentity(n.AuthenticationTicket.Identity.AuthenticationType);

        identity.AddClaims(userInfoResponse.Claims);

        n.AuthenticationTicket = new AuthenticationTicket(identity, n.AuthenticationTicket.Properties);
    }
}

      

I am getting compile error at the point where claims are added: identity.AddClaims(userInfoResponse.Claims);

There are actually two error areas. When when pointing to arguments it says:

The argument type 'System.Collections.Genereic.IEnumerable [mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089]' is not assigned to the parameter type '[mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = be77089c56] '

And the other, specifying the name of the method, says:

The type "Requirement" is defined in an assembly that is not referenced. You must add a reference to the assembly "System.Security.Claims, Version = 4.0.1.0, Culture = neutral, PublicKeyToken = 503f5 .. '

I tried to add a reference to this assembly via nuget but then another conflict started. There is an ambiguous link for System.Security.Claim between IdentityProvider and mscorlib.

What can I do to achieve my goal of assigning user statements to the identity of a registered user?

+3


source to share


1 answer


Looking at the tutorial, this line:

identity.AddClaims(userInfoResponse.Claims);

      

needs to be changed as follows:

identity.AddClaims(userInfoResponse.GetClaimsIdentity().Claims);

      



The second compiler error occurs when using a type Claim

without specifying a namespace. Determine where you are using Claim

explicitly and add the correct namespace to it.

Note:

this: is userInfoResponse.GetClaimsIdentity().Claims

equivalent to:

userInfoResponse.Claims.Select(c => new System.Security.Claim(c.Item1, c.Item2))

      

0


source







All Articles