Oauth 2.0 无法从signed_request“code”获取访问令牌价值
我正在迁移到 Oauth 2.0。我当前的网站使用 JS SDK,有一个 fb 登录按钮,然后我访问 Graph 来获取用户详细信息。
我在获取访问令牌以从 Graph 获取此数据时遇到问题。
一个问题可能是 JS SDK 对话框不会将我重定向到它所说的 URL,即带有 ?code=XXXXXXX 的 URL,然后我可以使用它来获取访问令牌。
所以我查看了 php SDK(我使用的是 ASP)来了解它是如何实现的。我已经解析了 cookie 中的签名请求值,获取了“code”参数中的值以添加到令牌 URL,但我无法获取访问令牌。这些是我正在使用的值:
解析的signed_request数据:
{"algorithm":"HMAC-SHA256","code":"2.AQCovUOFCduELbna.3600.1323900000.1-773555243|Y_cW4riF4K7el_9a4oVNjL0qvZc","issued_at":1323895617,"user_id":"XXXXXXXXXX"}
Token URL: https://graph.facebook.com/oauth/access_token?
client_id=XXXXXXXX&
redirect_uri=XXXXXXXX&
client_secret=XXXXXX&
code=2.AQCovUOFCduELbna.3600.1323900000.1-773555243|Y_cW4riF4K7el_9a4oVNjL0qvZc
这是响应:
{"error":{"message":"Error validating verification code.","type":"OAuthException"}}
代码值的格式是否正确?关于出了什么问题有什么想法吗?
I'm migrating to Oauth 2.0. My current site uses JS SDK, has a fb-login button, then I'm accessing Graph to get the users details.
I'm having problems getting an access token to get this data from Graph.
One problem could be that JS SDK dialog doesn't redirect my to the URL it says it should i.e. the one with ?code=XXXXXXX that I can then use to get an access token.
So I've looked at the php SDK (I'm using ASP) to see how it does it. I've parsed the signed-request value in the cookie, got the value in the 'code' param to add to the token URL but I can't get an access token. These are the values I'm using:
Parsed signed_request data:
{"algorithm":"HMAC-SHA256","code":"2.AQCovUOFCduELbna.3600.1323900000.1-773555243|Y_cW4riF4K7el_9a4oVNjL0qvZc","issued_at":1323895617,"user_id":"XXXXXXXXXX"}
Token URL: https://graph.facebook.com/oauth/access_token?
client_id=XXXXXXXX&
redirect_uri=XXXXXXXX&
client_secret=XXXXXX&
code=2.AQCovUOFCduELbna.3600.1323900000.1-773555243|Y_cW4riF4K7el_9a4oVNjL0qvZc
This is the response:
{"error":{"message":"Error validating verification code.","type":"OAuthException"}}
Does the code value appear to be in the correct format? Any ideas as to what's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里完全相同的问题...
解决方案:如果从 cookie 有效负载中提取代码,请将参数redirect_uri留空
尝试
令牌 URL:https://graph.facebook.com/oauth/access_token?client_id=XXXXXXXX&redirect_uri=&cl ient_secret=XXXXXX&code=2.AQCovUOFCduELbna.3600.1323900000.1-773555243|Y_cW4riF4K7el_9a4oVNjL0qvZc
为我工作!
exact same problem here...
solution: if code is extracted from cookie payload, leave parameter redirect_uri empty
try
Token URL: https://graph.facebook.com/oauth/access_token?client_id=XXXXXXXX&redirect_uri=&client_secret=XXXXXX&code=2.AQCovUOFCduELbna.3600.1323900000.1-773555243|Y_cW4riF4K7el_9a4oVNjL0qvZc
worked for me!