mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 06:54:19 +01:00
Greenfield API: Create User
Slightly big PR because I started refactoring to reduce code duplication between the UI based business logic and the api one.
This commit is contained in:
@@ -29,6 +29,13 @@ namespace BTCPayServer.Security.APIKeys
|
||||
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context,
|
||||
PolicyRequirement requirement)
|
||||
{
|
||||
//if it is a create user request, and the auth is not specified, and there are no admins in the system: authorize
|
||||
if (context.User.Identity.AuthenticationType == null && requirement.Policy == Policies.CanCreateUser.Key &&
|
||||
!(await _userManager.GetUsersInRoleAsync(Roles.ServerAdmin)).Any())
|
||||
{
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
|
||||
if (context.User.Identity.AuthenticationType != APIKeyConstants.AuthenticationType)
|
||||
return;
|
||||
|
||||
@@ -67,6 +74,7 @@ namespace BTCPayServer.Security.APIKeys
|
||||
}
|
||||
|
||||
break;
|
||||
case Policies.CanCreateUser.Key:
|
||||
case Policies.CanModifyServerSettings.Key:
|
||||
if (!context.HasPermissions(Permissions.ServerManagement))
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user