Add project files
This commit is contained in:
parent
4dafed3553
commit
8cf01ead74
40 changed files with 3967 additions and 0 deletions
|
|
@ -0,0 +1,28 @@
|
|||
using AspNetCore.Authentication.ApiKey;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using StalwartSimpleLoginMiddleware.Contexts;
|
||||
using StalwartSimpleLoginMiddleware.Models;
|
||||
using StalwartSimpleLoginMiddleware.Utilities;
|
||||
|
||||
namespace StalwartSimpleLoginMiddleware.Repositories;
|
||||
|
||||
public class ApiKeyContextRepository(ApiKeyContext context) : IApiKeyRepository
|
||||
{
|
||||
public async Task<IApiKey?> GetApiKeyAsync(string key)
|
||||
{
|
||||
var dbKey = await context.ApiKeys.AsNoTracking()
|
||||
.FirstOrDefaultAsync(api => api.Key == key);
|
||||
if (dbKey == null) return null;
|
||||
|
||||
return ApiKeyHelper.CreateDbApiKey(dbKey);
|
||||
}
|
||||
|
||||
public async Task<KeyMetadata> GetMetadataAsync(string key)
|
||||
{
|
||||
var dbKey = await context.ApiKeys.AsNoTracking()
|
||||
.Include(api => api.Members)
|
||||
.FirstAsync(api => api.Key == key);
|
||||
|
||||
return ApiKeyHelper.CreateKeyMetadata(dbKey);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
using AspNetCore.Authentication.ApiKey;
|
||||
using StalwartSimpleLoginMiddleware.Models;
|
||||
|
||||
namespace StalwartSimpleLoginMiddleware.Repositories;
|
||||
|
||||
public interface IApiKeyRepository
|
||||
{
|
||||
Task<IApiKey?> GetApiKeyAsync(string key);
|
||||
Task<KeyMetadata> GetMetadataAsync(string key);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue