This commit is contained in:
Kukks 2020-03-23 21:18:02 +01:00
parent 56ba834ca2
commit 7899c2d5c5
2 changed files with 10 additions and 4 deletions

View File

@ -46,13 +46,13 @@ namespace BTCPayServer.Tests
Assert.Single(apiKeyData.Permissions);
//a client using Basic Auth has no business here
await AssertHttpError(401, async () => await clientBasic.GetCurrentAPIKeyInfo());
await AssertHttpError(404, async () => await clientBasic.GetCurrentAPIKeyInfo());
//revoke current api key
await client.RevokeCurrentAPIKeyInfo();
await AssertHttpError(401, async () => await client.GetCurrentAPIKeyInfo());
//a client using Basic Auth has no business here
await AssertHttpError(401, async () => await clientBasic.RevokeCurrentAPIKeyInfo());
await AssertHttpError(404, async () => await clientBasic.RevokeCurrentAPIKeyInfo());
}

View File

@ -27,7 +27,10 @@ namespace BTCPayServer.Controllers.RestApi
[HttpGet("~/api/v1/api-keys/current")]
public async Task<ActionResult<ApiKeyData>> GetKey()
{
ControllerContext.HttpContext.GetAPIKey(out var apiKey);
if (!ControllerContext.HttpContext.GetAPIKey(out var apiKey))
{
return NotFound();
}
var data = await _apiKeyRepository.GetKey(apiKey);
return Ok(FromModel(data));
}
@ -36,7 +39,10 @@ namespace BTCPayServer.Controllers.RestApi
[Authorize(Policy = Policies.Unrestricted, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
public async Task<ActionResult<ApiKeyData>> RevokeKey()
{
ControllerContext.HttpContext.GetAPIKey(out var apiKey);
if (!ControllerContext.HttpContext.GetAPIKey(out var apiKey))
{
return NotFound();
}
await _apiKeyRepository.Remove(apiKey, _userManager.GetUserId(User));
return Ok();
}