// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var testSecret = new ApiSecrets { SecretId = Guid.Empty.ToString(), Key = Configuration["TestBinanceSecret:ExchangeKey"], Secret = Configuration["TestBinanceSecret:ExchangeSecret"], SubaccountName = Configuration["TestBinanceSecret:ExchangeAccount"] }; var redisConnectionString = Configuration["RedisConnections:DevConnectionString"]; services.AddSingleton(testSecret); services.AddControllers(); services.AddSwaggerGen(); services.AddTransient <IBotProcessManager, BotProcessManager>(); services.AddTransient <IExchangeFactory, ExchangeFactory>(); services.AddTransient <IBotProcessorFactory, BotProcessorFactory>(); services.AddTransient <IBotProcessor, CoreNumberProcessor>(); services.AddTransient <IExchange, BinanceService>(); services.AddTransient <IInstanceConfigurationService, InstanceConfigurationService>(); services.AddSingleton <ITradingViewAlertService, TradingViewAlertService>(); services.AddSingleton <IBotInstanceDataRepository, MemoryBotInstanceDataRepository>(); services.AddSingleton <ISecretDataRepository, MemorySecretDataRepository>(); services.AddTransient <IRedisClientsManager>(c => new RedisManagerPool(redisConnectionString)); services.Get }
public static Secret MapSecret(this ApiSecrets apiSecrets) { return(new Secret(value: apiSecrets.Value, description: apiSecrets.Description, expiration: apiSecrets.Expiration) { Type = apiSecrets.Type }); }
public IdentityServer4.Models.ApiResource ToModel() { return(new IdentityServer4.Models.ApiResource { ApiSecrets = ApiSecrets.Select(c => new IdentityServer4.Models.Secret { Type = c.Type, Description = c.Description, Expiration = c.Expiration, Value = StringExtensions.ToSha256(c.Value) }).ToList(), Description = Description, DisplayName = DisplayName, Enabled = Enabled, Name = Name, Properties = Properties, Scopes = Scopes.Select(s => new IdentityServer4.Models.Scope { Description = s.Description, DisplayName = s.DisplayName, Emphasize = s.Emphasize, Name = s.Name, Required = s.Required, ShowInDiscoveryDocument = s.ShowInDiscoveryDocument, UserClaims = s.UserClaims }).ToList(), UserClaims = UserClaims, }); }
internal GamesResource() : base( Application.Scopes.GamesApi.Name, Application.Scopes.GamesApi.DisplayName, IdentityResources.Roles.UserClaims.Union(IdentityResources.Permissions.UserClaims)) { ApiSecrets.Add(new Secret("secret".Sha256())); }
internal CashierWebAggregatorResource() : base( Application.Scopes.CashierWebAggregator.Name, Application.Scopes.CashierWebAggregator.DisplayName, IdentityResources.Roles.UserClaims.Union(IdentityResources.Permissions.UserClaims)) { ApiSecrets.Add(new Secret("secret".Sha256())); }
public MemorySecretDataRepository(ApiSecrets testSecret) { if (testSecret != null) { Data.Add(testSecret.SecretId, testSecret); } }
public string CreateSecret(string key, string secret, string subaccount = null) { var secretObject = new ApiSecrets { SecretId = Guid.NewGuid().ToString(), Key = key, Secret = secret, SubaccountName = subaccount }; _secretRepository.Save(secretObject); return(secretObject.SecretId); }
/// <summary> /// Converts this class to IdentityServer4.Models.ApiResource /// </summary> /// <returns></returns> public IdentityServer4.Models.ApiResource ToApiResource() { var apiResource = this.CopyPublicPropertiesToNew <IdentityServer4.Models.ApiResource>(); //hidden properties need to be copied explicitly as dto utils will not matche them on type! if (UserClaims != null) { apiResource.UserClaims = UserClaims; } apiResource.ApiSecrets = ApiSecrets.Select(cs => new Secret(cs.Value.Sha256(), cs.Description, cs.Expiration)).ToList(); apiResource.Scopes = Scopes.Select(s => s.ToScope()).ToList(); return(apiResource); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ApiResourceId,Description,Expiration,Type,Value")] ApiSecrets apiSecrets, string OldHash, string confirmPassword) { if (id != apiSecrets.Id) { return(NotFound()); } if (ModelState.IsValid) { if (confirmPassword != apiSecrets.Value) { ViewBag.error = "secret values do not match"; return(View()); } if (string.IsNullOrEmpty(apiSecrets.Value)) { apiSecrets.Value = OldHash; } else { apiSecrets.Value = apiSecrets.Value.ToSha256(); } try { _context.Update(apiSecrets); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApiSecretsExists(apiSecrets.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(apiSecrets)); }
public override bool Equals(object obj) { var other = obj as ApiResourceModel; if (other == null) { return(false); } var result = UserClaims.SafeListEquals(other.UserClaims) && ApiSecrets.SafeListEquals(other.ApiSecrets) && Scopes.SafeListEquals(other.Scopes) && Description.SafeEquals(other.Description) && DisplayName.SafeEquals(other.DisplayName) && Enabled.SafeEquals(other.Enabled) && Name.SafeEquals(other.Name) && Description.SafeEquals(other.Description); return(result); }
private async Task CleanupApiResourceAsync(ApiResource entity, CancellationToken cancellationToken = default(CancellationToken)) { //Remove old identity claims var apiResourceClaims = await ApiClaims.Where(x => x.ApiResource.Id == entity.Id).ToListAsync(); ApiClaims.RemoveRange(apiResourceClaims); //Remove old proprs var apiProps = await ApiProperties.Where(x => x.ApiResource.Id == entity.Id).ToListAsync(); ApiProperties.RemoveRange(apiProps); //Remove old scopes var apiScopes = await ApiScopes.Where(x => x.ApiResource.Id == entity.Id).ToListAsync(); ApiScopes.RemoveRange(apiScopes); //Remove old secrets var apiSecrets = await ApiSecrets.Where(x => x.ApiResource.Id == entity.Id).ToListAsync(); ApiSecrets.RemoveRange(apiSecrets); }
public async Task <IActionResult> Create([Bind("Id,ApiResourceId,Description,Expiration,Type,Value")] ApiSecrets apiSecrets, string confirmPassword) { if (string.IsNullOrEmpty(apiSecrets.Value)) { ViewBag.error = "Please enter a Value for: 'Api Secret'"; return(View()); } if (confirmPassword != apiSecrets.Value) { ViewBag.error = "Secret fields do not match"; return(View()); } apiSecrets.Value = apiSecrets.Value.ToSha256(); if (ModelState.IsValid) { _context.Add(apiSecrets); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(apiSecrets)); }