Exemplo n.º 1
0
        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            HttpRequestMessageProperty httpRequestProperty = request.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;

            NameValueCollection rawParameters = HttpUtility.ParseQueryString(request.Headers.To.Query);
            UriBuilder uriBuilder = new UriBuilder(request.Headers.To);
            uriBuilder.Query = Rfc3986.EncodeAndJoin(rawParameters);

            request.Headers.To = uriBuilder.Uri;

            OAuthConsumer consumer = new OAuthConsumer(_credentials.OAuthKey, _credentials.OAuthSecret);

            int unixTime = UnixTime.ToUnixTime(DateTime.UtcNow);

            OAuthParameters parameters = new OAuthParameters();
            parameters.Version = Constants.Version1_0;
            parameters.SignatureMethod = "RSA-SHA1";
            parameters.ConsumerKey = _credentials.OAuthKey;
            parameters.Token = _credentials.OAuthToken;
            parameters.TokenSecret = _credentials.OAuthTokenSecret;
            parameters.Timestamp = unixTime.ToString();
            parameters.Nonce = _nonceProvider.GenerateNonce(unixTime);

            RsaSha1SigningProvider provider = new RsaSha1SigningProvider();
            provider.PfxFile = _credentials.OAuthPfxFile;
            provider.PfxPassword = _credentials.OAuthPfxPassword;

            parameters.Sign(request.Headers.To, httpRequestProperty.Method, consumer, null, provider);

            httpRequestProperty.Headers["Authorization"] = parameters.ToHeaderFormat();

            return null;
        }
Exemplo n.º 2
0
        public void TestCase()
        {
            ISigningProvider rsa = new RsaSha1SigningProvider()
            {
                // PFX file is copied to output directory
                PfxFile = @"WikiTests\testcase.rsa.pfx"
            };

            OAuthParameters parameters = new OAuthParameters()
            {
                SignatureMethod = "RSA-SHA1",
                Version = Constants.Version1_0,
                ConsumerKey = "dpf43f3p2l4k3l03",
                Timestamp = "1196666512",
                Nonce = "13917289812797014437"
            };
            parameters.AdditionalParameters.Add("file", "vacaction.jpg");
            parameters.AdditionalParameters.Add("size", "original");

            Uri baseUri = new Uri("http://photos.example.net/photos");

            string sigbase = SignatureBase.Create(
                "GET", 
                baseUri, 
                parameters);

            Assert.That(sigbase, Is.EqualTo("GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacaction.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3D13917289812797014437%26oauth_signature_method%3DRSA-SHA1%26oauth_timestamp%3D1196666512%26oauth_version%3D1.0%26size%3Doriginal"));

            parameters.Signature = rsa.ComputeSignature(sigbase, "kd94hf93k423kf44", null);

            Assert.That(parameters.Signature, Is.EqualTo("jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE="));

            // There is no point comparing the URLs because order is not query string parameter important in URLs
        }