处理您的 OAuth 请求时出错:无效的 oauth_verifier 参数 [英] Error processing your OAuth request: Invalid oauth_verifier parameter

查看:676
本文介绍了处理您的 OAuth 请求时出错:无效的 oauth_verifier 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注 https://dev.twitter.com/web/sign-在/实现以在我的应用程序中使用 twitter 实现 OAuth 注册.

I'm following https://dev.twitter.com/web/sign-in/implementing to implement OAuth signup in my application with twitter.

这是向用户显示来自 twitter 的授权此应用程序对话框的服务:

Here is the service which presents the User the authorize this app dialog from twitter:

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/twitter")
public Response redirectToTwitter() {
    Configuration cfg = new ConfigurationBuilder().setOAuthConsumerKey(TWITTER_CONSUMER_KEY)
                                                  .setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET)
                                                  .build();
    Twitter twitter = new TwitterFactory(cfg).getInstance();
    String callbackURL = "https://localhost:9090/app/ui/oauth/twitter";
    try {
        RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL);
        String authURL = requestToken.getAuthenticationURL();
        return Response.seeOther(URI.create(authURL)).build();
    } catch (TwitterException e) {
        LOG.error(e.getMessage(), e);
        return ErrorResponse.create(e.getMessage());
    }
}

这有效并将浏览器重定向到要求授权的 Twitter 页面.当我单击登录"时,会出现重定向对话框,将我重定向到类似以下内容的 URL:

This works and redirects the browser to the Twitter Page which asks for authorization. When I click Sign In the redirect dialog appears which redirect me to a URL something like:

https://localhost:9090/app/ui/oauth/twitter?oauth_token=6oWQxQAAAAAAgyORAAABTtmVVFM&oauth_verifier=GMX5SiqnkFfUu2MgirTDJnkJmtHZXn5H

@GET
@Path("/twitter")
public SocialSignInView login(@QueryParam("oauth_token") String token,
                              @QueryParam("oauth_verifier") String verifier) {
    Configuration cfg = new ConfigurationBuilder().setOAuthConsumerKey(TWITTER_CONSUMER_KEY)
            .setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET)
            .setOAuthAccessToken(token)
            .build();
    Twitter twitter = new TwitterFactory(cfg).getInstance();
    String callbackURL = "https://localhost:9090/app/ui/oauth/twitter";
    String screenName = null;
    try {
        RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL);
        AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier);
        screenName = accessToken.getScreenName();
    } catch (TwitterException e) {
        LOG.error(e.getMessage(), e);
    }

    return new SocialSignInView(screenName);
}

此时我拥有所有必需的参数 - 根据 https://dev.twitter.com/web/sign-in/implementing 3. - 检索访问令牌,但是,我不知道如何将 RequestToken 对象从现有的 oauth_token 组合在一起.

At this point I have all the required parameters - according to https://dev.twitter.com/web/sign-in/implementing 3. - to retrieve an access token, however, I don't know how to put together a RequestToken object form the existing oauth_token.

使用上面的代码,我收到以下错误:

With the code above I'm receiving the following error:

ERROR 13:33:06.478 [dw-165 - GET /app/ui/oauth/twitter?oauth_token=6oWQxQAAAAAAgyORAAABTtmVVFM&oauth_verifier=GMX5SiqnkFfUu2MgirTDJnkJmtHZXn5H] r.d.d.resources.SocialSignInCompleteResource: 401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
Error processing your OAuth request: Invalid oauth_verifier parameter

推荐答案

当你请求 https://api.twitter.com/oauth/access_token.您作为获取参数获得的这些 oauth_verifier.所以只需在标题中设置 oauth_verifier=params[:oauth_verifier].

You need to set oauth_verifier in the header when you are requesting https://api.twitter.com/oauth/access_token. These oauth_verifier you are getting as get parameters. So just set oauth_verifier=params[:oauth_verifier] in header.

这篇关于处理您的 OAuth 请求时出错:无效的 oauth_verifier 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆