Aspnetcore: IAuthenticationSchemeProvider needs a TryAddScheme()

Created on 9 Oct 2017  路  11Comments  路  Source: dotnet/aspnetcore

Looking at this example/test to dynamically add authentication schemes at runtime:

https://github.com/aspnet/Security/blob/0959c941b40086b131b1e01d304fc23bb887fdc8/test/Microsoft.AspNetCore.Authentication.Test/DynamicSchemeTests.cs#L137-L143

If the endpoint is invoked twice, it will result in an InvalidOperationException:
https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNetCore.Authentication.Core/AuthenticationSchemeProvider.cs#L121

Instead perhaps this method should be bool TryAddScheme(AuthenticationScheme scheme) so users don't have to wrap it in a try-catch.

Also it appears that the underlying _map should be a ConcurrentDictionary?

Done area-security enhancement

All 11 comments

While we're looking at this API why is AddScheme and RemoveScheme synchronous but GetSchemeAsync asynchronous?

This is a good suggestion but the best way to fix it would be a breaking change, so we will consider this in the 3.0 milestone. For now we recommend using a workaround, such as trying to catch the exception.

Closing because it seems that implementors of the current interface could add their own interface with this new method, down-cast, and call it where needed.

We have default interface members so we believe this is non-breaking now.

Issues with dim still, moving to preview 8

Glad to see this happening :)

Contingency plan if we can't get DIM working (having some issues) is to punt to 3.1.

We're going to punt on DIM changes due to the limitations (VB support, crossgen issues). Let's move TryAddScheme out to 3.1.

crossgen dim works now in master, still doesn't work in release/3.1, so the fix looks good for 5.0 at least

Was this page helpful?
0 / 5 - 0 ratings