2014-02-06 65 views
1

我想实现与reddit和即时通讯运行oauth2在每一步的方式遇到问题,我使用oauth库codeigniter,但不会工作,所以我决定取消它,并尝试自己做。无法通过oauth2授权与reddit

这是授权请求,如果我没有登录reddit我得到的登录页面,如果我或登录后我得到一个错误。

https://ssl.reddit.com/api/v1/authorize?response_type=code&client_id=myclientid&scope=identity&redirect_uri=http%3A%2F%2Fmydomain.com%2Fregister

并重定向我回到这里:

mydomain.com/register?state=None &错误= INVALID_REQUEST

我找不到在reddit的OAuth的执行任何有用的文档。

回答

2

关于源代码github上的reddit's OAuth2有一点点关于reddit的来源。看起来您在初始请求中缺少state参数。

state - You can pass a value into the authorization page that will be included in the redirect back to you if the user grants access. This is useful for preventing cross-site request forgery (CSRF). By choosing (and remembering) a sufficiently random value, you can ensure that the request that comes back to your site was initiated by visiting the authorization URL you generated.

(所引用的维基信息是在state不正确的实际需要,我会更新维基不久)

+0

谢谢kemitche!似乎已完美工作,我已阅读其他地方stackoverflow Reddit的oAuth实施有点独特,有没有其他的怪癖可能会遇到? 经过Reddit成功授权后,即时通讯设法调用https://oauth.reddit.com/api/v1/me,与授权代码集,试图通过POST和GET后,我得到这个错误: 403 Forbidden 管理规则禁止的请求 – user1448020

+0

排序问题,我没有正确发送Authorization:头。对于遇到任何问题的人,我强烈建议阅读本文:http://www.reddit.com/r/redditdev/comments/197x36/using_oauth_to_send_valid_requests/c8lz57u – user1448020