将OAuth验证程序值取为null

时间:2016-10-17 13:13:21

标签: oauth

我正在尝试获取我需要OAuth验证程序的访问令牌。我正在使用TokenSecretVerifierHolder类来获取令牌,令牌秘密和验证者,但我只获得令牌,令牌秘密的值,但验证者值是a null。这是我的代码。

public TokenSecretVerifierHolder getRequestToken() {
        try {
            OAuthAccessor accessor = getAccessor();
            OAuthClient oAuthClient = new OAuthClient(new HttpClient4());
            List<OAuth.Parameter> callBack;
            if ((this.callback == null) || ("".equals(this.callback))) {
                callBack = Collections.emptyList();
            } else {
                callBack = ImmutableList.of(new OAuth.Parameter("oauth_callback", this.callback));
            }
            OAuthMessage message = oAuthClient.getRequestTokenResponse(accessor, "POST", callBack);
            TokenSecretVerifierHolder tokenSecretVerifier = new TokenSecretVerifierHolder();
            tokenSecretVerifier.token = accessor.requestToken;
            tokenSecretVerifier.secret = accessor.tokenSecret;
            tokenSecretVerifier.verifier = message.getParameter("oauth_verifier");
            return tokenSecretVerifier;
        } catch (Exception e) {
            throw new RuntimeException("Failed to obtain request token", e);
        }
    }

private String getAccessToken() {

    AtlassianOAuthClientRequest jiraoAuthClient = getJiraOAuthClient();
    TokenSecretVerifierHolder requestToken = jiraoAuthClient.getRequestToken();
    String authorizeUrl = jiraoAuthClient.getAuthorizeUrlForToken(requestToken.token);

    String token = requestToken.token;
    String tokenSecret = requestToken.secret;
    String verifier = requestToken.verifier;

    String accessToken = jiraoAuthClient.swapRequestTokenForAccessToken(token, tokenSecret, verifier);
    String verifier = requestToken.verifier;
    System.out.println("Access token is : " + accessToken);
    return accessToken;
}

在检索令牌,令牌密钥和验证者的值后,我传递它以获取访问令牌值。我想要的是,在我确认authorizeUrl后,它应该返回Oauth验证器的值。在我的情况下,它返回为null。

1 个答案:

答案 0 :(得分:0)

在HTTP重定向到回调网址时,会向您返回验证程序所需的值 - 重定向会发生在https://consumer.url/?oauth_token=TOKEN&oauth_verifier=VERIFIER之类的网址上,因此oauth_verifier参数的值就是您所需的。