I've created my own authentication handler in ASP.NET Core MVC v2.0.
It is invoked OK, but the options object is empty when the HandleAuthenticateAsync method is invoked.
Startup config
authenticationBuilder.AddSingleSignOn("SingleSignOn", options =>
{
options.OpenGlobalDb = () => OpenGlobalConnection(configuration);
options.OpenTenantDb = orgId => OpenTenantDb(configuration, orgId);
options.AuthenticationScheme = "Cookies";
});
(I've had a breakpoint in the code and it's invoked)
The authentication handler
public class SingleSignOnAuthenticationHandler : AuthenticationHandler<SingleSignOnAuthenticationOptions>,
IAuthenticationRequestHandler
{
private IOptionsMonitor<SingleSignOnAuthenticationOptions> _options;
public SingleSignOnAuthenticationHandler(IOptionsMonitor<SingleSignOnAuthenticationOptions> options,
ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock)
{
_options = options;
}
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
{
// _options.CurrentValue.OpenGlobalDb is null here.
}
//[.. all other methods ..]
}
Auth builder extensions
public static class AuthenticationBuilderExtensions
{
public static AuthenticationBuilder AddSingleSignOn(this AuthenticationBuilder builder, string authenticationScheme, Action<SingleSignOnAuthenticationOptions> configureOptions)
{
return builder.AddScheme<SingleSignOnAuthenticationOptions, SingleSignOnAuthenticationHandler>(authenticationScheme, "SingleSignOn authentication", configureOptions);
}
}
Do not save an own version of the options object in the constructor. Use the Options property in the HandleAuthenticateAsync method instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With