Have used Microsoft.AspNetCore.Authentication.WsFedaration in ASP.NET core signon page is coming however "User.Identity.IsAuthenticated" is always showing false even after signin with ADFS. Here are the steps:
- Created ASP.NET Core MVC webapplication.
- Configured WREALM in ADFS.
- referred Microsoft.AspNetCore.Authentication.WsFedaration library in the project
- Created Account Controller with login Logout, where Login action method would challenge for sign in
- return Challenge(
new AuthenticationProperties { RedirectUri = redirectUrl },
WsFederationDefaults.AuthenticationScheme);
- return Challenge(
- Startup code below
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = WsFederationDefaults.AuthenticationScheme;
})
.AddWsFederation(options =>
{
// this is where your AppID URI goesoptions.Wtrealm = "http://XYZ-DevLocal";
options.MetadataAddress = "https://signon.XYZ.net/federationmetadata/2007-06/federationmetadata.xml";
})
.AddCookie();services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}app.UseHttpsRedirection();
app.UseAuthentication();
app.UseStaticFiles();
app.UseCookiePolicy();app.UsePathBase("/OneEnrollment").UseMvc(routes =>
//app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
// template: "{controller=Account}/{action=Login}");
});
}