对社交 API 身份验证的抄写员进行故障排除



我刚刚开始研究抄写员,以便在Twitter/Facebook等社交网络上进行身份验证。 我使用推特的例子作为参考。 但是,由于某种原因,我似乎没有从 Twitter 获得oauth_verifier(即使回调是通过服务构建器注册的 - 我在回调中使用 localhost,因为它与另一个社交 API 一起工作)。 任何有用的建议将非常受欢迎。 提前谢谢。

OAuthService service = new ServiceBuilder()
.provider(TwitterApi.class)
.apiKey(consumerKey)
.apiSecret(consumerSecret)
.callback("http://localhost/oauth/twitter")
.build();
        //get the token
        Token requestToken = service.getRequestToken();
        String authUrl = service.getAuthorizationUrl(requestToken);
        Logger.info("authurl::" + authUrl); // not getting the oauth_verifier

从scribe调试输出我更改了令牌信息):

setting oauth_callback to http://localhost/oauth/twitter
generating signature...
base string is: POST&http%3A%2F%2Fapi.twitter.com%2Foauth%2Frequest_token&oauth_callback%3Dhttp%253A%252F%252Flocalhost%252Foauth%252Ftwitter%26oauth_consumer_key%3DAAACCCV6ASDFGHJCgYBCD%26oauth_nonce%3D607134093%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1353965859%26oauth_version%3D1.0
signature is: +mSqKJIC1Q0pMEFs/gIJViF7kbg=
appended additional OAuth parameters: { oauth_callback -> http://localhost/oauth/twitter , oauth_signature -> +mSqKJIC1Q0pMEFs/gIJViF7kbg= , oauth_version -> 1.0 , oauth_nonce -> 607134093 , oauth_signature_method -> HMAC-SHA1 , oauth_consumer_key -> AAACCCV6ASDFGHJCgYBCD , oauth_timestamp -> 1353965859 }
using Http Header signature
sending request...
response status code: 200
response body: oauth_token=itJrpOP3KLeD7Ha6oy0IRr4HysFut5eAOpIlj8OmNE&oauth_token_secret=X8LmhAUpvIkfEd7t7P1lvwwobC3JJIhUabcEs0Rn5w&oauth_callback_confirmed=true
authurl::https://api.twitter.com/oauth/authorize?oauth_token=itJrpOP3KLeD7Ha6oy0IRr4HysFut5eAOpIlj8OmNE
obtaining access token from http://api.twitter.com/oauth/access_token
setting token to: Token[itJrpOP3KLeD7Ha6oy0IRr4HysFut5eAOpIlj8OmNE , X8LmhAUpvIkfEd7t7P1lvwwobC3JJIhUabcEs0Rn5w] and verifier to: org.scribe.model.Verifier@55ac8c3d
generating signature...

更新:我现在能够收到oauth_verifier。 完成测试后,我将更新这篇文章。

主要是飞行员错误。 我能够让oauth使用抄写员与Twitter一起工作。 在获得服务后,来自服务的请求令牌,然后从服务中获得授权URL(在传递请求令牌时),我能够重定向到授权URL。 到达那里后,我能够使用我的推特ID对推特进行身份验证,该ID将我重定向到创建服务时指定的回调URL。 身份验证后,我收到了可用于创建验证程序的oauth_verifier,然后使用验证程序和请求令牌从服务接收访问令牌。 然后发出并签署了oauth请求,这导致了Twitter的响应,其中包含用户详细信息。 工作。 希望对您有所帮助。

最新更新