-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
160 additions
and
113 deletions.
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
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
44 changes: 21 additions & 23 deletions
44
src/Ocelot/Configuration/Validator/FileAuthenticationOptionsValidator.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 |
---|---|---|
@@ -1,35 +1,33 @@ | ||
using FluentValidation; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.Extensions.Options; | ||
using Ocelot.Configuration.File; | ||
|
||
namespace Ocelot.Configuration.Validator | ||
namespace Ocelot.Configuration.Validator; | ||
|
||
public class FileAuthenticationOptionsValidator : AbstractValidator<FileAuthenticationOptions> | ||
{ | ||
public class FileAuthenticationOptionsValidator : AbstractValidator<FileAuthenticationOptions> | ||
{ | ||
private readonly IAuthenticationSchemeProvider _authenticationSchemeProvider; | ||
private readonly IAuthenticationSchemeProvider _authenticationSchemeProvider; | ||
|
||
public FileAuthenticationOptionsValidator(IAuthenticationSchemeProvider authenticationSchemeProvider) | ||
{ | ||
_authenticationSchemeProvider = authenticationSchemeProvider; | ||
public FileAuthenticationOptionsValidator(IAuthenticationSchemeProvider authenticationSchemeProvider) | ||
{ | ||
_authenticationSchemeProvider = authenticationSchemeProvider; | ||
|
||
RuleFor(authOptions => authOptions) | ||
.MustAsync(IsSupportedAuthenticationProviders) | ||
.WithMessage("AuthenticationOptions: {PropertyValue} is unsupported authentication provider"); | ||
} | ||
RuleFor(authOptions => authOptions) | ||
.MustAsync(IsSupportedAuthenticationProviders) | ||
.WithMessage("AuthenticationOptions: {PropertyValue} is unsupported authentication provider"); | ||
} | ||
|
||
private async Task<bool> IsSupportedAuthenticationProviders(FileAuthenticationOptions options, CancellationToken cancellationToken) | ||
private async Task<bool> IsSupportedAuthenticationProviders(FileAuthenticationOptions options, CancellationToken cancellationToken) | ||
{ | ||
if (string.IsNullOrEmpty(options.AuthenticationProviderKey) && options.AuthenticationProviderKeys.Length == 0) | ||
{ | ||
if (string.IsNullOrEmpty(options.AuthenticationProviderKey) && options.AuthenticationProviderKeys.Length == 0) | ||
{ | ||
return true; | ||
} | ||
|
||
var schemes = await _authenticationSchemeProvider.GetAllSchemesAsync(); | ||
var supportedSchemes = schemes.Select(scheme => scheme.Name); | ||
var primary = options.AuthenticationProviderKey; | ||
return !string.IsNullOrEmpty(primary) && supportedSchemes.Contains(primary) | ||
|| (string.IsNullOrEmpty(primary) && options.AuthenticationProviderKeys.All(supportedSchemes.Contains)); | ||
return true; | ||
} | ||
|
||
var schemes = await _authenticationSchemeProvider.GetAllSchemesAsync(); | ||
var supportedSchemes = schemes.Select(scheme => scheme.Name); | ||
var primary = options.AuthenticationProviderKey; | ||
return !string.IsNullOrEmpty(primary) && supportedSchemes.Contains(primary) | ||
|| (string.IsNullOrEmpty(primary) && options.AuthenticationProviderKeys.All(supportedSchemes.Contains)); | ||
} | ||
} |
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