Task GetAccessTokenAsync() { #if DEBUG StringBuilder sb = new StringBuilder(); sb.AppendLine($"OAuth1Authenticator.GetAccessTokenAsync "); sb.AppendLine($" token = {token}"); System.Diagnostics.Debug.WriteLine(sb.ToString()); #endif RequestParameters = new Dictionary <string, string> { { "oauth_token", token } }; if (verifier != null) { RequestParameters["oauth_verifier"] = verifier; System.Diagnostics.Debug.WriteLine($" verifier = {verifier}"); } var reqUrl = OAuth1.CreateRequestUrl ( "GET", accessTokenUrl, request_parameters, consumerKey, consumerSecret, tokenSecret ); if (this.HttpWebClientFrameworkType == HttpWebClientFrameworkType.WebRequest) { //WebResponse response = req.GetResponseAsync().Result; var client = new System.Net.Http.HttpClient(); return(client.GetStringAsync(reqUrl).ContinueWith ( respTask => { var content = respTask.Result; 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); }
/// <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(Dictionary <string, string> query_parameters = null) { /* * mc++ * OriginalString property of the Uri object should be used instead of AbsoluteUri * * otherwise trailing slash is added. * * string[] uris = new string[] * { * "http://xamarin.com/", * "http://xamarin.com", * }; * foreach (string u in uris) * { * uri = new Uri(u); * Console.WriteLine("uri.AbsoluteUri = " + uri.AbsoluteUri); * Console.WriteLine("uri.OriginalString = " + uri.OriginalString); * } * * The problem is whether to send original string to be compared with registered * redirect_url on the authorization server od "correct" url (AblsoluteUrl) with * slash */ //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_original; var reqUrl = OAuth1.CreateRequestUrl ( "GET", requestTokenUrl, new Dictionary <string, string>() { { "oauth_callback", oauth_callback_uri }, }, consumerKey, consumerSecret, "" ); if (this.HttpWebClientFrameworkType == HttpWebClientFrameworkType.WebRequest) { var client = new System.Net.Http.HttpClient(); return(client.GetStringAsync(reqUrl) .ContinueWith ( respTask => { var content = respTask.Result; 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); }