To start, I am a developer and this is my first time working with OIDC and SSO. I did not set up the IDP (PingFederate) side of things, only wrote the code to add it to a web app. The SSO is properly signing in through the IDP.
My trouble is accessing custom claims that should be in the token, like claims loaded through LDS. The specific claim I am trying to access is configured as samAccountName on the IDP side. When I run the debugger to look at the claims, only three claims are present: NameIdentifier, jti, and auth_time.
Here is the code in which I am accessing the claims
protected override async Task OnInitializedAsync()
{
authState = await AuthStateProvider.GetAuthenticationStateAsync();
claims = authState.User.Claims.ToList();
var jtiClaim = claims.FirstOrDefault(c => c.Type == "jti")?.Value;
var authTimeClaim = claims.FirstOrDefault(c => c.Type == "auth_time")?.Value;
var nameIdentifier = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
getRoles();
setDdsButtonVisiblity();
handDdsPageAccess();
}
These are the claims within the claims list above. That custom claim, the samAccountName, is not present here.
Picture of claims within debugger
I have also tried mapping the samAccountName claim within the OIDC middleware code, but that results in the same issue.
This is the middleware code below
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
.AddOpenIdConnect(options =>
{
var serviceProvider = builder.Services.BuildServiceProvider();
var appSettings = serviceProvider.GetRequiredService<IOptions<AppSettings>>().Value;
options.Authority = appSettings.OidcAuthority;
options.ClientId = appSettings.OidcClientId;
options.ClientSecret = appSettings.OidcClientSecret;
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.ResponseType = OpenIdConnectResponseType.Code;
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("profile");
options.ClaimActions.MapJsonKey("samAccountName", "samAccountName");
});
I have checked out other posts and resources, but I can’t quite figure it out. I would greatly appreciate in advice.
sga2224 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
6