How do I add SAML login option to my authentication?

  Kiến thức lập trình

In my .NET Core 2.1 Startup.cs class, I added code for the itfoxtec-identity-saml2 SAML 2.0 library.

I followed the examples in the ITFoxTec repository, and I thought I added all the code I needed in my Startup.cs class.

But when the app loads, I get this error:

InvalidOperationException: No sign-in authentication handler is registered for the scheme 'saml2'. The registered sign-in schemes are: Cookies. Did you forget to call AddAuthentication().AddCookies("saml2",...)?
ResearchApp.Controllers.AuthController.AssertionConsumerService() in AuthController.cs

So I tried to fix it, but I am not sure what to do.

In my Startup.cs class, I see that I have this code related to Authentication.

public static String AuthenticationScheme => CookieAuthenticationDefaults.AuthenticationScheme;

       public IServiceProvider ConfigureServices(IServiceCollection services)
       {
           services.AddOptions();

           services.AddAuthentication(AuthenticationScheme)
               .AddCookie(opts => {
                   opts.LoginPath = new PathString("/Account/Login");
                   opts.Cookie.SecurePolicy = NavConfig.RequireHttps ? CookieSecurePolicy.Always : CookieSecurePolicy.SameAsRequest;
                   opts.Cookie.HttpOnly = true;
                   opts.ExpireTimeSpan = TimeSpan.FromDays(7);
               });
               

Is there anything I need to add for SAML?

Thanks!

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT