/// <summary> /// Create a checkout Creates a Afterpay checkout. During the checkout process a customer can apply for credit decisioning in real-time. This means the checkout needs to represent a good picture of known customer details along with order information and the checkout entity represents this as a resource. For more information on how to checkout with Afterpay see the #model:Z2QcrzRGHACY8wM6G guide. /// </summary> /// <exception cref="MerchantApi.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="body"> (optional)</param> /// <returns>Checkout</returns> public Authentication AuthorizationCreateToken() { this.Configuration.Timeout = 15000; //15 Seconds var authorization = Convert.ToBase64String(Encoding.Default.GetBytes(this.Configuration.MerchantId + ":" + this.Configuration.MerchantSecretKey)); this.Configuration.AccessToken = authorization; Configuration.AddApiKey("Authorization", this.Configuration.AccessToken); Configuration.AddApiKeyPrefix("Authorization", "Basic"); Configuration.AddApiKey("User-Agent", this.Configuration.UserAgent); Configuration.AddApiKeyPrefix("User-Agent", "User-Agent"); var authorityRequest = new AuthorityRequest(AuthorityRequest.TypeEnum.ClientCredentials, this.Configuration.MerchantId, this.Configuration.MerchantSecretKey); ApiResponse <Authentication> localVarResponse = AuthorizationCreateWithHttpInfo(); if ((System.Net.HttpStatusCode)localVarResponse.StatusCode == System.Net.HttpStatusCode.OK) { return(localVarResponse.Data); } return(null); }
public void Init() { Configuration configuration = new Configuration(); configuration.AddApiKey("APG-API-KEY", "APG3oNq6T4xJTzPiyaLRBIQqfW8VhswK4a79zGxG1nPM7pPtPO5JXUqooEtxQUxl"); /// CHANGE api key to yours. instance = new PaymentApi(configuration); }
private static void Init() { // load db and configuration string currentDir = Directory.GetCurrentDirectory(); DbReader.DbFile = (Path.Combine(currentDir, "db.json")); db = DbReader.Load(); config = ConfigReader.Get(currentDir, "config.json"); downloadFolder = Path.GetFullPath(Path.Combine(currentDir, (string)config.downloadFolder)); Directory.CreateDirectory(downloadFolder); // setup the client Configuration clientConfig = new Configuration(); clientConfig.Timeout = (int)config.timeout; clientConfig.setApiClientUsingDefault(); clientConfig.AddApiKey("api_key_both", (string)config.apiPwd); clientConfig.ApiClient = new ApiClient((string)config.basePath); bundlesApi = new BundlesApi(clientConfig); RestClient client = bundlesApi.Configuration.ApiClient.RestClient; //X509Certificate cert = CertificateReader.LoadFromPemFile(Path.GetFullPath(Path.Combine(currentDir, (string)config.crt.cert))); //client.ClientCertificates = new X509CertificateCollection{ cert }; Console.WriteLine("Api calls will be sent to: \"" + bundlesApi.GetBasePath() + "\"."); // The timer for checking new files in the local directory recheckTimer = new Timer((double)config.interval); recheckTimer.Elapsed += new ElapsedEventHandler( async(object source, ElapsedEventArgs evt) => { try { // Queue the recheck on the thread pool because // synchronization back into this context isn't needed // flags are used to prevent the application from exiting early await Task.Run(async() => { await DoRecheckBundles(source, evt); }); } catch (ApiException e) { Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine( "An Api Exception occured:\n\tMessage: " + e.Message + "\n\tHTTP Status Code: " + e.ErrorCode + "\n\tBody: " + e.ErrorContent ); Console.ResetColor(); } } ); Console.WriteLine("The available bundles will be checked every " + recheckTimer.Interval + " ms and saved to \"" + downloadFolder + "\" ."); }
public void SetToken(string customtoken, string server) { Configuration = new Configuration(new ApiClient(String.Format(URL, server))); token = customtoken; Configuration.AddApiKey("Authorization", "Bearer " + customtoken); }
public API(string accessToken, string host = "https://api.youneedabudget.com/v1", bool useHttps = true) { // TODO: Use this _useHttps = useHttps; _config.AddApiKey("Authorization", accessToken); _config.AddApiKeyPrefix("Authorization", "Bearer"); _config.BasePath = host; }
public void SetToken(string customtoken) { Configuration = new Configuration(new ApiClient(URL)); token = customtoken; Configuration.AddApiKey("Authorization", "Bearer " + customtoken); }
/// <summary> /// Create a Order Creates a zipMoney Order. During the Order process a customer can apply for credit decisioning in real-time. This means the Order needs to represent a good picture of known customer details along with order information and the Order entity represents this as a resource. For more information on how to Order with zipMoney see the #model:Z2QcrzRGHACY8wM6G guide. /// </summary> /// <exception cref="MerchantApi.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="body"> (optional)</param> /// <returns>Task of Order</returns> public async System.Threading.Tasks.Task <OrderCreateResponse> OrderCreateAsync(AccessToken accessToken = null, string idempotencyKey = null, CreateOrderRequest body = null) { Configuration.AddApiKey("Authorization", accessToken.Token); Configuration.AddApiKeyPrefix("Authorization", "Bearer"); Configuration.AddApiKey("Idempotency-Key", idempotencyKey); Configuration.AddApiKeyPrefix("Idempotency-Key", "Idempotency-Key"); ApiResponse <OrderCreateResponse> localVarResponse = await OrderCreateAsyncWithHttpInfo(body); return(localVarResponse.Data); }
public VoidOrder OrderVoid(AccessToken accessToken, string id, string idempotencyKey = null, CreateVoidRequest body = null) { Configuration.AddApiKey("Authorization", accessToken.Token); Configuration.AddApiKeyPrefix("Authorization", "Bearer"); Configuration.AddApiKey("Idempotency-Key", idempotencyKey); Configuration.AddApiKeyPrefix("Idempotency-Key", "Idempotency-Key"); ApiResponse <VoidOrder> localVarResponse = OrderVoidWithHttpInfo(id, body); return(localVarResponse.Data); }
public void BeforeScenario() { var config = SetupUtils.ReadConfig <TestConfig>("testconfig.json"); objectContainer.RegisterInstanceAs <TestConfig>(config); objectContainer.RegisterInstanceAs <IWebDriver>(SetupUtils.CreateDriver(config)); var apiConfig = new Configuration(); apiConfig.BasePath = config.ApiBaseUrl; apiConfig.AddApiKey("Ocp-Apim-Subscription-Key", config.ApimKey); objectContainer.RegisterInstanceAs <DefaultApi>(new DefaultApi(apiConfig)); }
/// <summary> /// Retrieve a Order Retrieves a previously created Order by id. /// </summary> /// <exception cref="MerchantApi.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id"></param> /// <returns>Order</returns> public CheckoutOrder OrderGet(AccessToken accessToken, string id) { // verify the required parameter 'id' is set if (id == null) { throw new ApiException(400, "Missing required parameter 'id' when calling OrdersApi->OrderGet"); } Configuration.AddApiKey("Authorization", accessToken.Token); Configuration.AddApiKeyPrefix("Authorization", "Bearer"); ApiResponse <CheckoutOrder> localVarResponse = OrderGetWithHttpInfo(id); return(localVarResponse.Data); }
/// <summary> /// Creates API accessor. /// </summary> /// <typeparam name="TApiAccessor"> /// The API accessor type. /// </typeparam> /// <param name="accessToken"> /// The access token. /// </param> /// <returns> /// The API accessor. /// </returns> private static TApiAccessor CreateApiAccessor <TApiAccessor>(string accessToken) where TApiAccessor : IApiAccessor, new() { // A generic method create api accessor generated by codegen. const string AuthorizationHeaderKey = "Authorization"; // Version suffix should be ommited in path. var configuration = new Configuration(new ApiClient(ResourceServerEndpointAddressBase)); // Add 'Bearer' token authorization. configuration.AddApiKeyPrefix(AuthorizationHeaderKey, "Bearer"); configuration.AddApiKey(AuthorizationHeaderKey, accessToken); return(new TApiAccessor { Configuration = configuration }); }
private static Configuration GetConfig() { VerifyAuthentication(); var config = new Configuration(); /* * The generated ApiClient still does not understand the use of the Bearer token, * it's trying to use Basic Auth. This workaround exists to explicitly set the Authorization * header */ config.AddApiKey(AuthScheme, BearerToken); config.AddApiKeyPrefix(AuthScheme, BearerPrefix); config.DefaultHeaders[AuthorizationHeader] = config.GetApiKeyWithPrefix(AuthScheme); return(config); }
private async Task <string> SendViaSendInBlue(SendSmtpEmail msg) { var configuration = new Configuration(); configuration.AddApiKey("api-key", emailSettings.SendInBlueSettings.ApiKey); var apiInstance = new SMTPApi(configuration); try { // Send a transactional email CreateSmtpEmail result = await apiInstance.SendTransacEmailAsync(msg); logger.LogDebug("SendInBlue sent email {Result}", result.MessageId); return(result.MessageId); } catch (Exception e) { throw new SendInBlueException("Exception when calling SMTPApi.SendTransacEmailAsync: ", e); } }
public Configuration Configuration() { Configuration conf = new Configuration(); AuthApi authApi = new AuthApi(conf); var requestEup = new WasteRegisterPublicApiApiModelsRequestsAuthV1EupRequest(); requestEup.ClientId = "a9b06fba-e707-47ef-b21a-c9f25932e17c"; requestEup.ClientSecret = "f67194ff2f5643b08634a0c006ca7cab7095db4394b149daaa93254199790969"; requestEup.PaginationParameters = new WasteRegisterPublicApiApiModelsRequestsAuthV1AuthPaginationParameters() { Order = new WasteRegisterPublicApiApiModelsRequestsAuthV1Aorder() { IsAscending = true }, Page = new WasteRegisterPublicApiApiModelsRequestsAuthV1Apage() { Index = 1, Size = 10 }, }; var responseEup = authApi.GetEupList(requestEup); var requestToken = new WasteRegisterPublicApiApiModelsRequestsAuthV1JwtRequest(); requestToken.EupId = responseEup.Items[0].EupId.ToString(); requestToken.ClientId = "a9b06fba-e707-47ef-b21a-c9f25932e17c"; requestToken.ClientSecret = "f67194ff2f5643b08634a0c006ca7cab7095db4394b149daaa93254199790969"; var responseToken = authApi.GenerateEupAccessToken(requestToken); conf.AccessToken = responseToken.AccessToken; conf.Password = "******"; conf.Username = "******"; conf.AddApiKey("Authorization", conf.AccessToken); conf.AddApiKeyPrefix("Authorization", "Bearer"); return(conf); }
public async Task <bool> CanBearerTokenUsed(string bearerToken) { var tmpConfiguration = new Configuration { BasePath = AccountApi.Configuration.BasePath //DefaultHeader = {["Authorization"] = string.Concat(AuthorizationPrefix, bearerToken)}, }; tmpConfiguration.AddApiKeyPrefix("Authorization", "Bearer"); tmpConfiguration.AddApiKey("Authorization", bearerToken); var testApi = new UsersApi(tmpConfiguration); try { var test = await testApi.UsersGetCurrentUserAsync(); return(test != null); } catch (Exception) { return(false); } }
protected override void RegisterTypes(IContainerRegistry containerRegistry) { containerRegistry.RegisterSingleton <IAppInfo, AppInfoImplementation>(); containerRegistry.RegisterSingleton <IDeviceInfo, DeviceInfoImplementation>(); containerRegistry.RegisterSingleton <ISecureStorage, SecureStorageImplementation>(); containerRegistry.RegisterSingleton <IConnectivity, ConnectivityImplementation>(); Configuration config = new Configuration(); config.BasePath = "http://10.0.2.2:5000"; // Configure API key authorization: RiskAppKey config.AddApiKey("Risk-App-Key", "azVd94zazPu/+q5ZHqoL1v6wccamHV3oWoALYWQK0Z8="); // Configure Bearer token for authorization: AccessToken config.AccessToken = string.Empty; containerRegistry.RegisterInstance <IReadableConfiguration>(config); containerRegistry.RegisterInstance <IAutApi>(new AutApi(config)); containerRegistry.RegisterInstance <IGenApi>(new GenApi(config)); containerRegistry.RegisterInstance <IMsjApi>(new MsjApi(config)); containerRegistry.RegisterInstance <IRepApi>(new RepApi(config)); containerRegistry.RegisterForNavigation <NavigationPage>(); containerRegistry.RegisterForNavigation <MainPage, MainPageViewModel>(); containerRegistry.RegisterForNavigation <LoginPage, LoginPageViewModel>(); containerRegistry.RegisterForNavigation <NoConnectionPage, NoConnectionPageViewModel>(); // Polly PolicyRegistry registry = new PolicyRegistry(); var authorizationEnsuringPolicy = Policy .HandleResult <ApiException>(r => r.ErrorCode == 401 /*HttpStatusCode.Unauthorized*/) .RetryAsync(1, async(outcome, retryNumber, context) => { var autApi = Container.Resolve <IAutApi>(); var secureStorage = Container.Resolve <ISecureStorage>(); // Busca Access Token string accessToken; try { accessToken = await secureStorage.GetAsync(RiskConstants.ACCESS_TOKEN); } catch (Exception) { accessToken = string.Empty; } // Busca Refresh Token string refreshToken; try { refreshToken = await secureStorage.GetAsync(RiskConstants.REFRESH_TOKEN); } catch (Exception) { refreshToken = string.Empty; } SesionRespuesta respuestaRefrescarSesion = null; try { respuestaRefrescarSesion = await autApi.RefrescarSesionAsync(null, new RefrescarSesionRequestBody { AccessToken = accessToken, RefreshToken = refreshToken }); if (respuestaRefrescarSesion.Codigo.Equals(RiskConstants.CODIGO_OK)) { await secureStorage.SetAsync(RiskConstants.ACCESS_TOKEN, respuestaRefrescarSesion.Datos.AccessToken); await secureStorage.SetAsync(RiskConstants.REFRESH_TOKEN, respuestaRefrescarSesion.Datos.RefreshToken); var apiConfig = (Configuration)autApi.Configuration; // Aca en realidad hay que configurar todos los Api? config.AccessToken = respuestaRefrescarSesion.Datos.AccessToken; this.Properties[RiskConstants.IS_USER_LOGGED_IN] = true; } else { secureStorage.Remove(RiskConstants.ACCESS_TOKEN); secureStorage.Remove(RiskConstants.REFRESH_TOKEN); this.Properties[RiskConstants.IS_USER_LOGGED_IN] = false; await NavigationService.NavigateAsync("/LoginPage"); } } catch (Exception) { secureStorage.Remove(RiskConstants.ACCESS_TOKEN); secureStorage.Remove(RiskConstants.REFRESH_TOKEN); this.Properties[RiskConstants.IS_USER_LOGGED_IN] = false; await NavigationService.NavigateAsync("/LoginPage"); } } ); registry.Add("AuthorizationEnsuringPolicy", authorizationEnsuringPolicy); }