How to set callback URL for Google OAuth?

user1625971 picture user1625971 · Apr 30, 2013 · Viewed 28.2k times · Source

I am using Google OAuth to authenticate the user in my GAE application. After the user clicks on "Grant Access", I want to return to my application. I tried setting the callback URL, but instead of being called independently, it gets appended to the current URL in the browser, and thus shows as an invalid URL.

Here is my code:

 OAuthGetTemporaryToken requestToken = new OAuthGetTemporaryToken(REQUEST_TOKEN_URL);
        requestToken.consumerKey = CONSUMER_KEY;
        requestToken.transport = TRANSPORT;
        requestToken.signer = signer;
        requestToken.callback="www.mail.yahoo.com";

        OAuthCredentialsResponse requestTokenResponse = requestToken.execute();

        // updates signer's token shared secret
        signer.tokenSharedSecret = requestTokenResponse.tokenSecret;

        OAuthAuthorizeTemporaryTokenUrl authorizeUrl = new OAuthAuthorizeTemporaryTokenUrl(AUTHORIZE_URL);
        authorizeUrl.temporaryToken = requestTokenResponse.token;

This line sends it to the Google OAuth page.

resp.sendRedirect(authorizeUrl.build());

I have set the callback parameter as shown above, but it's not working. Please help! Thanks in advance.

Answer

Tim Bray picture Tim Bray · May 2, 2013

This is OAuth1 stuff, which is deprecated. Try using OAuth 2.0 instead. Start at https://developers.google.com/accounts/docs/OAuth2