Set roles when authenticating via greenfield

fixes #1855
This commit is contained in:
Kukks
2020-08-19 14:46:45 +02:00
parent 39beacf884
commit 1cb3e5f98c
6 changed files with 104 additions and 93 deletions

View File

@@ -16,13 +16,14 @@ namespace BTCPayServer.Security.GreenField
_applicationDbContextFactory = applicationDbContextFactory;
}
public async Task<APIKeyData> GetKey(string apiKey)
public async Task<APIKeyData> GetKey(string apiKey, bool includeUser = false)
{
using (var context = _applicationDbContextFactory.CreateContext())
await using var context = _applicationDbContextFactory.CreateContext();
if (includeUser)
{
return await EntityFrameworkQueryableExtensions.SingleOrDefaultAsync(context.ApiKeys,
data => data.Id == apiKey && data.Type != APIKeyType.Legacy);
return await context.ApiKeys.Include(data => data.User).SingleOrDefaultAsync(data => data.Id == apiKey && data.Type != APIKeyType.Legacy);
}
return await context.ApiKeys.SingleOrDefaultAsync(data => data.Id == apiKey && data.Type != APIKeyType.Legacy);
}
public async Task<List<APIKeyData>> GetKeys(APIKeyQuery query)