Ejemplo n.º 1
0
        public virtual async Task <int> UpdateApiResourceAsync(ApiResource apiResource)
        {
            //Remove old relations
            await RemoveApiResourceClaimsAsync(apiResource);

            //Update with new data
            DbContext.ApiResources.Update(apiResource);

            return(await AutoSaveChangesAsync());
        }
 public ApiSecret ToEntity(IdentityServer4.EntityFramework.Entities.ApiResource savedApi)
 {
     return(new ApiSecret
     {
         ApiResourceId = savedApi.Id,
         Description = Description,
         Expiration = Expiration,
         Type = Type,
         Value = GetValue()
     });
 }
Ejemplo n.º 3
0
        public async Task <bool> CanInsertApiResourceAsync(ApiResource apiResource)
        {
            if (apiResource.Id == 0)
            {
                var existsWithSameName = await _dbContext.ApiResources.Where(x => x.Name == apiResource.Name).SingleOrDefaultAsync();

                return(existsWithSameName == null);
            }
            else
            {
                var existsWithSameName = await _dbContext.ApiResources.Where(x => x.Name == apiResource.Name && x.Id != apiResource.Id).SingleOrDefaultAsync();

                return(existsWithSameName == null);
            }
        }
Ejemplo n.º 4
0
 public ApiScope ToEntity(IdentityServer4.EntityFramework.Entities.ApiResource savedApi)
 {
     return(new ApiScope()
     {
         ApiResourceId = savedApi.Id,
         Description = Description,
         Required = Required,
         DisplayName = DisplayName,
         Emphasize = Emphasize,
         Name = Name,
         ShowInDiscoveryDocument = ShowInDiscoveryDocument,
         UserClaims = UserClaims.Select(s => new ApiScopeClaim()
         {
             Type = s
         }).ToList(),
     });
 }
        /// <summary>
        /// This method creates an API Resource for the BurstChat Signal server with all the neccessary configuration.
        /// </summary>
        /// <param name="context">The configuration database context</param>
        /// <param name="configuration">The application settings configuration</param>
        public static void AddDevelopmentSignalResource(ConfigurationDbContext?context, IdentitySecretsOptions identitySecretsOptions)
        {
            if (context == null)
            {
                return;
            }

            var creationDate = DateTime.Now;
            var signalName   = "burstchat.signal";
            var signalSecret = identitySecretsOptions
                               .ApiSecrets[signalName];

            var signalResource = new ApiResource
            {
                Created     = creationDate,
                Name        = signalName,
                Description = "The BurstChat Signal Server",
                Enabled     = true
            };

            signalResource
            .Secrets = new List <ApiResourceSecret>
            {
                new()
                {
                    Value   = signalSecret.Sha256(),
                    Created = creationDate,
                }
            };

            signalResource
            .Scopes = new List <ApiResourceScope>
            {
                new()
                {
                    Scope = signalName,
                }
            };

            context
            .ApiResources
            .Add(signalResource);
        }
Ejemplo n.º 6
0
        public async Task <int> AddApiResourceAsync(ApiResource apiResource)
        {
            _dbContext.ApiResources.Add(apiResource);

            return(await AutoSaveChangesAsync());
        }
 private void LoadLookups(ApiResource apiResource)
 {
     HashTypes = EnumExtensions.ToSelectList <HashType>();
     Types     = PredefinedData.GetSecretTypes().Select(x => new SelectListItem(x, x));
     Secrets   = apiResource.Secrets.Select(ApiResourceMappers.ToModel).ToList();
 }