Not able to read the claims in Asp.net 6 web app after connecting to ADFS

Subash Subramaniam 1 Reputation point
2022-12-07T21:55:39.5+00:00

I have tried various ways to get the claims but couldn't succeed.

But sure that the authentication from ADFS is sending the Name Identifier and other claim information. Used Fiddler verify that information during the testing.

Below is my code. Appreciate your help to fix my issue

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSession();
builder.Services.AddHttpContextAccessor();

// Add services to the container.
builder.Services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => false;
options.MinimumSameSitePolicy = SameSiteMode.None;
options.HttpOnly = HttpOnlyPolicy.Always;
options.Secure = CookieSecurePolicy.SameAsRequest;
});
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = WsFederationDefaults.AuthenticationScheme;
}).
AddWsFederation(options =>
{
options.Wtrealm = AppSettings.GetAppSetting("ida:Wtrealm");
options.Wreply = AppSettings.GetAppSetting("ida:Wreply");
options.MetadataAddress = AppSettings.GetAppSetting("ida:ADFSMetadata");

}).AddCookie(options =>
{
options.CookieManager = new SystemWebCookieManager();

});

builder.Services.RegisterAllAssemblyModules();

builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseSession();

app.UseCookiePolicy();
app.UseAuthentication();
app.UseAuthorization();

app.MapRazorPages();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Login}/{id?}");

app.Run();

268357-image.png

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,156 questions
Active Directory Federation Services
Active Directory Federation Services
An Active Directory technology that provides single-sign-on functionality by securely sharing digital identity and entitlement rights across security and enterprise boundaries.
1,189 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,366 Reputation points
    2022-12-19T18:21:06.09+00:00

    your configuration is probably wrong. most likely the client & sever scopes don't match.

    0 comments No comments