【问题标题】:Yahoo OAuth2 get_token return error 500 (internal server error)Yahoo OAuth2 get_token 返回错误 500(内部服务器错误)
【发布时间】:2020-01-21 15:00:05
【问题描述】:

我正在关注雅虎官方文档 (https://developer.yahoo.com/oauth2/guide/openid_connect/getting_started.html)。用户使用 Yahoo 登录后,我可以成功获取授权码。我现在在第 3 步,尝试用授权码交换令牌,但 Yahoo 不断返回 http 错误 500。

要从 Yahoo 交换访问令牌的授权代码,我使用以下 RestSharp 语法:

var client = new RestClient(provider.TokenUrl);
RestRequest request = new RestRequest() { Method = Method.POST };

request.AddParameter("client_id", codeModel.clientId, ParameterType.GetOrPost);
request.AddParameter("client_secret", provider.Secret, ParameterType.GetOrPost);
request.AddParameter("code", codeModel.code, ParameterType.GetOrPost);
request.AddParameter("grant_type", "authorization_code", ParameterType.GetOrPost);
request.AddParameter("redirect_uri", codeModel.redirectUri, ParameterType.GetOrPost);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");

var response = client.Execute<TokenResponseModel>(request);

responde.data 返回以下内容: 内容:{"error":"ACCESS_TOKEN_GENERATION_FAILED","error_description":"访问令牌生成失败"} 状态码:InternalServerError

官方文档指出:“下面的请求参数是在请求正文中使用 HTTP POST 传输的。但是,您也可以在 HTTP Headers 中发送参数 client_id 和 client_secret”。

我已经尝试了这两种方法(clientid 和 secret 作为正文的一部分和作为基本授权标头)并且都返回相同的结果。

当将 clientid 和 secret 作为 Basic Authorization 标头的一部分发送时,上面的两个参数都替换为以下参数:

client.Authenticator = new RestSharp.Authenticators.HttpBasicAuthenticator(codeModel.clientId, provider.Secret);

如前所述,雅虎返回的唯一消息是“内部服务器错误”。

RestSharp 语法是否有问题可能导致此问题?任何其他想法将不胜感激。

不用说,请求的所有参数都包含他们需要的数据。

谢谢

【问题讨论】:

  • 有这方面的消息吗?

标签: c# oauth-2.0 restsharp yahoo-api


【解决方案1】:

当您在 YDN 创建应用程序配置文件时,您必须确保选择至少一项 API 权限。例如尝试“个人资料(社交目录)阅读公开”。

如果您的应用程序没有 API 权限,那么令牌生成将按照您描述的方式失败。

如果您已经创建了一个没有权限的应用程序,那么您必须将其删除并重新创建。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 2013-07-24
    • 1970-01-01
    • 1970-01-01
    • 2015-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多