问题
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