Yahoo OAuth 使用 WebAuthenticationBroker 返回错误

Yahoo OAuth returning error using WebAuthenticationBroker

我试图从我的 UWP 应用程序使用 yahoo 登录。

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);

正在正确显示登录 但登录后显示错误页面

如果我们按下关闭键,它将引导我进入雅虎主页,而不是征求用户同意。有人知道为什么会这样吗?

您的授权有两个问题URL。

首先,你的URL中的client_id不对。通常,client_id的结尾是--,以Authorization Code Flow for Server-side App中的client_id为例,就是

dj0yJmk9ak5IZ2x5WmNsaHp6JmQ9WVdrOVNqQkJUMnRYTjJrbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1hYQ--

所以我认为你的client_id错了。

第二个问题是你的redirect_uri,redirect_uri应该匹配你的回调域在您的应用中设置。

Please specify the domain to which your application will be returning after successfully authenticating. Yahoo OAuth flow will redirect users to a URL only on this domain (or its sub-domain) after they authorize access to their private data.

所以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()}";
    }
}

登录后,您会看到如下内容:

The second problem is your redirect_uri, the redirect_uri should match the Callback Domain you've set in your app.

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