您的授权网址存在两个问题。
首先,您的URL中的client_id是不正确的。通常情况下,client_id
是结束了-,在Authorization Code Flow for Server-side App例如使用client_id
,它是
dj0yJmk9ak5IZ2x5WmNsaHp6JmQ9WVdrOVNqQkJUMnRYTjJrbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1hYQ--
所以我觉得你client_id
的错误。
第二个问题是您REDIRECT_URI,则REDIRECT_URI应该匹配回调域你已经在你的应用程序设置。
请指定您的应用程序在成功验证后返回的域。雅虎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()}";
}
}
并登录,您会看到类似后: