c# - Yahoo OAuth2 get_token 返回错误 500(内部服务器错误)
问题描述
我正在关注雅虎官方文档(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 返回以下内容: content: {"error":"ACCESS_TOKEN_GENERATION_FAILED","error_description":"Access token generation failed"} StatusCode: InternalServerError
官方文档指出:“下面的请求参数是在请求正文中使用 HTTP POST 传输的。但是,您也可以在 HTTP 标头中发送参数 client_id 和 client_secret ”。
我已经尝试了这两种方法(clientid 和 secret 作为正文的一部分和作为基本授权标头)并且都返回相同的结果。
当发送 clientid 和 secret 作为 Basic Authorization 标头的一部分时,上面的两个参数都替换为以下参数:
client.Authenticator = new RestSharp.Authenticators.HttpBasicAuthenticator(codeModel.clientId, provider.Secret);
如前所述,雅虎返回的唯一消息是“内部服务器错误”。
RestSharp 语法是否有问题可能导致这种情况?任何其他想法将不胜感激。
不用说,请求的所有参数都包含他们需要的数据。
谢谢
解决方案
当您在 YDN 创建应用程序配置文件时,您必须确保选择至少一项 API 权限。例如尝试“个人资料(社交目录)阅读公开”。
如果您的应用程序没有 API 权限,那么令牌生成将按照您描述的方式失败。
如果您已经创建了一个没有权限的应用程序,那么您将不得不删除它并重新创建它。
推荐阅读
- java - 在实践中如何理解递归的原理?
- java - Android BindingConversion 在 kotlin 中不起作用?
- reactjs - 减速器不能改变返回结果
- python - 无法从 s3 下载文件,因为垃圾字符串附加到密钥名称
- bash - 如果从 bash 脚本执行,则乱码邮件命令
- wordpress - htaccess wordpress中的重定向问题
- javascript - 如何使用 Python 拆分 Javascript 代码(bs4)
- azure-active-directory - AADSTS700016:在目录“some_another_id”中找不到标识符为“some_id”的应用程序
- python - 我正在运行一个程序通过两个套接字发送图片,我没有错误,但程序卡住了
- javascript - 单击laravel中的下拉标签后隐藏回声