public async Task <IActionResult> GetResourcePermissions(string id, CancellationToken cancellationToken) { var umaResource = await _umaResourceRepository.FindByIdentifier(id, cancellationToken); if (umaResource == null) { return(this.BuildError(HttpStatusCode.NotFound, UMAErrorCodes.NOT_FOUND)); } return(new OkObjectResult(ResourcesAPIController.Serialize(umaResource.Permissions))); }
public async Task <IActionResult> Get(string id, CancellationToken cancellationToken) { if (!await IsPATAuthorized(cancellationToken)) { return(new UnauthorizedResult()); } var result = await _umaResourceRepository.FindByIdentifier(id, cancellationToken); if (result == null) { return(this.BuildError(HttpStatusCode.NotFound, UMAErrorCodes.NOT_FOUND)); } return(new OkObjectResult(Serialize(result))); }
public Task <IActionResult> Confirm(string id, CancellationToken cancellationToken) { return(CallOperationWithAuthenticatedUser(async(sub, payload) => { var pendingRequest = await _umaPendingRequestRepository.FindByTicketIdentifierAndOwner(id, sub, cancellationToken); if (pendingRequest == null) { return this.BuildError(HttpStatusCode.Unauthorized, UMAErrorCodes.REQUEST_DENIED); } if (pendingRequest.Status != UMAPendingRequestStatus.TOBECONFIRMED) { return this.BuildError(HttpStatusCode.BadRequest, ErrorCodes.INVALID_REQUEST, UMAErrorMessages.REQUEST_CANNOT_BE_CONFIRMED); } var resource = await _umaResourceRepository.FindByIdentifier(pendingRequest.Resource.Id, cancellationToken); foreach (var claimTokenFormat in _claimTokenFormats) { resource.Permissions.Add(new UMAResourcePermission(Guid.NewGuid().ToString(), DateTime.UtcNow) { Claims = new List <UMAResourcePermissionClaim> { new UMAResourcePermissionClaim { Name = claimTokenFormat.GetSubjectName(), Value = pendingRequest.Requester } }, Scopes = pendingRequest.Scopes.ToList() }); } pendingRequest.Confirm(); await _umaPendingRequestRepository.Update(pendingRequest, cancellationToken); await _umaResourceRepository.Update(resource, cancellationToken); await _umaPendingRequestRepository.SaveChanges(cancellationToken); await _umaResourceRepository.SaveChanges(cancellationToken); return new NoContentResult(); })); }