Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Twitter OAuth was failing because HttpWebRequest does not support TLS v1.2 #417

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions source/Core/Xamarin.Auth.Common.LinkSource/OAuth1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
using System.Net;
using System.Globalization;
using Xamarin.Utilities;

#if ! AZURE_MOBILE_SERVICES
using System.Net.Http;

#if !AZURE_MOBILE_SERVICES
namespace Xamarin.Auth
#else
namespace Xamarin.Auth._MobileServices
Expand Down Expand Up @@ -201,6 +202,15 @@ public static HttpWebRequest CreateRequest(string method, Uri uri, IDictionary<s
req.Method = method;

return req;
}

public static string CreateRequestUrl(string method, Uri uri, IDictionary<string, string> parameters, string consumerKey, string consumerSecret, string tokenSecret)
{
Dictionary<string, string> ps = MixInOAuthParameters(method, uri, parameters, consumerKey, consumerSecret, tokenSecret);

string realUrl = uri.AbsoluteUri + "?" + ps.FormEncode();

return realUrl;
}

/// <summary>
Expand Down
33 changes: 17 additions & 16 deletions source/Core/Xamarin.Auth.Common.LinkSource/OAuth1Authenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ The problem is whether to send original string to be compared with registered

string oauth_callback_uri = oauth_callback_uri_original;

var req = OAuth1.CreateRequest
var reqUrl = OAuth1.CreateRequestUrl
(
"GET",
requestTokenUrl,
Expand All @@ -213,13 +213,14 @@ The problem is whether to send original string to be compared with registered

if (this.HttpWebClientFrameworkType == HttpWebClientFrameworkType.WebRequest)
{
return req.GetResponseAsync()
var client = new System.Net.Http.HttpClient();
return client.GetStringAsync(reqUrl)
.ContinueWith
(
respTask =>
{

var content = respTask.Result.GetResponseText();
var content = respTask.Result;

var r = WebEx.FormDecode(content);

Expand Down Expand Up @@ -318,26 +319,26 @@ Task GetAccessTokenAsync()
System.Diagnostics.Debug.WriteLine($" verifier = {verifier}");
}

// WebRequest Replaced with HttpRequest for .net Standard 1.1
HttpWebRequest req = OAuth1.CreateRequest
(
"GET",
accessTokenUrl,
request_parameters,
consumerKey,
consumerSecret,
tokenSecret
);
var reqUrl = OAuth1.CreateRequestUrl
(
"GET",
accessTokenUrl,
request_parameters,
consumerKey,
consumerSecret,
tokenSecret
);

if (this.HttpWebClientFrameworkType == HttpWebClientFrameworkType.WebRequest)
{
WebResponse response = req.GetResponseAsync().Result;
//WebResponse response = req.GetResponseAsync().Result;

return req.GetResponseAsync().ContinueWith
var client = new System.Net.Http.HttpClient();
return client.GetStringAsync(reqUrl).ContinueWith
(
respTask =>
{
var content = respTask.Result.GetResponseText();
var content = respTask.Result;

var accountProperties = WebEx.FormDecode(content);

Expand Down
Loading