Esempio n. 1
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. 2
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. 3
0
        public Uri BuildAuthorizationUrl(
            IToken token,
            NameValueCollection additionalParameters)
        {
            if (token.Type == TokenType.Request)
            {
                OAuthParameters authParameters = new OAuthParameters()
                {
                    Token = token.Token
                };

                if (additionalParameters != null)
                {
                    authParameters.AdditionalParameters.Add(additionalParameters);
                }

                // Construct final authorization Uri (HTTP method must be GET)
                string query = authParameters.ToQueryStringFormat();

                UriBuilder authUri = new UriBuilder(this.AuthorizationUrl);

                if (String.IsNullOrEmpty(authUri.Query))
                {
                    authUri.Query = query;
                }
                else
                {
                    authUri.Query = authUri.Query.Substring(1) + "&" + query;
                }

                return(authUri.Uri);
            }
            else
            {
                throw new ArgumentException("Invalid token type for Authorization");
            }
        }