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

Developer technologies | ASP.NET | ASP.NET Core
Microsoft Security | Active Directory Federation Services
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 78,161 Reputation points Volunteer Moderator
    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.