コード例 #1
0
ファイル: OAuthRequest.cs プロジェクト: yhtsnda/oauth-dot-net
        protected virtual void SignParameters(Uri requestUri, string httpMethod, OAuthParameters authParameters, IToken token)
        {
            // Check there is a signing provider for the signature method
            ISigningProvider signingProvider = this.Service.ComponentLocator.GetInstance <ISigningProvider>(Constants.SigningProviderIdPrefix + this.Service.SignatureMethod);

            if (signingProvider == null)
            {
                // There is no signing provider for this signature method
                OAuthRequestException.ThrowSignatureMethodRejected(null);
            }

            // Double check the signing provider declares that it can handle the signature method
            if (!signingProvider.SignatureMethod.Equals(this.Service.SignatureMethod))
            {
                OAuthRequestException.ThrowSignatureMethodRejected(null);
            }

            // Compute the signature
            authParameters.Sign(requestUri, httpMethod, this.Service.Consumer, token, signingProvider);
        }
コード例 #2
0
        public void TestConsumerRequestSignature()
        {
            OAuthService service = OAuthService.Create(
                new EndPoint("http://example.com/request_token"),
                new Uri("http://example.com/authorize"),
                new EndPoint("http://example.com/access_token"),
                new MockConsumer()
            {
                Key    = "dpf43f3p2l4k3l03",
                Secret = "kd94hf93k423kf44",
                Status = ConsumerStatus.Valid
            });

            OAuthRequest consumerRequest =
                OAuthConsumerRequest.Create(
                    new EndPoint("http://provider.example.net/profile", "GET"),
                    service);

            OAuthParameters authParameters = new OAuthParameters()
            {
                ConsumerKey     = service.Consumer.Key,
                Realm           = service.Realm,
                SignatureMethod = service.SignatureMethod,
                Timestamp       = "1191242096",
                Nonce           = "kllo9940pd9333jh",
                Version         = service.OAuthVersion
            };

            Assert.AreEqual(
                SignatureBase.Create(consumerRequest.ResourceEndPoint.HttpMethod, consumerRequest.ResourceEndPoint.Uri, authParameters),
                "GET&http%3A%2F%2Fprovider.example.net%2Fprofile&oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_version%3D1.0");

            authParameters.Sign(consumerRequest.ResourceEndPoint.Uri,
                                consumerRequest.ResourceEndPoint.HttpMethod,
                                service.Consumer,
                                consumerRequest.RequestToken,
                                new OAuth.Net.Components.HmacSha1SigningProvider());

            Assert.AreEqual(authParameters.Signature, "SGtGiOrgTGF5Dd4RUMguopweOSU=");
        }