Let me explain my scenario first. I'm using Scribe to connect via Oauth to an API not directly supported by Scribe. That said, the server I'm connecting to requires to enter a 4 digit number as the final step for being able to create the accessToken.

While this is working great, when the user inputs the 4 digits wrong, the app stays running forever, no error or excepction is thrown (to my understanding). This is the code I'm using:

//verifierString has the 4-digit number
verifier = new Verifier(verifierString);
Logger.debug("Trading the Request Token for an Access Token...");
accessToken = service.getAccessToken(requestToken, verifier);

App stays in getAccessToken forever. I wonder if there is a way to control this, since it's very possible that users input the 4 digit wrong. I've checked the code for getAccessToken, Oauth 1.0 since it's the one I'm using:

public Token getAccessToken(Token requestToken, Verifier verifier)
{
    config.log("obtaining access token from " + api.getAccessTokenEndpoint());
    OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
    request.addOAuthParameter(OAuthConstants.TOKEN, requestToken.getToken());
    request.addOAuthParameter(OAuthConstants.VERIFIER, verifier.getValue());
    config.log("setting token to: " + requestToken + " and verifier to: " + verifier);
    addOAuthParams(request, requestToken);
    appendSignature(request);
    Response response = request.send();
    return api.getAccessTokenExtractor().extract(response.getBody());
}

It only seems that send() throws a RuntimeException, but not sure if catching it from my code is the right way to do it....any suggestions?

Thanks ! Alex

有帮助吗?

解决方案

If you try any of the scribe examples you'll see that entering a wrong verifier code results in an immediate OAuthException (note that it is an OAuthException though, as you correctly state it inherits from RuntimeException, this is by design since I'm 100% against checked exceptions).

The problem is on the server side, for what you say it keeps the http connection open for long or possibly even forever, until the default connection timeout happens.

Perhaps if you ask in the Api forums you'll get a better response, also using scribe's debug mode (new since 1.3.0) helps you diagnose most problems.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top