Skip to content

Shared Cookie between ASP.NET and ASP.NET Core not reading custom claims #535

Open
@Schoof-T

Description

@Schoof-T

Hi

We have set up cookie sharing between my ASP.NET and ASP.NET Core application. I did this using the guidance found here:

This all works great, but we have now noticed that custom claims we are adding in our ASP.NET Core application are not being read/remembered in the ASP.NET application.

We are adding the custom claim in ASP.NET Core as follows:

        .AddOpenIdConnect("oidc", options =>
        {
           ....
            options.Events = new OpenIdConnectEvents
            {
                OnTokenValidated = async (ctx) =>
                {
                    var claims = new List<Claim>();
                    var claim = new Claim("NEWCLAIM", "TEST");
                    claims.Add(claim);

                    var appIdentity = new ClaimsIdentity(claims);
                    ctx.Principal.AddIdentity(appIdentity);

                    return;
                }
            };
        });

And in ASP.NET we are reading the claims as follows:

            var principal = Thread.CurrentPrincipal as ClaimsPrincipal;
            var identity =  principal?.Identity as ClaimsIdentity;
            var claim = identity?.Claims.FirstOrDefault(x => x.Type == "NEWCLAIM");

However, the 'NEWCLAIM' is missing. All the other default claims we get from the identity provider are there.

Any ideas, something we might be missing?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions