Open iKingNinja opened 2 months ago
The AuthenticationHandler<TOptions>
constructor doesn't initialize Options
because it doesn't have the scheme name yet. It's initialized after the authentication middleware calls InitializeAsync
.
If you need access to Options
while initializing your handler, we recommend overriding InitializeHandlerAsync
where Options
should be initialized. Does this address your issue?
Yes, this indeed solves the issue. It would be nice if this was mentioned in the docs. Thank you for the help.
@guardrex, we think we should update the docs to include this scenario - is there enough context on this issue for you to add a bit about InitializeHandlerAsync
?
Yes, but this isn't Blazor specific, so it would map to either @mjrousos (the listed author of the overview security article) and/or @Rick-Anderson, the listed MS author.
@iKingNinja could you write the simplest possible app to demonstrate this for https://github.com/dotnet/AspNetCore.Docs.Samples/issues/258 and then outline the context for https://github.com/dotnet/AspNetCore.Docs/issues/33405 ?
@Rick-Anderson Sorry I'm new to these things, do you want me to write a simple app that throws the exception and create a pull request to https://github.com/dotnet/AspNetCore.Docs.Samples/issues/258?
@iKingNinja
@Rick-Anderson Sorry I'm new to these things, do you want me to write a simple app that throws the exception and create a pull request to dotnet/AspNetCore.Docs.Samples#258?
To access the Options
while initializing your handler, override the InitializeHandlerAsync
where Options
should be initialized.
Is that the typical way to solve the problem? If so, write a sample that does that.
Is there an existing issue for this?
Describe the bug
I'm having the same problem reported in #17539. The
AddScheme<TOptions,THandler>(String, Action<TOptions>)
method is not setting the options' values.The handler throws a
NullReferenceException
exception with the following detailsThis is how i'm configuring the scheme:
I even tried another approach which follows:
However there's no change in the error.
Of course both the previous configuration code blocks are followed by
I'm sure
configuration["ApiKey"]
is not null as its logged value is correct.Expected Behavior
I expect the
AddScheme()
method to set options values.Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
8.0.400
Anything else?
No response