示例#1
0
        public async Task <ActionResult> AddApiResourceClaim([FromBody] ApiClaimDto claim)
        {
            if (claim.Type == string.Empty)
            {
                return(BadRequest());
            }

            int newId = await this._configurationManagementService.AddApiResourceClaimAsync(claim);

            return(this.CreatedAtAction(nameof(this.ReturnApiResourceClaim), new { ApiClaimName = claim.ApiClaimName, id = newId, version = _apiVersion.ToString() }, claim));
        }
示例#2
0
        public async Task <ActionResult> UpdateApiResourceClaim([FromBody] ApiClaimDto claim)
        {
            var currentIdentityResource = await this._configurationManagementService.ReturnApiResourceClaimAsync(claim.ApiClaimName, claim.Id);

            if (currentIdentityResource == null)
            {
                return(NotFound());
            }

            await this._configurationManagementService.UpdateApiResourceClaimAsync(claim);

            return(NoContent());
        }
示例#3
0
        public async Task <int> AddApiResourceClaimAsync(ApiClaimDto claim)
        {
            IdentityServer4.EntityFramework.Entities.ApiResourceClaim newclaim = new IdentityServer4.EntityFramework.Entities.ApiResourceClaim();
            var entityResult = await this._configContext.ApiResources.FirstOrDefaultAsync(i => i.Name.ToLower() == claim.ApiClaimName.ToLower());

            newclaim.Type          = claim.Type;
            newclaim.ApiResourceId = entityResult.Id;
            var result = await this._configContext.AddAsync(newclaim);

            await this._configContext.SaveChangesAsync();

            claim.ApiClaimName = entityResult.Name;
            return(result.Entity.Id);
        }
示例#4
0
        public async Task UpdateApiResourceClaimAsync(ApiClaimDto claim)
        {
            var entityResult = await this._configContext.ApiResources.FirstOrDefaultAsync(i => i.Name.ToLower() == claim.ApiClaimName.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();
        }
示例#5
0
        public async Task RemoveClaimFromApiResourceAsync(ApiClaimDto claim, bool saveChanges)
        {
            var entityResult = await this._configContext.ApiResources.FirstOrDefaultAsync(i => i.Name.ToLower() == claim.ApiClaimName.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();
            }
        }