A api key can always revoke itself, add a route to delete any api key

This commit is contained in:
nicolas.dorier
2020-03-27 14:46:51 +09:00
parent 39a8c3fe47
commit 6d7b57ea3b
5 changed files with 69 additions and 43 deletions

View File

@@ -53,15 +53,18 @@ namespace BTCPayServer.Security.GreenField
}
}
public async Task Remove(string id, string getUserId)
public async Task<bool> Remove(string id, string getUserId)
{
using (var context = _applicationDbContextFactory.CreateContext())
{
var key = await EntityFrameworkQueryableExtensions.SingleOrDefaultAsync(context.ApiKeys,
data => data.Id == id && data.UserId == getUserId);
if (key == null)
return false;
context.ApiKeys.Remove(key);
await context.SaveChangesAsync();
}
return true;
}
public class APIKeyQuery