Dynamically add a SAML2 authentication provider using Sustainsys.Saml2 in ASP.NET Core

故事扮演 提交于 2019-12-24 06:34:43

问题


I'm trying to dynamically add a SAML2 authentication scheme using IAuthenticationSchemeProvider in ASP.NET Core and the Sustainsys.Saml2 library:

schemeProvider.AddScheme(new AuthenticationScheme("myAuthScheme", "myAuthScheme", typeof(Saml2Handler)));

Along with the scheme, I need to configure the Saml2Options that go along with it. I'm attempting to do this using IOptionsMonitorCache<Saml2Options> like so:

samlOptionsCache.TryAdd("myAuthScheme", options);

When I then attempt to authenticate using this scheme, I get the following error:

NullReferenceException: Object reference not set to an instance of an object. Sustainsys.Saml2.WebSso.Saml2Urls..ctor(HttpRequestData request, IOptions options) Sustainsys.Saml2.WebSso.SignInCommand.Run(EntityId idpEntityId, string returnPath, HttpRequestData request, IOptions options, IDictionary relayData) Sustainsys.Saml2.AspNetCore2.Saml2Handler.ChallengeAsync(AuthenticationProperties properties)

So it looks like the properties are never being linked with the scheme.

I'm not sure that I'm going down the correct path with this. Is it possible to dynamically register a scheme in this way?


回答1:


It turns out it was the just the logger that wasn't instantiated, all the other options were fine. I solved this by adding...

options.SPOptions.Logger = new AspNetCoreLoggerAdapter(loggerFactory.CreateLogger<Saml2Handler>());

...when I set up the options.

loggerFactory refers to an injected instance of Microsoft.Extensions.Logging.ILoggerFactory.



来源:https://stackoverflow.com/questions/54831086/dynamically-add-a-saml2-authentication-provider-using-sustainsys-saml2-in-asp-ne

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!