Esempio n. 1
0
        /// <summary>
        /// Method that returns the initial URL to be displayed in the web browser.
        /// </summary>
        /// <returns>
        /// A task that will return the initial URL.
        /// </returns>
        public override Task <Uri> GetInitialUrlAsync()
        {
            var req = OAuth1.CreateRequest(
                "GET",
                requestTokenUrl,
                new Dictionary <string, string>()
            {
                { "oauth_callback", callbackUrl.AbsoluteUri },
            },
                consumerKey,
                consumerSecret,
                "");

            return(req.GetResponseAsync().ContinueWith(respTask => {
                var content = respTask.Result.GetResponseText();

                var r = WebEx.FormDecode(content);

                token = r["oauth_token"];
                tokenSecret = r["oauth_token_secret"];

                string paramType = authorizeUrl.AbsoluteUri.IndexOf("?") >= 0 ? "&" : "?";

                var url = authorizeUrl.AbsoluteUri + paramType + "oauth_token=" + Uri.EscapeDataString(token);
                return new Uri(url);
            }));
        }
Esempio n. 2
0
        /// <summary>
        /// Method that returns the initial URL to be displayed in the web browser.
        /// </summary>
        /// <returns>
        /// A task that will return the initial URL.
        /// </returns>
        public override Task <Uri> GetInitialUrlAsync()
        {
            /*
             *                  mc++
             *                  OriginalString property of the Uri object should be used instead of AbsoluteUri
             *                  otherwise trailing slash is added.
             */
            string oauth_callback_uri_absolute = callbackUrl.AbsoluteUri;
            string oauth_callback_uri_original = callbackUrl.OriginalString;

            System.Diagnostics.Debug.WriteLine("GetInitialUrlAsync callbackUrl.AbsoluteUri    = " + oauth_callback_uri_absolute);
            System.Diagnostics.Debug.WriteLine("GetInitialUrlAsync callbackUrl.OriginalString = " + oauth_callback_uri_original);

            string oauth_callback_uri = oauth_callback_uri_absolute;

            var req = OAuth1.CreateRequest
                      (
                "GET",
                requestTokenUrl,
                new Dictionary <string, string>()
            {
                { "oauth_callback", oauth_callback_uri },
            },
                consumerKey,
                consumerSecret,
                ""
                      );

            if (this.HttpWebClientFrameworkType == HttpWebClientFrameworkType.WebRequest)
            {
                return(req.GetResponseAsync()
                       .ContinueWith
                       (
                           respTask =>
                {
                    var content = respTask.Result.GetResponseText();

                    var r = WebEx.FormDecode(content);

                    token = r["oauth_token"];
                    tokenSecret = r["oauth_token_secret"];

                    string paramType = authorizeUrl.AbsoluteUri.IndexOf("?") >= 0 ? "&" : "?";

                    var url = authorizeUrl.AbsoluteUri + paramType + "oauth_token=" + Uri.EscapeDataString(token);
                    return new Uri(url);
                }
                       ));
            }
            else if (this.HttpWebClientFrameworkType == HttpWebClientFrameworkType.HttpClient)
            {
                throw new NotImplementedException("HttpClient implementation!");
            }

            return(null);
        }
Esempio n. 3
0
        Task GetAccessTokenAsync()
        {
            var requestParams = new Dictionary <string, string> {
                { "oauth_token", token }
            };

            if (verifier != null)
            {
                requestParams["oauth_verifier"] = verifier;
            }

            var req = OAuth1.CreateRequest(
                "GET",
                accessTokenUrl,
                requestParams,
                consumerKey,
                consumerSecret,
                tokenSecret);

            return(req.GetResponseAsync().ContinueWith(respTask => {
                var content = respTask.Result.GetResponseText();

                var accountProperties = WebEx.FormDecode(content);
                accountProperties["oauth_consumer_key"] = consumerKey;
                accountProperties["oauth_consumer_secret"] = consumerSecret;

                if (getUsernameAsync != null)
                {
                    getUsernameAsync(accountProperties).ContinueWith(uTask => {
                        if (uTask.IsFaulted)
                        {
                            OnError(uTask.Exception);
                        }
                        else
                        {
                            OnSucceeded(uTask.Result, accountProperties);
                        }
                    });
                }
                else
                {
                    OnSucceeded("", accountProperties);
                }
            }));
        }
Esempio n. 4
0
        /// <summary>
        /// Gets OAuth authorization header.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Make sure that the parameters array contains mulitpart keys if we're dealing with a buggy
        /// OAuth implementation (such as Flickr).
        /// </para>
        /// <para>
        /// These normally shouldn't be included: http://tools.ietf.org/html/rfc5849#section-3.4.1.3.1
        /// </para>
        /// </remarks>
        protected virtual string GetAuthorizationHeader()
        {
            var ps = new Dictionary <string, string> (Parameters);

            if (includeMultipartsInSignature)
            {
                foreach (var p in Multiparts)
                {
                    if (!string.IsNullOrEmpty(p.TextData))
                    {
                        ps [p.Name] = p.TextData;
                    }
                }
            }

            return(OAuth1.GetAuthorizationHeader(
                       Method,
                       Url,
                       ps,
                       Account.Properties ["oauth_consumer_key"],
                       Account.Properties ["oauth_consumer_secret"],
                       Account.Properties ["oauth_token"],
                       Account.Properties ["oauth_token_secret"]));
        }
Esempio n. 5
0
        Task GetAccessTokenAsync()
        {
            #if DEBUG
            StringBuilder sb = new StringBuilder();
            sb.AppendLine($"OAuth1Authenticator.GetAccessTokenAsync ");
            sb.AppendLine($"        token = {token}");
            System.Diagnostics.Debug.WriteLine(sb.ToString());
            #endif

            var requestParams = new Dictionary <string, string>
            {
                { "oauth_token", token }
            };

            if (verifier != null)
            {
                requestParams["oauth_verifier"] = verifier;
                System.Diagnostics.Debug.WriteLine($"        verifier = {verifier}");
            }

            var req = OAuth1.CreateRequest(
                "GET",
                accessTokenUrl,
                requestParams,
                consumerKey,
                consumerSecret,
                tokenSecret);

            if (this.HttpWebClientFrameworkType == HttpWebClientFrameworkType.WebRequest)
            {
                return(req.GetResponseAsync().ContinueWith(respTask =>
                {
                    var content = respTask.Result.GetResponseText();

                    var accountProperties = WebEx.FormDecode(content);

                    accountProperties["oauth_consumer_key"] = consumerKey;
                    accountProperties["oauth_consumer_secret"] = consumerSecret;

                    if (getUsernameAsync != null)
                    {
                        getUsernameAsync(accountProperties).ContinueWith(uTask =>
                        {
                            if (uTask.IsFaulted)
                            {
                                OnError(uTask.Exception);
                            }
                            else
                            {
                                OnSucceeded(uTask.Result, accountProperties);
                            }
                        });
                    }
                    else
                    {
                        OnSucceeded("", accountProperties);
                    }
                }));
            }
            else if (this.HttpWebClientFrameworkType == HttpWebClientFrameworkType.HttpClient)
            {
                throw new NotImplementedException("HttpClient implementation!");
            }

            return(null);
        }