Open
Description
Hi
We have set up cookie sharing between my ASP.NET and ASP.NET Core application. I did this using the guidance found here:
- https://learn.microsoft.com/en-us/aspnet/core/security/cookie-sharing?view=aspnetcore-8.0#share-authentication-cookies-between-aspnet-4x-and-aspnet-core-apps
- Share authentication cookies between ASP.NET 4.x and ASP.NET Core apps dotnet/AspNetCore.Docs#21987
- Cookie compatibility between OWIN and Microsoft.AspNetCore.Authentication #435
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
Labels
No labels