your configuration is probably wrong. most likely the client & sever scopes don't match.
Not able to read the claims in Asp.net 6 web app after connecting to ADFS
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();