public DefaultOAuthAuthorizationPolicy(CredentialSet credentials)
 {
     _innerOauthPolicy = new OAuthAuthorizationPolicy(
         new MadgexOAuthHeader(new SystemClock(), new SystemNonceFactory()),
         credentials
     );
 }
예제 #2
0
        public string New(Request request, CredentialSet credentials)
        {
            var parameters = ToParameters(request, credentials);

            parameters.Signature = Sign(request, credentials, parameters);

            return parameters.ToHeaderFormat();
        }
예제 #3
0
 private String Sign(
     Request request,
     CredentialSet credentials,
     OAuthParameters parameters
     )
 {
     return new MadgexSignature().Sign(
         request,
         credentials.Consumer.Secret,
         credentials.Token.Secret,
         parameters
     );
 }
        public void can_generate_correct_header_without_token()
        {
            var request = Request.Get(new Uri("http://xxx/"));
            request.ContentType = "application/x-www-form-urlencoded";
            var consumer = new CredentialSet(new Credential("key", "secret"));

            _clock.Stub(clock => clock.NewTimestamp()).Return("1303687141");
            _nonceFactory.Stub(clock => clock.NewNonce()).Return("38a2dd30277558668a92913686175bb1");

            var instance = new MadgexOAuthHeader(_clock, _nonceFactory);
            var result = instance.New(request, consumer);

            Assert.That(result, Contains.Substring("oauth_signature=\"lKUJBmz5ULuNh67y8KRGrWRRMvI%3D\""));
        }
예제 #5
0
        public void if_you_supply_invalid_credentials_you_get_an_error()
        {
            var invalidCredentials = new CredentialSet(new Credential("xxx_clearly_invalid", ""));

            var authorizationPolicy = new OAuthAuthorizationPolicy(
                new MadgexOAuthHeader(new SystemClock(), new SystemNonceFactory()),
                invalidCredentials
            );

            var theInternet = new SystemInternet(authorizationPolicy);
            var nodes = new Nodes(theInternet, Settings.BaseUrl);

            var theError = Assert.Throws<Exception>(() => nodes.FindAll());

            Assert.That(theError.Message, Is.StringEnding("The server returned status Unauthorized (401), and error message: \"Invalid OAuth Request\""));
        }
예제 #6
0
        private OAuthParameters ToParameters(Request request, CredentialSet credentials)
        {
            var options = Options.Default;

            var parameters = new OAuthParameters {
                ConsumerKey     = credentials.Consumer.Key,
                Timestamp       = NewTimestamp,
                Nonce           = NewNonce,
                SignatureMethod = options.SignatureMethod,
                Version         = options.Version.ToString()
            };

            parameters.AdditionalParameters.Add(CollectAllParameters(request));

            un.less(String.IsNullOrEmpty(credentials.Token.Key), () =>
                parameters.Token = credentials.Token.Key
            );

            return parameters;
        }
 private String GetAuthHeader(Request request, CredentialSet credentials)
 {
     return _oAuthHeader.New(request, credentials);
 }
 public OAuthAuthorizationPolicy(OAuthHeader oAuthHeader, CredentialSet credentials)
 {
     _oAuthHeader = oAuthHeader;
     _credentials = credentials;
 }
        public void requests_a_new_nonce_and_new_timestamp_with_each_invocation()
        {
            var request = Request.Get(new Uri("http://xxx/?name=value"));
            request.ContentType = "application/x-www-form-urlencoded";
            var consumerAndToken = new CredentialSet(Credential.Empty, Credential.Empty);

            var mockClock = MockRepository.GenerateStub<Clock>();
            mockClock.Stub(clock => clock.NewTimestamp()).Return("1303692000");
            var mockNonce = MockRepository.GenerateStub<NonceFactory>();
            mockNonce.Stub(clock => clock.NewNonce()).Return("ba3af980256a87ba503c19ef91863c5e");

            var instance = new MadgexOAuthHeader(mockClock, mockNonce);

            instance.New(request, consumerAndToken);
            instance.New(request, consumerAndToken);

            mockClock.AssertWasCalled(clock => clock.NewTimestamp(), options => options.Repeat.Twice());
            mockNonce.AssertWasCalled(nonce => nonce.NewNonce(), options => options.Repeat.Twice());
        }