我的应用中的WebAuthenticationBroker返回的数据存在一些问题。我正在连接的api使用OAuth 1.0a。我可以让Broker提取授权页面,但来自Broker的ResponseData只是包含OAuth Verifier的键值对的页面的url。所以我尝试了一个Web请求来尝试获取该数据,但最终得到405:方法不允许来自页面的错误。这是我的代码......
public async Task Authorize(string oAuthAuthorizeUrl)
{
// Start WebAuthenticationBroker
System.Uri StartUri = new Uri(oAuthAuthorizeUrl);
System.Uri EndUri = new Uri(oAuthCallBack);
WebAuthenticationResult auth = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, StartUri, EndUri);
if (auth.ResponseStatus == WebAuthenticationStatus.Success)
{
HttpClient httpClient = new HttpClient();
HttpResponseMessage response = await httpClient.GetAsync(auth.ResponseData);
HttpContent content = response.Content;
string responseText = await content.ReadAsStringAsync();
string oauth_verifier = null;
string[] keyValPairs = responseText.Split('&');
for (int i = 0; i < keyValPairs.Length; i++)
{
String[] splits = keyValPairs[i].Split('=');
switch (splits[0])
{
case "oauth_verifier":
oauth_verifier = splits[1];
break;
}
}
oAuthVerifier = oauth_verifier;
}
}
这是经纪人应该如何运作的?我假设它将使用Verifier发回数据。谢谢你的帮助。