public async Task <ActionResult> AddIdentityResourceClaim([FromBody] IdentityClaimDto claim) { if (claim.Type == string.Empty) { return(BadRequest()); } int newId = await this._configurationManagementService.AddIdentityResourceClaimAsync(claim); return(this.CreatedAtAction(nameof(this.ReturnIdentityResourceClaim), new { identityClaimName = claim.IdentityClaimName, id = newId, version = _apiVersion.ToString() }, claim)); }
public async Task <ActionResult> UpdateIdentityResourceClaim([FromBody] IdentityClaimDto claim) { var currentIdentityResource = await this._configurationManagementService.ReturnIdentityResourceClaimAsync(claim.IdentityClaimName, claim.Id); if (currentIdentityResource == null) { return(NotFound()); } await this._configurationManagementService.UpdateIdentityResourceClaimAsync(claim); return(NoContent()); }
public async Task <int> AddIdentityResourceClaimAsync(IdentityClaimDto claim) { IdentityServer4.EntityFramework.Entities.IdentityClaim newclaim = new IdentityServer4.EntityFramework.Entities.IdentityClaim(); var entityResult = await this._configContext.IdentityResources.FirstOrDefaultAsync(i => i.Name.ToLower() == claim.IdentityClaimName.ToLower()); newclaim.Type = claim.Type; newclaim.IdentityResourceId = entityResult.Id; var result = await this._configContext.AddAsync(newclaim); await this._configContext.SaveChangesAsync(); claim.IdentityClaimName = entityResult.Name; return(result.Entity.Id); }
public async Task UpdateIdentityResourceClaimAsync(IdentityClaimDto claim) { var entityResult = await this._configContext.IdentityResources.FirstOrDefaultAsync(i => i.Name.ToLower() == claim.IdentityClaimName.ToLower()); if (entityResult == null) { throw new Exception("Entity Not Found"); } var foundClaim = entityResult.UserClaims.FirstOrDefault(c => c.Id == claim.Id); if (foundClaim == null) { throw new Exception("Claim not found"); } foundClaim.Type = claim.Type; this._configContext.Update(foundClaim); await this._configContext.SaveChangesAsync(); }
public async Task RemoveClaimFromIdentityResourceAsync(IdentityClaimDto claim, bool saveChanges) { var entityResult = await this._configContext.IdentityResources.FirstOrDefaultAsync(i => i.Name.ToLower() == claim.IdentityClaimName.ToLower()); if (entityResult == null) { throw new Exception("Entity Not Found"); } var foundClaim = entityResult.UserClaims.FirstOrDefault(c => c.Id == claim.Id); if (foundClaim == null) { throw new Exception("Claim not found"); } this._configContext.Remove(foundClaim); if (saveChanges) { await this._configContext.SaveChangesAsync(); } }