public async Task StoreAsync(Model.ApiScope model)
        {
            var entity = model.ToEntity();

            try
            {
                await StorageContext
                .SaveBlobWithHashedKeyAsync(entity.Name, JsonConvert.SerializeObject(entity), StorageContext.ApiScopeBlobContainer)
                .ConfigureAwait(false);

                var entities = await GetAllApiScopeEntitiesAsync().ConfigureAwait(false);

                entities = entities.Where(e => entity.Name != e.Name).Concat(new Entities.ApiScope[] { entity });
                await UpdateApiScopeCacheFileAsync(entities).ConfigureAwait(false);
            }
            catch (AggregateException agg)
            {
                ExceptionHelper.LogStorageExceptions(agg, (tblEx) =>
                {
                    _logger.LogWarning("exception updating {apiName} identity resource in table storage: {error}", model.Name, tblEx.Message);
                }, (blobEx) =>
                {
                    _logger.LogWarning("exception updating {apiName} identity resource in blob storage: {error}", model.Name, blobEx.Message);
                });
                throw;
            }
        }
Пример #2
0
        public async Task <bool> AddApiScope(IdentityServer4.Models.ApiScope scope)
        {
            bool Result = false;
            await Context.ApiScopes.AddAsync(scope.ToEntity());

            Result = await Context.SaveChangesAsync() > 0;

            return(Result);
        }
Пример #3
0
        public async Task <ActionResult> RegisterScope(ScopeViewModel scopeViewModel)
        {
            ActionResult Result = Ok();

            IdentityServer4.Models.ApiScope Scope = new IdentityServer4.Models.ApiScope
            {
                Name        = scopeViewModel.Name,
                DisplayName = scopeViewModel.DisplayName
            };
            bool IsSuccess = await Repository.AddApiScope(Scope);

            if (!IsSuccess)
            {
                Result = Problem("Error to add scope", null, 500, "", null);
            }
            return(Result);
        }
 /// <summary>
 /// Maps a model to an entity.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns></returns>
 public static Entities.ApiScope ToEntity(this Models.ApiScope model)
 {
     return(model == null ? null : Mapper.Map <Entities.ApiScope>(model));
 }