public QrCodeController(QrCodeRenderOptions renderOptions, IQrCodeRenderer renderer, ApiKeyProvider apiKeyProvider, IImageService imageService, IConfiguration config) { this.renderOptions = renderOptions; this.renderer = renderer; this.apiKeyProvider = apiKeyProvider; this.imageService = imageService; this.config = config; }
public void GetsApiKeyFromRequest(string url, string key) { var apiKeyProvider = new ApiKeyProvider(); var request = new HttpRequestMessage(HttpMethod.Get, url); var apikey = apiKeyProvider.GetApiFromRequestAsync(request).Result; Assert.That(apikey, Is.EqualTo(key)); }
public ApiKeyAuthenticationHandler( ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock, IOptionsMonitor<ApiKeyAuthenticationOptions> options, IApiKeyService apiKeyService, ApiKeyProvider apiKeyProvider) : base(options, logger, encoder, clock) { this.apiKeyService = apiKeyService; this.apiKeyProvider = apiKeyProvider; }
static void Main(string[] args) { Task.Run(async() => { var apiKey = "<YOUR-API-KEY>"; var imoNumber = 1234567; var provider = new ApiKeyProvider { ApiKey = apiKey }; using (var apiClient = await MACS3.Connected.SDK.ConditionCheck.API2.CreateClientAsync(provider)) { try { var condition = new ConditionCheckParameter(); // Specify settings for the call condition.Settings = new ConditionCheckSettingsParameter { }; // Specify which check to carry out condition.WhatToCheck = new ConditionCheckWhatToCalculateParameter() { FlyingMixStowageCheck = true }; // Add one container to the condition condition.Containers = new List <ContainerParameter>() { new ContainerParameter() { Id = "1", ContainerId = "ABCD1234567", Position = "020086", // 020084 is lowest TypeIsoCode = "45G0" } }; // View the payload e.g. for Swagger/Postman var json = JsonConvert.SerializeObject(condition); var result = await apiClient.ConditionCheckAsync(imoNumber, "", condition); // Inspect result for further processing } catch (ApiException) { } } }).Wait(); }
public void ValidatesHash() { var config = new Dictionary <string, string> { ["Security:ApiKeyHashPhrase"] = "SecretSquirrel" }; var configuration = new ConfigurationBuilder().AddInMemoryCollection(config).Build(); var target = new ApiKeyProvider(configuration); var hash = target.GetBase64("steve"); Assert.True(target.CheckBase64("steve", hash)); }
public void GeneratesSensibleKey() { var config = new Dictionary <string, string> { ["Security:ApiKeyHashPhrase"] = "SecretSquirrel" }; var configuration = new ConfigurationBuilder().AddInMemoryCollection(config).Build(); var target = new ApiKeyProvider(configuration); var actual = target.GetBase64("steve"); Assert.NotNull(actual); Assert.NotEqual(0, actual.Length); }
public QrCodeService( IQrCodeDataService qrCodeDataService, IQrCodeRenderingService qrCodeRenderingService, IImageFileService imageFileService, ICreatedQrCodeRepository qrCodeRepository, ApiKeyProvider apiKeyProvider ) { this.qrCodeDataService = qrCodeDataService; this.qrCodeRenderingService = qrCodeRenderingService; this.imageFileService = imageFileService; this.qrCodeRepository = qrCodeRepository; this.apiKeyProvider = apiKeyProvider; }
protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (!request.Properties.Any()) { //properties is null under test need to add basic configuration request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); } var apikey = await ApiKeyProvider.GetApiFromRequestAsync(request); return(await base.SendAsync(request, cancellationToken).ContinueWith( response => LogResponse(apikey, response, request), cancellationToken)); }
static void Main(string[] args) { Task.Run(async() => { var apiKey = "<YOUR-API-KEY>"; var imoNumber = 1234567; var provider = new ApiKeyProvider { ApiKey = apiKey }; using (var apiClient = await MACS3.Connected.SDK.Lashing.API2.CreateClientAsync(provider)) { try { var parameters = new Model.LashingParameters(new Model.DynamicParameters( gm: 5, draft: 10, vesselSpeed: 15.0, windSpeed: 40.0)); parameters.Containers = new List <Model.ContainerParameter> { new Model.ContainerParameter(id: 1, containerId: "AAAU1234568", typeIsoCode: "42G0", grossWeight: 10.1, position: "020206", relativeVcg: 0.50, height: 2.591, length: 12.192, width: 2.438), new Model.ContainerParameter(id: 2, containerId: "AAAU1234569", typeIsoCode: "42G0", grossWeight: 10.1, position: "020282", relativeVcg: 0.50, height: 2.591, length: 12.192, width: 2.438), }; parameters.Calculate = new Model.WhatToCalculateParameterLashing { LoadableWeights = true, PlacedLashBars = true }; var json = JsonConvert.SerializeObject(parameters); var result = await apiClient.PerformLashCalculationsAsync(imoNumber, parameters); } catch (ApiException e) { } } }).Wait(); }
public async Task <ApiResponse <Dictionary <string, int>?> > GetInventoryWithHttpInfoAsync(System.Threading.CancellationToken?cancellationToken = null) { try { using (HttpRequestMessage request = new HttpRequestMessage()) { UriBuilder uriBuilder = new UriBuilder(); uriBuilder.Host = HttpClient.BaseAddress !.Host; uriBuilder.Scheme = ClientUtils.SCHEME; uriBuilder.Path = ClientUtils.CONTEXT_PATH + "/store/inventory"; List <TokenBase> tokens = new List <TokenBase>(); ApiKeyToken apiKey = (ApiKeyToken)await ApiKeyProvider.GetAsync(cancellationToken).ConfigureAwait(false); tokens.Add(apiKey); apiKey.UseInHeader(request, "api_key"); request.RequestUri = uriBuilder.Uri; string[] accepts = new string[] { "application/json" }; string?accept = ClientUtils.SelectHeaderAccept(accepts); if (accept != null) { request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(accept)); } request.Method = HttpMethod.Get; using (HttpResponseMessage responseMessage = await HttpClient.SendAsync(request, cancellationToken.GetValueOrDefault()).ConfigureAwait(false)) { DateTime requestedAt = DateTime.UtcNow; string responseContent = await responseMessage.Content.ReadAsStringAsync(cancellationToken.GetValueOrDefault()).ConfigureAwait(false); if (ApiResponded != null) { try { ApiResponded.Invoke(this, new ApiResponseEventArgs(requestedAt, DateTime.UtcNow, responseMessage.StatusCode, "/store/inventory")); } catch (Exception e) { Logger.LogError(e, "An error occured while invoking ApiResponded."); } } ApiResponse <Dictionary <string, int>?> apiResponse = new ApiResponse <Dictionary <string, int>?>(responseMessage, responseContent); if (apiResponse.IsSuccessStatusCode) { apiResponse.Content = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, int> >(apiResponse.RawContent, ClientUtils.JsonSerializerSettings); } else if (apiResponse.StatusCode == (HttpStatusCode)429) { foreach (TokenBase token in tokens) { token.BeginRateLimit(); } } return(apiResponse); } } } catch (Exception e) { Logger.LogError(e, "An error occured while sending the request to the server."); throw; } }
public async Task <ApiResponse <ModelClient?> > TestClassnameWithHttpInfoAsync(ModelClient modelClient, System.Threading.CancellationToken?cancellationToken = null) { try { #pragma warning disable CS0472 // The result of the expression is always the same since a value of this type is never equal to 'null' if (modelClient == null) { throw new ArgumentNullException(nameof(modelClient)); } #pragma warning disable CS0472 // The result of the expression is always the same since a value of this type is never equal to 'null' using (HttpRequestMessage request = new HttpRequestMessage()) { UriBuilder uriBuilder = new UriBuilder(); uriBuilder.Host = HttpClient.BaseAddress !.Host; uriBuilder.Scheme = ClientUtils.SCHEME; uriBuilder.Path = ClientUtils.CONTEXT_PATH + "/fake_classname_test"; System.Collections.Specialized.NameValueCollection parseQueryString = System.Web.HttpUtility.ParseQueryString(string.Empty); if ((modelClient as object) is System.IO.Stream stream) { request.Content = new StreamContent(stream); } else { // request.Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(modelClient, ClientUtils.JsonSerializerSettings)); request.Content = new StringContent(System.Text.Json.JsonSerializer.Serialize(modelClient, ClientUtils.JsonSerializerOptions)); } List <TokenBase> tokens = new List <TokenBase>(); ApiKeyToken apiKey = (ApiKeyToken)await ApiKeyProvider.GetAsync(cancellationToken).ConfigureAwait(false); tokens.Add(apiKey); apiKey.UseInQuery(request, uriBuilder, parseQueryString, "api_key_query"); uriBuilder.Query = parseQueryString.ToString(); request.RequestUri = uriBuilder.Uri; string[] contentTypes = new string[] { "application/json" }; string?contentType = ClientUtils.SelectHeaderContentType(contentTypes); if (contentType != null) { request.Content.Headers.Add("ContentType", contentType); } string[] accepts = new string[] { "application/json" }; string?accept = ClientUtils.SelectHeaderAccept(accepts); if (accept != null) { request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(accept)); } request.Method = HttpMethod.Patch; using (HttpResponseMessage responseMessage = await HttpClient.SendAsync(request, cancellationToken.GetValueOrDefault()).ConfigureAwait(false)) { DateTime requestedAt = DateTime.UtcNow; string responseContent = await responseMessage.Content.ReadAsStringAsync(cancellationToken.GetValueOrDefault()).ConfigureAwait(false); if (ApiResponded != null) { try { ApiResponded.Invoke(this, new ApiResponseEventArgs(requestedAt, DateTime.UtcNow, responseMessage.StatusCode, "/fake_classname_test")); } catch (Exception e) { Logger.LogError(e, "An error occured while invoking ApiResponded."); } } ApiResponse <ModelClient?> apiResponse = new ApiResponse <ModelClient?>(responseMessage, responseContent); if (apiResponse.IsSuccessStatusCode) { apiResponse.Content = System.Text.Json.JsonSerializer.Deserialize <ModelClient>(apiResponse.RawContent, ClientUtils.JsonSerializerOptions); } else if (apiResponse.StatusCode == (HttpStatusCode)429) { foreach (TokenBase token in tokens) { token.BeginRateLimit(); } } return(apiResponse); } } } catch (Exception e) { Logger.LogError(e, "An error occured while sending the request to the server."); throw; } }
static void Main(string[] args) { Task.Run(async() => { var apiKey = "<YOUR-API-KEY>"; var imoNumber = 1234567; var provider = new ApiKeyProvider { ApiKey = apiKey }; using (var apiClient = await MACS3.Connected.SDK.DangerousGoods.API2.CreateClientAsync(provider)) { try { DaGoCheckParameters parameter = new DaGoCheckParameters(); parameter.Settings = new DaGoSettingsParameter( amendmentNumber: 39, checkForSunlight: true, stowKeepCoolCargoAwayFromReefers: true, stowKeepCoolCargoAwayFromSun: true); parameter.Containers = new List <DaGoContainerParameter> { new DaGoContainerParameter ( id: "11", containerId: "NCVS1234568", typeIsoCode: "42G0", grossWeight: 10.1, position: "020206", relativeVcg: 0.50, height: 2.591, length: 12.192, width: 2.438, openTop: false, liveReefer: false, empty: false, doorOrientationAft: false, foodStuff: false, sunExposed: false, dangerousGoods: new List <DangerousGoodParameter> { new DangerousGoodParameter ( un: 1234, _class: "3", packingGroup: 2, subLabel: "", subLabel2: "", stowageCategory: "E", technicalName: "", flashpoint: -28, limitedQuantity: false, exceptedQuantity: false, marinePollutant: false, caa: false, segregationGroup: "" ) } ), new DaGoContainerParameter ( id: "12", containerId: "NCVS1234569", typeIsoCode: "42G0", grossWeight: 10.1, position: "020208", relativeVcg: 0.50, height: 2.591, length: 12.192, width: 2.438, openTop: false, liveReefer: false, empty: false, doorOrientationAft: false, setPoint: 0, foodStuff: false, sunExposed: false, dangerousGoods: new List <DangerousGoodParameter> { new DangerousGoodParameter ( un: 4, _class: "1.1D", packingGroup: 1, subLabel: "", subLabel2: "", stowageCategory: "4", technicalName: "", limitedQuantity: false, exceptedQuantity: false, marinePollutant: false, caa: false, segregationGroup: "" ) } ) }; parameter.ContainerToCheck = new List <ContainerIdentifier> { new ContainerIdentifier(id: "11", containerId: "NCVS1234568", position: "020206") }; DaGoCheckResult result = await apiClient.PerformDangerousGoodsCheckAsync(imoNumber, parameter); } catch (ApiException e) { } } }).Wait(); }
static void Main(string[] args) { Task.Run(async() => { var apiKey = "<YOUR-API-KEY>"; var imoNumber = 1234567; var provider = new ApiKeyProvider { ApiKey = apiKey }; using (var apiClient = await MACS3.Connected.SDK.Stability.API2.CreateClientAsync(provider)) { try { var parameter = new Model.CalculationsParameter(); parameter.Containers = new List <Model.ContainerParameter> { new Model.ContainerParameter( id: 1, position: "170182", typeIsoCode: "22G0", grossWeight: 14, containerId: "AAAU1234567" ) }; parameter.Tanks = new List <Model.TankParameter> { new Model.TankParameter(name: "5DBP", density: 1.0250, percentageFilled: 50, maxFs: false) }; parameter.Constants = new List <Model.ConstantParameter> { new Model.ConstantParameter( name: "Deadweight constant", lcg: 79.27, tcg: 0, vcg: 7.65, wda: -4.6, wdf: 295, weight: 676 ) }; parameter.Calculate = new Model.WhatToCalculateParameter( stability: true, strength: false, tanks: true ); parameter.Settings = new Model.SettingsParameter(); var availParameters = await apiClient.GetStabilityParametersAsync(imoNumber); parameter.Settings.FreeboardMode = "Summer"; // see availParameters.FreeboardModes[]; var json = JsonConvert.SerializeObject(parameter); var result = await apiClient.CalculateStabilityAsync(imoNumber, parameter); } catch (ApiException e) { } } }).Wait(); }
private void View_PrivateApiKeyChanged(Tuple <ApiKeyRole, IApiKey> apiKeyInfo) { ApiKeyProvider.SetPrivateApiKey(apiKeyInfo.Item1, apiKeyInfo.Item2); }
public ApiKeyController(IApiKeyService apiKeyService, ApiKeyProvider apiKeyProvider, IImageService imageSerivice) { this.apiKeyService = apiKeyService; this.apiKeyProvider = apiKeyProvider; this.imageService = imageSerivice; }