public void AuthorizeWithBasicAuthentication() { var logger = Substitute.For<ILog>(); var testHandler = new TestHandler((request, cancelation) => { Assert.AreEqual("Basic", request.Headers.Authorization.Scheme); var authDetailsBytes = Convert.FromBase64String(request.Headers.Authorization.Parameter); var authDetails = Encoding.GetEncoding("iso-8859-1").GetString(authDetailsBytes); var authArray = authDetails.Split(':'); Assert.AreEqual("testToken", authArray[0]); Assert.AreEqual("testSecret", authArray[1]); return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)); }); var credentials = new Credentials("testToken", "testSecret"); var handler = new AuthorizationHandler(credentials, logger) {InnerHandler = testHandler}; var client = new HttpClient(handler); // ReSharper disable once MethodSupportsCancellation var response = client.GetAsync("http://lodididki"); Assert.AreEqual(HttpStatusCode.OK, response.Result.StatusCode); }
private static JudoPayApi Create(Credentials credentials, JudoEnvironment environment) { string baseUrl = null; switch (environment) { case JudoEnvironment.Live: baseUrl = LIVE_URL; break; case JudoEnvironment.Sandbox: baseUrl = SANDBOX_URL; break; } IHttpClientHelper httpClientHelper = DependencyService.Get<IHttpClientHelper>(); IClientService clientService = DependencyService.Get<IClientService>(); var nh = new NativeHandler(httpClientHelper.MessageHandler, credentials, XamarinLoggerFactory.Create(typeof(AuthorizationHandler)), Apiversionheader, API_VERSION, clientService); HttpClientWrapper httpClient = new HttpClientWrapper(nh); var connection = new Connection(httpClient, XamarinLoggerFactory.Create, baseUrl); var client = new Client(connection); return new JudoPayApi(XamarinLoggerFactory.Create, client); }
public void SetupOnce() { var logger = Substitute.For<ILog>(); var credentials = new Credentials("ABC"); _versionHandler = new VersioningHandler(API_VERSION); _authorizationHandlerhandler = new AuthorizationHandler(credentials, logger); }
public NativeHandler(HttpMessageHandler innerHandler, Credentials credentials, ILog log, string apiVersionHeader, string apiVersionValue, IClientService clientService) : base(innerHandler) { _log = log; _credentials = credentials; _clientService = clientService; _apiVersionHeader = apiVersionHeader; _apiVersionValue = apiVersionValue; }
public static JudoPayApi Create(string token, string secret, string address) { var credentials = new Credentials(token, secret); var httpClient = new HttpClientWrapper(); var connection = new Connection(httpClient, WindowsPhoneLoggerFactory.Create(typeof(Connection)), address); var client = new Client(connection); return new JudoPayApi(credentials, client); }
public AuthorizationHandler(Credentials credentials, ILog log) { _log = log; _credentials = credentials; _authenticationType = AuthType.Unknown; if (!String.IsNullOrWhiteSpace(_credentials.OAuthAccessToken)) { _authenticationType = AuthType.Bearer; } else if (!String.IsNullOrWhiteSpace(_credentials.Token) && !String.IsNullOrWhiteSpace(_credentials.Secret)) { _authenticationType = AuthType.Basic; } }
/// <summary> /// Factory method for the benefit of platform tests that need to have finer grained control of the API version /// </summary> /// <param name="credentials">The api token and secret to use</param> /// <param name="baseUrl">Base URL for the host</param> /// <param name="apiVersion">The api version to use</param> /// <param name="userAgent">User-Agent details to set in the header for each request</param> /// <returns>Initialized instance of the Judopay api client</returns> internal static JudoPayApi Create(Credentials credentials, string baseUrl, string apiVersion, ProductInfoHeaderValue userAgent) { var userAgentCollection = new List<ProductInfoHeaderValue>(); userAgentCollection.Add(new ProductInfoHeaderValue("DotNetCLR", Environment.Version.ToString())); userAgentCollection.Add(new ProductInfoHeaderValue(Environment.OSVersion.Platform.ToString(), Environment.OSVersion.Version.ToString())); if (userAgent != null) userAgentCollection.Add(userAgent); var httpClient = new HttpClientWrapper( userAgentCollection, new AuthorizationHandler(credentials, DotNetLoggerFactory.Create(typeof(AuthorizationHandler))), new VersioningHandler(apiVersion)); var connection = new Connection(httpClient, DotNetLoggerFactory.Create, baseUrl); var client = new Client(connection); return new JudoPayApi(DotNetLoggerFactory.Create, client); }
public void AuthorizeWithOAuth() { var logger = Substitute.For<ILog>(); var testHandler = new TestHandler((request, cancelation) => { Assert.AreEqual("Bearer", request.Headers.Authorization.Scheme); Assert.AreEqual("ABC", request.Headers.Authorization.Parameter); return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)); }); var credentials = new Credentials("ABC"); var handler = new AuthorizationHandler(credentials, logger) {InnerHandler = testHandler}; var client = new HttpClient(handler); // ReSharper disable once MethodSupportsCancellation var response = client.GetAsync("http://lodididki"); Assert.AreEqual(HttpStatusCode.OK, response.Result.StatusCode); }
private static JudoPayApi Create(Credentials credentials, Environment environment) { string baseUrl = null; switch (environment) { case Environment.Live: baseUrl = LIVE_URL; break; case Environment.Sandbox: baseUrl = SANDBOX_URL; break; } var httpClient = new HttpClientWrapper(new AuthorizationHandler(credentials, XamarinLoggerFactory.Create(typeof(AuthorizationHandler))), new VersioningHandler(Apiversionheader, API_VERSION)); var connection = new Connection(httpClient, XamarinLoggerFactory.Create, baseUrl); var client = new Client(connection); return new JudoPayApi(XamarinLoggerFactory.Create, client); }
internal static JudoPayApi Create(Credentials credentials, JudoEnvironment judoEnvironment, string apiVersion) { return Create(credentials, GetEnvironmentUrl(judoEnvironment), apiVersion, null); }
/// <summary> /// Factory method for the benefit of platform tests that need to have finer grained control of the API version /// </summary> /// <param name="credentials">The api token and secret to use</param> /// <param name="baseUrl">Base URL for the host</param> /// <param name="apiVersion">The api version to use</param> /// <returns>Initialized instance of the Judopay api client</returns> internal static JudoPayApi Create(Credentials credentials, string baseUrl, string apiVersion) { return Create(credentials, baseUrl, apiVersion, null); }
private static JudoPayApi Create(Credentials credentials, string baseUrl, IJudoConfiguration configuration, ProductInfoHeaderValue userAgent) { var apiVersion = GetConfigValue(ApiVersionKey, VersioningHandler.DEFAULT_API_VERSION, configuration); return Create(credentials, baseUrl, apiVersion, userAgent); }
/// <summary> /// Creates an instance of the judopay API client with a custom base url, that will authenticate with your API token and secret. /// </summary> /// <remarks>This is intended for development/sandbox environments</remarks> /// <param name="token">Your API token (from our merchant dashboard)</param> /// <param name="secret">Your API secret (from our merchant dashboard)</param> /// <param name="baseUrl">Base URL for the Judopay api</param> /// <param name="userAgent">The name and version number of the calling application, should be in the form PRODUCT/VERSION</param> /// <param name="configuration">Application configuration accessor</param> /// <returns>Initialized instance of the Judopay api client</returns> public static JudoPayApi Create(string token, string secret, string baseUrl, IJudoConfiguration configuration = null) { var credentials = new Credentials(token, secret); return Create(credentials, baseUrl, configuration ?? defaultConfigurationAccess, null); }