Closed Poltergeisen closed 5 years ago
We don't use the IOptions framework.
Oh sorry -- your initial comment about the wrong repo confused me and I thought this was being asked in the IS repo. Ignore my comment above :)
We don't do anything special. So this should work.
Do you think that it isn't working because this library is using an AuthenticationBuilder instead of IServiceCollection?
I set this up successfully with swashbuckle so it seems that the pattern should work, but they are using IServiceCollection.
We are using the standard pattern for authentication handlers.
I think I mistakenly thought that the options could be configured similar to services. If you know of a way for me to still use IConfigureOptions interface when configuring identity server I would love to hear it.
Otherwise if you think that isn't possible I think you can close this ticket. It doesn't seem to be an issue in this library, rather it seems that it is an issue in my own implementation or lack of understanding of the .net core options pattern.
@Poltergeisen Try implementing IConfigureNamedOptions instead - you will need to implement another Configure method that takes a name.
Now pass a name into AddAuthentication in your startup. Typically you would use IdentityServerAuthenticationDefaults.AuthenticationScheme (“Bearer”)
You can still add your class to dependency injection as IConfigureOptions
I was doing a similar thing to you, except I was already day passing the name in, and my IConfigureOptions.Configure method wasn’t being called until I implemented IConfigureNamedOptions instead. Good luck!
@snappyfoo Can you post a code example? I cannot get this to work either.
UPDATE No example needed, I got it. The class has to implement both interfaces
I accidentally created this issue in the wrong repo: https://github.com/IdentityServer/IdentityServer4/issues/3081
Issue
Create a class that implements
IConfigureOptions<IdentityServerAuthenticationOptions>
Add to dependency injection:
services.AddSingleton<IConfigureOptions<IdentityServerAuthenticationOptions>, ConfigureIdentityServerAuthenticationOptions>();
The Configure method is never called when using
services.AddAuthentication().AddIdentityServerAuthentication()
I needed to access my configuration variables from a settings class. I'd like to keep the configuration settings separate from the startup class.
I'll include an example below
This is the IOptions pattern that Microsoft is pushing with .net core I think.
Example (pseudo code):
Settings.cs
Then if that all worked correctly I'd make a configuration class for Identity server that implements IConfigureOptions that could automatically configure what I want: