Skip to content

Commit

Permalink
Upgraded to .NET 7 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgernand authored Nov 20, 2022
1 parent cd75f03 commit 414f5da
Show file tree
Hide file tree
Showing 52 changed files with 704 additions and 731 deletions.
14 changes: 7 additions & 7 deletions AspNetCore.Authentication.ApiKey.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Authentication.A
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SampleWebApi.Shared", "samples\SampleWebApi.Shared\SampleWebApi.Shared.shproj", "{E544FB20-29F3-41F5-A78E-6164F9C43B3C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApi_6_0", "samples\SampleWebApi_6_0\SampleWebApi_6_0.csproj", "{13031DBF-54EA-4A64-A03B-88B4CED1D5F5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApi", "samples\SampleWebApi\SampleWebApi.csproj", "{0B6FB864-E2AE-4086-8E51-53A6A079E9FD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -41,10 +41,10 @@ Global
{5A9AAE35-66E9-408E-B763-C71F0C0751B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A9AAE35-66E9-408E-B763-C71F0C0751B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A9AAE35-66E9-408E-B763-C71F0C0751B2}.Release|Any CPU.Build.0 = Release|Any CPU
{13031DBF-54EA-4A64-A03B-88B4CED1D5F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13031DBF-54EA-4A64-A03B-88B4CED1D5F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13031DBF-54EA-4A64-A03B-88B4CED1D5F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13031DBF-54EA-4A64-A03B-88B4CED1D5F5}.Release|Any CPU.Build.0 = Release|Any CPU
{0B6FB864-E2AE-4086-8E51-53A6A079E9FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B6FB864-E2AE-4086-8E51-53A6A079E9FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B6FB864-E2AE-4086-8E51-53A6A079E9FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B6FB864-E2AE-4086-8E51-53A6A079E9FD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -53,13 +53,13 @@ Global
{09D17A19-0406-487A-810A-24107AE767F8} = {BCEF726B-D658-40C2-9099-7001BA519E71}
{5A9AAE35-66E9-408E-B763-C71F0C0751B2} = {A15FB7AB-5B7A-4428-BEBA-32DEE3C88C39}
{E544FB20-29F3-41F5-A78E-6164F9C43B3C} = {3C777BBB-7464-43FB-A046-EA465791AB0C}
{13031DBF-54EA-4A64-A03B-88B4CED1D5F5} = {3C777BBB-7464-43FB-A046-EA465791AB0C}
{0B6FB864-E2AE-4086-8E51-53A6A079E9FD} = {3C777BBB-7464-43FB-A046-EA465791AB0C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {70815049-1680-480A-BF5A-00536D6C9C20}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
samples\SampleWebApi.Shared\SampleWebApi.Shared.projitems*{13031dbf-54ea-4a64-a03b-88b4ced1d5f5}*SharedItemsImports = 5
samples\SampleWebApi.Shared\SampleWebApi.Shared.projitems*{0b6fb864-e2ae-4086-8e51-53a6a079e9fd}*SharedItemsImports = 5
samples\SampleWebApi.Shared\SampleWebApi.Shared.projitems*{e544fb20-29f3-41f5-a78e-6164f9c43b3c}*SharedItemsImports = 13
EndGlobalSection
EndGlobal
5 changes: 2 additions & 3 deletions samples/SampleWebApi.Shared/Models/ApiKey.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using AspNetCore.Authentication.ApiKey;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Security.Claims;

namespace SampleWebApi.Models
{
class ApiKey : IApiKey
class ApiKey : MadEyeMatt.AspNetCore.Authentication.ApiKey.IApiKey
{
public ApiKey(string key, string owner, List<Claim> claims = null)
{
Expand Down
5 changes: 2 additions & 3 deletions samples/SampleWebApi.Shared/Repositories/IApiKeyRepository.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AspNetCore.Authentication.ApiKey;
using System.Threading.Tasks;
using System.Threading.Tasks;

namespace SampleWebApi.Repositories
{
Expand All @@ -8,6 +7,6 @@ namespace SampleWebApi.Repositories
/// </summary>
public interface IApiKeyRepository
{
Task<IApiKey> GetApiKeyAsync(string key);
Task<MadEyeMatt.AspNetCore.Authentication.ApiKey.IApiKey> GetApiKeyAsync(string key);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AspNetCore.Authentication.ApiKey;
using SampleWebApi.Models;
using SampleWebApi.Models;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -12,13 +11,13 @@ namespace SampleWebApi.Repositories
/// </summary>
public class InMemoryApiKeyRepository : IApiKeyRepository
{
private List<IApiKey> _cache = new List<IApiKey>
private List<MadEyeMatt.AspNetCore.Authentication.ApiKey.IApiKey> _cache = new List<MadEyeMatt.AspNetCore.Authentication.ApiKey.IApiKey>
{
new ApiKey("Key1", "Admin"),
new ApiKey("Key2", "User"),
};

public Task<IApiKey> GetApiKeyAsync(string key)
public Task<MadEyeMatt.AspNetCore.Authentication.ApiKey.IApiKey> GetApiKeyAsync(string key)
{
var apiKey = _cache.FirstOrDefault(k => k.Key.Equals(key, StringComparison.OrdinalIgnoreCase));
return Task.FromResult(apiKey);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using AspNetCore.Authentication.ApiKey;
using Microsoft.Extensions.Logging;
using SampleWebApi.Repositories;
using System.Threading.Tasks;

namespace SampleWebApi.Services
{
internal class ApiKeyAuthenticationService : IApiKeyAuthenticationService
internal class ApiKeyAuthenticationService : MadEyeMatt.AspNetCore.Authentication.ApiKey.IApiKeyAuthenticationService
{
private readonly ILogger<IApiKeyAuthenticationService> _logger;
private readonly ILogger<MadEyeMatt.AspNetCore.Authentication.ApiKey.IApiKeyAuthenticationService> _logger;
private readonly IApiKeyRepository _apiKeyRepository;

public ApiKeyAuthenticationService(ILogger<ApiKeyAuthenticationService> logger, IApiKeyRepository apiKeyRepository)
Expand All @@ -16,7 +15,7 @@ public ApiKeyAuthenticationService(ILogger<ApiKeyAuthenticationService> logger,
_apiKeyRepository = apiKeyRepository;
}

public async Task<IApiKey> AuthenticateAsync(string key)
public async Task<MadEyeMatt.AspNetCore.Authentication.ApiKey.IApiKey> AuthenticateAsync(string key)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using AspNetCore.Authentication.ApiKey;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using SampleWebApi.Repositories;
using System.Diagnostics;

namespace SampleWebApi.Services
{
internal class ApiKeyAuthenticationServiceFactory : IApiKeyAuthenticationServiceFactory
internal class ApiKeyAuthenticationServiceFactory : MadEyeMatt.AspNetCore.Authentication.ApiKey.IApiKeyAuthenticationServiceFactory
{
private readonly ILoggerFactory loggerFactory;
private readonly IApiKeyRepository apiKeyRepository;
Expand All @@ -17,7 +16,7 @@ public ApiKeyAuthenticationServiceFactory(ILoggerFactory loggerFactory, IApiKeyR
}

/// <inheritdoc />
public IApiKeyAuthenticationService CreateApiKeyAuthenticationService(string authenticationSchemaName)
public MadEyeMatt.AspNetCore.Authentication.ApiKey.IApiKeyAuthenticationService CreateApiKeyAuthenticationService(string authenticationSchemaName)
{
Debug.WriteLine(authenticationSchemaName);
return new ApiKeyAuthenticationService(loggerFactory.CreateLogger<ApiKeyAuthenticationService>(), this.apiKeyRepository);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Text;

namespace SampleWebApi_6_0.Controllers
namespace SampleWebApi.Controllers
{
using Microsoft.AspNetCore.Authorization;
using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

[Route("api/[controller]")]
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using AspNetCore.Authentication.ApiKey;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using SampleWebApi.Repositories;
using SampleWebApi.Services;
using ApiKeyExtensions = MadEyeMatt.AspNetCore.Authentication.ApiKey.ApiKeyExtensions;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -13,15 +13,7 @@
// Add the ApiKey scheme authentication here..
// It requires Realm to be set in the options if SuppressWWWAuthenticateHeader is not set.
// If an implementation of IApiKeyProvider interface is registered in the dependency register as well as OnValidateKey delegete on options.Events is also set then this delegate will be used instead of an implementation of IApiKeyProvider.
builder.Services.AddAuthentication(ApiKeyDefaults.AuthenticationScheme)

// The below AddApiKeyInHeaderOrQueryParams without type parameter will require OnValidateKey delegete on options.Events to be set unless an implementation of IApiKeyProvider interface is registered in the dependency register.
// Please note if OnValidateKey delegete on options.Events is also set then this delegate will be used instead of ApiKeyProvider.*
//.AddApiKeyInHeaderOrQueryParams(options =>

// The below AddApiKeyInHeaderOrQueryParams with type parameter will add the ApiKeyProvider to the dependency register.
// Please note if OnValidateKey delegete on options.Events is also set then this delegate will be used instead of ApiKeyProvider.
.AddApiKeyInHeaderOrQueryParams<ApiKeyAuthenticationService>(options =>
ApiKeyExtensions.AddApiKeyInHeaderOrQueryParams<ApiKeyAuthenticationService>(builder.Services.AddAuthentication(MadEyeMatt.AspNetCore.Authentication.ApiKey.ApiKeyDefaults.AuthenticationScheme), options =>
{
options.Realm = "Sample Web API";
options.KeyName = "X-API-KEY";
Expand All @@ -37,7 +29,7 @@

//// Optional events to override the ApiKey original logic with custom logic.
//// Only use this if you know what you are doing at your own risk. Any of the events can be assigned.
options.Events = new ApiKeyEvents
options.Events = new MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyEvents
{

//// A delegate assigned to this property will be invoked just before validating the api key.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>disable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/AspNetCore.Authentication.ApiKey/ApiKeyDefaults.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mihir Dilip. All rights reserved.
// Licensed under the MIT License. See LICENSE file in the project root for license information.

namespace AspNetCore.Authentication.ApiKey
namespace MadEyeMatt.AspNetCore.Authentication.ApiKey
{
/// <summary>
/// Default values used by api key authentication.
Expand Down
Loading

0 comments on commit 414f5da

Please sign in to comment.