Ejemplo n.º 1
0
        public void TestTokenCaching()
        {
            Action<WebRequest> verifier = (WebRequest wr) =>
            {
                var req = wr as WebMocker.MockRequest;
                Assert.AreEqual("POST", wr.Method);
                Assert.AreEqual("api-key", req.Body);
            };

            Mocker.Mock(new Uri("test:///authn/users/username/authenticate"), "token1")
                .Verifier = verifier;

            var credential = new NetworkCredential("username", "api-key");
            var authenticator = new ApiKeyAuthenticator(new Uri("test:///authn"), credential);

            Assert.AreEqual("token1", authenticator.GetToken());

            Mocker.Mock(new Uri("test:///authn/users/username/authenticate"), "token2")
                .Verifier = verifier;

            Assert.AreEqual("token1", authenticator.GetToken());

            authenticator.StartTokenTimer(new TimeSpan(0, 0, 0, 0, 1));
            Thread.Sleep(10);

            Assert.AreEqual("token2", authenticator.GetToken());
        }
Ejemplo n.º 2
0
        public static async Task <string> MakeAuthenticatedSubscriptionAsync(Subscription subscription, WebSocketConfig config)
        {
            subscription.ExtraJson.Add("key", config.ApiKey);
            subscription.ExtraJson.Add("passphrase", config.Passphrase);

            var timestamp = await TimeHelper.GetCurrentTimestampAsync(config.UseTimeApi)
                            .ConfigureAwait(false);

            subscription.ExtraJson.Add("timestamp", timestamp);

            var signature = ApiKeyAuthenticator.GenerateSignature(timestamp, "GET", "/users/self/verify", null, config.Secret);

            subscription.ExtraJson.Add("signature", signature);

            return(JsonConvert.SerializeObject(subscription));
        }
Ejemplo n.º 3
0
        public CoinbaseClient(string token, ApiKeyAuthenticator method)
        {
            _isDisposed = false;

            if (String.IsNullOrWhiteSpace(token))
            {
                throw new ArgumentException(String.Format("Parameter 'token' passed to {0} constructor must not be empty.", ClassName));
            }

            if (method == null)
            {
                throw new ArgumentNullException("method", "Authentication method must be specified.");
            }

            _authToken = token;
            _method    = method;
        }
Ejemplo n.º 4
0
 public void CreateAuthenticator()
 {
     Authenticator = new ApiKeyAuthenticator(new Uri("test:///authn"), credential);
 }