-
Notifications
You must be signed in to change notification settings - Fork 67
IConfigureOptions isn't called for authentication (named) options #225
Comments
The 1.1 behaviour was for this to be called for all handlers. |
Yes, judging by commit 52ab5f1, it was introduced in 2.0.0-preview2. |
Yes Auth 2.0 uses named options, IConfigureOptions are equivalent to IConfigureNamed options with name = Options.DefaultName |
IPostConfigureOptions works because it supports names since its new in 2.0, we wanted to preserve existing behavior for existing users of IOptions/IConfigureOptions so we left those alone and added IConfigureNamedOptions. |
You need to switch to IConfigureNamedOptions to be able to target the correct authentication scheme in 2.0, this breaking change was intentional |
I added this to the known issues/breaking changes section at the bottom of the Auth 2.0 announcement: aspnet/Announcements#262 |
Alright. I think we're done here 👍 |
After a Twitter discussion with @mwadams, we discovered this weird thing...
The
OptionsFactory.Create
method seems to only call registeredIConfigureOptions<T>
whenname == Options.DefaultName
:Options/src/Microsoft.Extensions.Options/OptionsFactory.cs
Lines 28 to 47 in e71178f
This results in
IConfigureOptions<T>
not being called when options are requested from authentication handlers (or any other named options):https://github.com/aspnet/Security/blob/488eb44467eb677eab62bdc49aa6255cc1be3119/src/Microsoft.AspNetCore.Authentication/AuthenticationHandler.cs#L89
Why is this? Was this intended or a regression? It seems like a weird, artificial restriction to have. Not to mention the inconsistently configured named/default options you'd have around.
A workaround is to just use the exact same class, but implement
IPostConfigureOptions<T>
instead.// @HaoK (from commit 52ab5f1)
The text was updated successfully, but these errors were encountered: