public BinanceApiClient() { if (LoadApiKeys("binance.hash")) { this.Encryptor = new HMACSHA256(ApiSecret.ToByteArray()); } }
public async Task <bool> Handle(SetApiSecretCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return(false); } var resource = await _apiResourceRepository.FindByNameAsync(request.ApiResourceName); if (resource == null) { await _bus.RaiseEvent(new DomainNotification("key_not_found", $"{request.ApiResourceName} not found")); return(false); } var secret = new ApiSecret { ApiResource = resource, Description = request.Description, Type = request.Type, Expiration = request.Expiration, Value = request.GetHashValue() }; await _apiSecretRepository.AddAsync(secret); if (Commit()) { return(true); } return(false); }
public DsxApiClient() { if (LoadApiKeys("dsx.hash")) { this.Encryptor = new HMACSHA512(ApiSecret.ToByteArray()); } }
public override bool Equals(object o) { if (!(o is ApiAccess)) { return(false); } ApiAccess v = o as ApiAccess; if (!AccountName.Equals(v.AccountName)) { return(false); } if (!ApiKey.Equals(v.ApiKey)) { return(false); } if (!ApiSecret.Equals(v.ApiSecret)) { return(false); } if (!ProviderName.Equals(v.ProviderName)) { return(false); } return(true); }
public UploadService( GraphQLRequest graphQlRequest, GraphQLClient graphQlClient, ApiSecret apiSecret, IIdentityProviderService service, IMemoryCache cache, ILogger <UploadService> logger) { _map = new Dictionary <string, Guid> { { "SDS_P1", new Guid("777CECC4-C140-477D-BD94-5A0A611F47FC") }, { "SDS_P2", new Guid("FB43A587-8251-4EA1-97B2-6F2F702952A6") }, { "humidity", new Guid("795F28B0-77ED-4A57-AF57-32A2C47CDBA0") }, { "temperature", new Guid("6E78294C-0AB6-4E71-A790-EA099D0693A6") }, { "BMP_pressure", new Guid("516C6AB3-E615-462E-8718-63FD85220D6A") }, { "BMP_temperature", new Guid("8FA026A5-BA9F-476A-AB7F-27406C3CEA91") }, }; _graphQlClient = graphQlClient; _graphQlRequest = graphQlRequest; _graphQlRequest.Query = Query.CreateMeasureValueBunch; //@"mutation AddValue($measure: MeasureValueInput!) { createMeasureValue(measureValueType: $measure){id}}"; //_graphQlRequest.OperationName = "AddValue"; _service = service; _apiSecret = apiSecret; _cache = cache; _logger = logger; _exp = DateTime.MinValue; }
public async Task <int> DeleteApiSecretAsync(ApiSecret apiSecret) { using (var dbContext = ConnectionDatabase.Get(_configuration)) { return(await dbContext.ExecuteAsync("delete from ApiSecrets where Id = @Id;", new { apiSecret.Id })); } }
public async Task Handle(SaveApiSecretCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return; } var savedClient = await _apiResourceRepository.GetByName(request.ResourceName); if (savedClient == null) { await Bus.RaiseEvent(new DomainNotification("1", "Client not found")); return; } var secret = new ApiSecret { ApiResource = savedClient, Description = request.Description, Expiration = request.Expiration, Type = request.Type, Value = request.GetValue() }; _apiSecretRepository.Add(secret); if (Commit()) { await Bus.RaiseEvent(new ApiSecretSavedEvent(request.Id, request.ResourceName)); } }
public BittrexApi() { if (LoadApiKeys("bittrex.hash")) { this.Encryptor = new HMACSHA512(ApiSecret.ToByteArray()); } }
public async Task <int> AddApiSecretAsync(int apiResourceId, ApiSecret apiSecret) { apiSecret.ApiResource = await _dbContext.ApiResources.Where(x => x.Id == apiResourceId).SingleOrDefaultAsync(); await _dbContext.ApiSecrets.AddAsync(apiSecret); return(await AutoSaveChangesAsync()); }
public async Task <int> DeleteApiSecretAsync(ApiSecret apiSecret) { var apiSecretToDelete = await _dbContext.ApiSecrets.Where(x => x.Id == apiSecret.Id).SingleOrDefaultAsync(); _dbContext.ApiSecrets.Remove(apiSecretToDelete); return(await AutoSaveChangesAsync()); }
public override string ToString() { StringBuilder sb = new StringBuilder(); sb.AppendLine("AccountName=" + AccountName.ToString()); sb.AppendLine("ApiKey=" + ApiKey.ToString()); sb.AppendLine("ApiSecret=" + ApiSecret.ToString()); sb.AppendLine("ProviderName=" + ProviderName.ToString()); return(sb.ToString()); }
public HttpUploadService( HttpClient client, ILogger <HttpUploadService> logger, IIdentityProviderService identity, ApiSecret secret) { _client = client; _client.Timeout = TimeSpan.FromSeconds(5); _logger = logger; _identity = identity; _secret = secret; }
public override int GetHashCode() { unchecked { var hashCode = ApiKey != null?ApiKey.GetHashCode() : 0; hashCode = (hashCode * 397) ^ (ApiSecret != null ? ApiSecret.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Domain != null ? Domain.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ShopperId != null ? ShopperId.GetHashCode() : 0); return(hashCode); } }
public async Task <int> AddApiSecretAsync(int apiResourceId, ApiSecret apiSecret) { using (var dbContext = ConnectionDatabase.Get(_configuration)) { return(await dbContext.QueryFirstAsync <int>("insert into ApiSecrets values (@Expiration, @Description, @Value, @Type, @apiResourceId); select SCOPE_IDENTITY();", new { apiSecret.Expiration, apiSecret.Description, apiSecret.Value, apiSecret.Type, apiResourceId })); } }
public static SecretModel FromEntity(ApiSecret secret) { return(new SecretModel { Id = secret.Id, Description = secret.Description, Value = secret.Value, Expiration = secret.Expiration, Type = secret.Type, Created = secret.Created, ApiResourceId = secret.ApiResource.Id, ApiResourceName = secret.ApiResource.Name, }); }
public ApiSecretDto GetApiSecret(int?id) { ApiSecretDto apiSecretDto = new ApiSecretDto(); if (!id.HasValue && id.GetValueOrDefault() <= 0) { return(apiSecretDto); } ApiSecret apiSecret = this.Session.Get <ApiSecret>(id.Value); if (apiSecret == null) { return(apiSecretDto); } return(apiSecret.ToModel()); }
public async Task <JsonResult> Edit(ApiSecret request) { JsonResponse response = new JsonResponse(); var model = _context.ApiSecrets.FirstOrDefault(m => m.Id == request.Id); model.Description = request.Description; model.ApiResourceId = request.ApiResourceId; if (model.Value != request.Value) { model.Value = request.Value.Sha256(); } _context.Update(model); await _context.SaveChangesAsync(); response.status = 0; response.code = "200"; return(Json(response)); }
public async Task <JsonResult> Create(ApiSecret request) { JsonResponse response = new JsonResponse(); var model = (await _context.ApiSecrets.AddAsync(request)).Entity; await _context.SaveChangesAsync(); if (model != null) { response.status = 0; response.code = "200"; } else { response.status = -1; response.code = "500"; } return(Json(response)); }
public async Task <IActionResult> Create(ApiSecretInputViewModel vm) { if (vm == null) { return(BadRequest()); } if (ModelState.IsValid) { var apiResource = await _dbContext.ApiResources.FindAsync(vm.ApiResourceId); if (apiResource == null) { return(BadRequest()); } var apiSecret = new ApiSecret { ApiResource = apiResource, Description = vm.Description, Value = vm.Value.Sha256(), Expiration = vm.Expiration }; if (!string.IsNullOrEmpty(vm.Type)) { apiSecret.Type = vm.Type; } _dbContext.Set <ApiSecret>().Add(apiSecret); try { await _dbContext.SaveChangesAsync(); _logger.LogInformation($"API secret Id {apiSecret.Id} created by {User?.Identity?.Name}."); return(RedirectToAction("Edit", "ApiResources", new { id = vm.ApiResourceId })); } catch (DbException ex) { _logger.LogError(ex.GetBaseException()?.Message ?? ex.Message); throw; } } return(View(vm)); }
public IActionResult Secrets(SecretsModel model) { var api = _configurationDbContext.ApiResources .Include(x => x.Secrets) .FirstOrDefault(x => x.Id == model.ApiResourceId); var secret = new ApiSecret { Created = DateTime.UtcNow, }; model.HashSecret(); model.UpdateEntity(secret); api.Secrets.Add(secret); _configurationDbContext.SaveChanges(); return(RedirectToAction(nameof(Secrets), new { id = api.Id })); }
public void UpdateApiSecret(int id, ApiSecretDto apiSecretDto) { apiSecretDto.HashApiSharedSecret(); var transaction = this.Session.BeginTransaction(); try { ApiSecret apiSecret = this.Session.Get <ApiSecret>(id); apiSecret = apiSecretDto.ToEntity(apiSecret); this.Session.Update(apiSecret); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } }
public string AddApiSecret(ApiSecret model) { string result; try { using (/*var*/ _ctx /*= new ResourceConfigDbContext()*/) { _ctx.ApiSecrets.Add(model); _ctx.SaveChanges(); //int Id = result = model.Id.ToString(); } } catch (Exception ex) { result = ex.Message.ToString(); } return(result); }
public async Task <JsonResult> GetList(ApiSecret dto) { JsonResponse json = new JsonResponse(); var query = _context.ApiSecrets.AsQueryable(); if (!string.IsNullOrEmpty(dto.Description)) { query = query.Where(m => m.Description == dto.Description); } if (dto.ApiResourceId != 0) { query = query.Where(m => m.ApiResourceId == dto.ApiResourceId); } var list = await query.ToListAsync(); var total = list.Count(); var list_secret = new List <SysApiSecret>(); if (total > 0) { foreach (var item in list) { var apiResource = await _context.ApiResources.FirstOrDefaultAsync(m => m.Id == item.ApiResourceId); SysApiSecret m_secret = new SysApiSecret() { Id = item.Id, Description = item.Description, ApiResourceId = item.ApiResourceId, ApiResourceName = apiResource.Name, Created = item.Created, Value = item.Value }; list_secret.Add(m_secret); } } json.status = 0; json.total = total; json.data = list_secret; return(Json(json)); }
public HitBtcApiClient() : base("hitbtc.hash", typeof(HMACSHA256)) { if (IsSigned) { clientAuth.Authenticator = new RestSharp.Authenticators.HttpBasicAuthenticator(ApiKey.ToManagedString(), ApiSecret.ToManagedString()); wsTrading.Opened += (sender, e) => { Debug.Print("Trading socket connected."); var reqLogin = new HitBtc.WsRequestBase() { method = "login", id = "authenticate" }; var nn = nonce.ToString(); reqLogin.data.Add("algo", HitBtc.AuthAlgo.HS256.ToString()); reqLogin.data.Add("pKey", ApiKey.ToManagedString()); reqLogin.data.Add("nonce", nn); reqLogin.data.Add("signature", ByteArrayToHexString(SignString(nn))); wsTrading.Send(JsonConvert.SerializeObject(reqLogin)); }; wsTrading.Open(); } }
public static ApiSecretsDto ToModel(this ApiSecret resource) { return(resource == null ? null : Mapper.Map <ApiSecretsDto>(resource)); }
public static ApiSecretDto ToModel(this ApiSecret apiSecret) { return(Mapper.Map <ApiSecret, ApiSecretDto>(apiSecret)); }
public async Task OnPostAsync() { // Arrange const string secret1OriginalValue = "Original Value"; const string secret1EditedValue = "Edited Value"; const string newSecretValue = "New Value"; var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync)}"; var options = new DbContextOptionsBuilder <OidcDbContext>() .UseInMemoryDatabase(databaseName) .Options; SecretsModel secrets; IActionResult post; var secret1 = new ApiSecret { Id = Random.Next(), Value = secret1OriginalValue }; var secret2 = new ApiSecret { Id = Random.Next() }; var apiResource = new ApiResource { Id = Random.Next(), Secrets = new List <ApiSecret> { secret1, secret2 } }; using (var context = new OidcDbContext(options)) { context.Add(apiResource); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new OidcDbContext(options)) { secrets = new SecretsModel(context) { ApiResource = new ApiResource { Id = apiResource.Id, Secrets = new List <ApiSecret> { new ApiSecret { Id = secret1.Id, Value = secret1EditedValue }, new ApiSecret { Value = newSecretValue } } } }; post = await secrets.OnPostAsync().ConfigureAwait(false); } // Assert using (var context = new OidcDbContext(options)) { apiResource = await context.ApiResources .Include(x => x.Secrets) .SingleOrDefaultAsync(x => x.Id.Equals(apiResource.Id)) .ConfigureAwait(false); secret1 = apiResource.Secrets.SingleOrDefault(x => x.Id.Equals(secret1.Id)); secret2 = apiResource.Secrets.SingleOrDefault(x => x.Id.Equals(secret2.Id)); var newSecret = apiResource.Secrets.SingleOrDefault(x => x.Value.Equals(newSecretValue)); Assert.NotNull(secret1); Assert.Equal(secret1EditedValue, secret1.Value); Assert.Null(secret2); Assert.NotNull(newSecret); } var result = Assert.IsType <RedirectToPageResult>(post); Assert.Equal("../Details/Secrets", result.PageName); Assert.Collection(result.RouteValues, routeValue => { var(key, value) = routeValue; Assert.Equal(nameof(ApiResource.Id), key); Assert.Equal(secrets.ApiResource.Id, value); }); }
private static void GenerateSecret(ApiSecret secret) { secret.Value = Guid.NewGuid().ToString(); }
public FiskalyClient(ApiKey apiKey, ApiSecret apiSecret) { ApiKey = apiKey; ApiSecret = apiSecret; Client = new Client(); }
internal static Dto.AuthorizationTokenRequest CreateAuthorizationToken(ApiKey apiKey, ApiSecret apiSecret) { return(new Dto.AuthorizationTokenRequest { ApiKey = apiKey.Value, ApiSecret = apiSecret.Value }); }