2

H!I am having a very hard time with Yahoo Oauth right now.

So here's the problem, I am using scribe 3.1.5 and followed Yahoo's documentations(apparently they use Oauth1.0), I've been able to get the request token, then trade for the access token with the verifier. The problem emerges when I try to get user's GUID from URL http://social.yahooapis.com/v1/me/guid?format=json with the access token.

now, what's interesting is that, yahoo would sometimes give me the GUID back, and sometimes give me a "invalid signature" error. Sometimes I get 5 invalid signatures in a row, sometimes I get 15 successful calls in a row, most of the time it is like 40% invalid signatures and 60% success. What is even weirder is that sometimes I get a success when fetching GUID, but when i try to fetch user's profile IMMEDIATELY after the success with the identical access token and GUID, it gives me an invalid sigature...(wtf)

so here's the code I use:

Redirecting User:

    Token requestToken = yahooService.getRequestToken();
    getSession().setAttribute("yahooRequestToken", requestToken);
    String authenticationUrl = yahooService.getAuthorizationUrl(requestToken);
    redirect(authenticationUrl);

Getting callback:

@GET @Path("/oauthcallback/yahoo")
public Response yahooCallback(@QueryParam("oauth_token") String oAuthToken, @QueryParam("oauth_verifier") String oAuthVerifier) {

    Token requestToken = (Token)getSession().getAttribute("yahooRequestToken");
    Token accessToken = yahooService.getAccessToken(requestToken, oAuthVerifier);


        UserProfile user = userService.findUserById(getUserId());
        try{
            //TODO occasioanlly yahoo returns invalid_signature, this is inconsistent and I have no idea why

            String guid = yahooService.getGuid(accessToken);
            String email = yahooService.getUserEmail(guid, accessToken);

            .....

YahooService::Getting Access Token:

[the service object is protected final OAuthService service; in parent class]

@Override
public Token getAccessToken(Token requestToken, String oAuthVerifier) {
    Verifier verifier = new Verifier(oAuthVerifier);
    return service.getAccessToken(requestToken, verifier);
}

YahooService::Getting GUID:

@Override
public String getGuid(Token accessToken){
    OAuthRequest requestA = new OAuthRequest(Verb.GET, GET_YAHOO);
    service.signRequest(accessToken, requestA);
    Response responseA = requestA.send();

    JsonParser parser = new JsonParser();
    //sometimes the response body is a invalid signature error message
    JsonObject json = (JsonObject)parser.parse(responseA.getBody());

    return json.getAsJsonObject("guid").get("value").getAsString();
}

YahooService::Getting User Email:

@Override
public String getUserEmail(String guid, Token accessToken) {
    String profileCallUrl = GET_YAHOO_PROFILE.replaceAll("GUID", guid);
    OAuthRequest requestB = new OAuthRequest(Verb.GET, profileCallUrl);
    service.signRequest(accessToken, requestB);
    requestB.addHeader("realm", "yahooapis.com");
    Response responseB = requestB.send();

    JsonParser parser = new JsonParser();
    //sometimes the response body is a invalid signature error message
    JsonObject jsonProfile = (JsonObject)parser.parse(responseB.getBody());
    ...processing code, error free

}

I know YahooAPI class in Scribe 3.1.5 in maven distribution is like 2 years old, but I doubt it would lead to such inconsistent behavior. Scribe's built in support for Google and Live oauth is basically useless, unfortunately, unlike Google or Hotmail which both have awesome doc so that I could basically figure out everything myself, Yahoo's doc stops at getting the access token, I can not find useful explanation on why I would get an invalid signature SOMETIMES with my access token

Please help! Thanks in advance

4

2 回答 2

0

无需向 yahoo 询问 GUID,因为 yahoo 在为您提供访问令牌时会返回当前登录用户的 GUID,因此如果您有访问令牌,则响应中也有 GUID。 参考这个

于 2014-03-10T11:52:21.493 回答
0

它看起来像雅虎问题,几天以来我有同样的错误消息:

http://developer.yahoo.com/forum/OAuth-General-Discussion-YDN-SDKs/signature-invalid-when-making-calls-to-the/1385735171123-8a38d8cf-815b-43ac-9d77-5bd2f2f60796

于 2013-12-03T08:47:18.203 回答