Better error message if permission missing

This commit is contained in:
nicolas.dorier 2020-06-27 14:05:56 +09:00
parent 3288264ca0
commit 6208706d46
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE

View File

@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Mvc;
using BTCPayServer.Security.GreenField;
using NBitcoin.DataEncoders;
using NBitcoin;
using Org.BouncyCastle.Ocsp;
namespace BTCPayServer.Controllers.GreenField
{
@ -39,10 +40,15 @@ namespace BTCPayServer.Controllers.GreenField
[HttpPost("~/api/v1/api-keys")]
[Authorize(Policy = Policies.Unrestricted, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
public async Task<ActionResult<ApiKeyData>> CreateKey(CreateApiKeyRequest request)
public async Task<IActionResult> CreateKey(CreateApiKeyRequest request)
{
if (request is null)
return NotFound();
if (request.Permissions is null || request.Permissions.Length == 0)
{
ModelState.AddModelError(nameof(request.Permissions), "One or more permissions are required");
return this.CreateValidationError(ModelState);
}
var key = new APIKeyData()
{
Id = Encoders.Hex.EncodeData(RandomUtils.GetBytes(20)),