Skip to content

Commit

Permalink
Changed the ApiKeyMiddleware to accept an array of apiKeys instead of…
Browse files Browse the repository at this point in the history
… a string
  • Loading branch information
Gaardsholt committed Jul 10, 2020
1 parent 4d9ad33 commit 88fd735
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ApiKeyAuthMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ApiKeyAuthOptions : AuthenticationSchemeOptions
/// Your super secret value that should be in "KeyName"
/// If you need to specify multiple keys then do it as comma seperated.
/// </summary>
public string ApiKeys { get; set; }
public string[] ApiKeys { get; set; }
}

internal class ApiKeyAuthHandler : AuthenticationHandler<ApiKeyAuthOptions>
Expand All @@ -54,7 +54,7 @@ protected override Task<AuthenticateResult> HandleAuthenticateAsync()
var identity = new ClaimsIdentity(Options.KeyName);
var ticket = new AuthenticationTicket(new ClaimsPrincipal(identity), null, Options.KeyName);

if (string.IsNullOrWhiteSpace(Options.ApiKeys))
if (Options.ApiKeys.Length == 0)
return Task.FromResult(AuthenticateResult.Success(ticket));


Expand All @@ -67,7 +67,7 @@ protected override Task<AuthenticateResult> HandleAuthenticateAsync()



if (Options.ApiKeys.Split(',').Contains(key))
if (Options.ApiKeys.Contains(key))
return Task.FromResult(AuthenticateResult.Success(ticket));


Expand Down
2 changes: 1 addition & 1 deletion Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton(new Settings());
services.AddApiKeyAuthentication(a =>
{
a.ApiKeys = Settings.API_KEYS;
a.KeyName = "ApiKey";
a.ApiKeys = Settings.API_KEYS.Split(',');
});


Expand Down

0 comments on commit 88fd735

Please sign in to comment.