Esempio n. 1
0
        public Uri BuildRequestTokenUri()
        {
            int timestamp = UnixTime.ToUnixTime(DateTime.Now);

            OAuthParameters parameters = new OAuthParameters();

            parameters.ConsumerKey     = ConsumerStore.FixedConsumer.Key;
            parameters.Nonce           = new GuidNonceProvider().GenerateNonce(timestamp);
            parameters.SignatureMethod = "HMAC-SHA1";
            parameters.Timestamp       = timestamp.ToString(CultureInfo.InvariantCulture);
            parameters.Version         = "1.0";
            parameters.Callback        = "http://yourownsite.com/";

            parameters.Signature = ServiceProviderContext.GetSigningProvider("HMAC-SHA1").ComputeSignature(
                SignatureBase.Create("GET", this.RequestTokenBaseUri, parameters),
                ConsumerStore.FixedConsumer.Secret,
                null);

            UriBuilder builder = new UriBuilder(this.RequestTokenBaseUri)
            {
                Query = parameters.ToQueryStringFormat()
            };

            return(builder.Uri);
        }
Esempio n. 2
0
        public Uri BuildEchoCallUri(params KeyValuePair <string, string>[] pairs)
        {
            int timestamp = UnixTime.ToUnixTime(DateTime.Now);

            OAuthParameters parameters = new OAuthParameters();

            parameters.ConsumerKey     = ConsumerStore.FixedConsumer.Key;
            parameters.Nonce           = new GuidNonceProvider().GenerateNonce(timestamp);
            parameters.SignatureMethod = "HMAC-SHA1";
            parameters.Timestamp       = timestamp.ToString(CultureInfo.InvariantCulture);
            parameters.Version         = "1.0";
            parameters.Token           = TokenGenerator.FixedAccessToken.Token;

            foreach (KeyValuePair <string, string> pair in pairs)
            {
                parameters.AdditionalParameters.Add(pair.Key, pair.Value);
            }

            parameters.Signature = ServiceProviderContext.GetSigningProvider("HMAC-SHA1").ComputeSignature(
                SignatureBase.Create("GET", this.EchoApiBaseUri, parameters),
                ConsumerStore.FixedConsumer.Secret,
                TokenGenerator.FixedAccessToken.Secret);

            UriBuilder builder = new UriBuilder(this.EchoApiBaseUri)
            {
                Query = parameters.ToQueryStringFormat()
            };

            return(builder.Uri);
        }
Esempio n. 3
0
        public void Test_SigningProviderLookup()
        {
            ISigningProvider provider;

            provider = ServiceProviderContext.GetSigningProvider("HMAC-SHA1");
            Assert.That(provider, Is.TypeOf(typeof(HmacSha1SigningProvider)));
            Assert.That(provider.SignatureMethod, Is.EqualTo("HMAC-SHA1"));
        }
Esempio n. 4
0
        public void Test_NonexistentSigningProviderLookup()
        {
            ISigningProvider provider = ServiceProviderContext.GetSigningProvider("MADEUP");

            Assert.That(provider, Is.Null);
        }