28 lines
No EOL
911 B
C#
28 lines
No EOL
911 B
C#
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);
|
|
}
|
|
} |