New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make auth infer opt in #2460
Merged
Merged
Make auth infer opt in #2460
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
test/Swashbuckle.AspNetCore.SwaggerGen.Test/Fixtures/FakeAuthenticationSchemeProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authentication; | ||
|
||
namespace Swashbuckle.AspNetCore.SwaggerGen.Test | ||
{ | ||
public class FakeAuthenticationSchemeProvider : IAuthenticationSchemeProvider | ||
{ | ||
private readonly IEnumerable<AuthenticationScheme> _authenticationSchemes; | ||
|
||
public FakeAuthenticationSchemeProvider(IEnumerable<AuthenticationScheme> authenticationSchemes) | ||
{ | ||
_authenticationSchemes = authenticationSchemes; | ||
} | ||
|
||
public void AddScheme(AuthenticationScheme scheme) | ||
=> throw new NotImplementedException(); | ||
public Task<IEnumerable<AuthenticationScheme>> GetAllSchemesAsync() | ||
=> Task.FromResult(_authenticationSchemes); | ||
|
||
public Task<AuthenticationScheme> GetDefaultAuthenticateSchemeAsync() | ||
=> Task.FromResult(_authenticationSchemes.First()); | ||
|
||
public Task<AuthenticationScheme> GetDefaultChallengeSchemeAsync() | ||
=> Task.FromResult(_authenticationSchemes.First()); | ||
|
||
public Task<AuthenticationScheme> GetDefaultForbidSchemeAsync() | ||
=> Task.FromResult(_authenticationSchemes.First()); | ||
|
||
public Task<AuthenticationScheme> GetDefaultSignInSchemeAsync() | ||
=> Task.FromResult(_authenticationSchemes.First()); | ||
|
||
public Task<AuthenticationScheme> GetDefaultSignOutSchemeAsync() | ||
=> Task.FromResult(_authenticationSchemes.First()); | ||
|
||
public Task<IEnumerable<AuthenticationScheme>> GetRequestHandlerSchemesAsync() | ||
=> throw new NotImplementedException(); | ||
|
||
public Task<AuthenticationScheme> GetSchemeAsync(string name) | ||
=> Task.FromResult(_authenticationSchemes.First()); | ||
|
||
public void RemoveScheme(string name) | ||
=> throw new NotImplementedException(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize that this commit removed the code that would've prevented the
Bearer
auth scheme from being generated if there was already one provided withoptions.SecuritySchemes
. Perhaps we should add that back here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combining the use of
options.SecuritySchemes
with the infer behaviour (either default or viaSecuritySchemesSelector
), with trumping rules etc, feels like a recipe for disaster. So, for this PR, I've simplified the approach so that you either set the security schemes explicitly (viaoptions.SecuritySchemes
) OR you "opt-in" to the infer behavior (viaInferSecuritySchemes()
). So, you can use one approach or the other not a combination of both.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And of course, in both cases schema filters may be applied for any final tweaks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fair! I think the schema filters ordering is the most important bit here.
Will this be shipped in a patch or minor release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will ship as a minor version release