2016-04-22 104 views
0

我想从我的UWP应用程序使用雅虎登录。雅虎OAuth返回错误使用WebAuthenticationBroker

StartUri是https://api.login.yahoo.com/oauth2/request_auth?response_type=code&scope=openid&client_id=dj0yJmk9TDNtd2MxeGNMT1pUJmQ9WVdrOVQwVlNVbFpQTkdjbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD05Mw&redirect_uri=http://localhost:8080

EndUri是http://localhost:8080/

WebAuthenticationResult WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(
              WebAuthenticationOptions.None, 
              StartUri, 
              EndUri); 

它正确显示登录 但在它的标志后显示错误页面 enter image description here

如果我们贴近就会直接我到雅虎主页而不是询问用户的同意。有人知道为什么会发生这种情况

回答

1

您的授权网址存在两个问题。

首先,您的URL中的client_id是不正确的。通常情况下,client_id是结束了-,在Authorization Code Flow for Server-side App例如使用client_id,它是

dj0yJmk9ak5IZ2x5WmNsaHp6JmQ9WVdrOVNqQkJUMnRYTjJrbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1hYQ--

所以我觉得你client_id的错误。

第二个问题是您REDIRECT_URI,则REDIRECT_URI应该匹配回调域你已经在你的应用程序设置。 enter image description here

请指定您的应用程序在成功验证后返回的域。雅虎OAuth流程将在授权访问其私有数据后,将用户重定向到仅在此域(或其子域)上的URL。

因此redirect_uri需要是一个域而http://localhost:8080不符合此要求。在我的测试中,我只是用localhost.com例如:

public async Task<string> AuthorizeWithYahoo() 
{ 
    var clientId = "<My client id>"; 

    var StartUri = new Uri($"https://api.login.yahoo.com/oauth2/request_auth?client_id={clientId}&response_type=code&redirect_uri=http://localhost.com"); 
    var EndUri = new Uri("http://localhost.com"); 

    WebAuthenticationResult WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, 
StartUri, EndUri); 
    if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success) 
    { 
     var responseData = WebAuthenticationResult.ResponseData; 

     return responseData; 
    } 
    else if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp) 
    { 
     return $"HTTP Error returned by AuthenticateAsync() : {WebAuthenticationResult.ResponseErrorDetail.ToString()}"; 
    } 
    else 
    { 
     return $"Error returned by AuthenticateAsync() : {WebAuthenticationResult.ResponseStatus.ToString()}"; 
    } 
} 

并登录,您会看到类似后: enter image description here

0

的第二个问题是你REDIRECT_URI,该REDIRECT_URI应该匹配回调域你已经在你的应用程序中设置。

重定向URL,可以在我的本地主机上设置为Visual Studio开发人员?