0
votes

Been pouring over Implementing my own Google oAuth methods for three days now. Keep hitting snags. Not sure what variables are at play with the problem anymore. I need fresh eyes and proper advice. I wish Google was more specific outside of 'Invalid Token'. I can sign the request with NO token secret and i'll still get the same error. So I'm not sure if my signature is still invalid or if I have mad too many requests. I have no idea. It's absolutely frustrating.

Here is my latest attempt with code that I think should work:

I get my request token data, and store it in a database (decoded) before redirecting the user to authorize.

Token: 4/M1ZCp6Y115rBqxYz3v1Dq9bbTCrr
Secret: f39Fuyg6MwlW35w4UIKNDBag
Verifier: kZt189Tk7tTrTiodhhk_QOxX

I take all three and pass them into my method to get an access token. I discovered that I was double encoding my token, which was causing the token to be invalid. Now I am getting the usual invalid signature again. I'm not really all that sure how.

Access token method:

public function oAuthGetAccessToken($authToken, $authTokenVerifier, $authTokenSecret)
    {
        $nonce = self::generateNonce();
        $time = time();
        $url = 'https://www.google.com/accounts/OAuthGetAccessToken';

    $authParams = array(
                    'oauth_consumer_key' => 'anonymous',
                    'oauth_token' => $authToken,
                    'oauth_verifier' => $authTokenVerifier,
                    'oauth_signature_method' => 'HMAC-SHA1',
                    'oauth_timestamp' => $time,
                    'oauth_nonce' => $nonce,
                    'oauth_version' => '1.0'
                );
    $baseString = self::getBaseString('GET', $url, $authParams);

    $key = self::urlencodeRFC3986('anonymous') . '&' . self::urlencodeRFC3986($authTokenSecret);

    $signature = self::hmacsha1($key, $baseString);

    $postParams = array(
                'oauth_version' => '1.0',
                'oauth_nonce' => $nonce,
                'oauth_timestamp' => $time,
                'oauth_consumer_key' => 'anonymous',
                'oauth_token' => $authToken,
                'oauth_verifier' => $authTokenVerifier,
                'oauth_signature_method' => 'HMAC-SHA1',
                'oauth_signature' => $signature
                );

    $authHeaderString = '';
    foreach($postParams as $key => $value)
    {
        $authHeaderString .= $key .'="' . self::urlencodeRFC3986($value) . '", ';
    }

    $authHeaderString = rtrim($authHeaderString, ', ');

    $headers = array('Authorization: OAuth ' . $authHeaderString);

    $rest = new Rest();
    echo $rest->OAuthHttpGetRequest($url, $headers);
}



Base String: GET&https%3A%2F%2Fwww.google.com%2Faccounts%2FOAuthGetAccessToken&oauth_consumer_key%3Danonymous%26oauth_nonce%3Dc0c072fadcc9e9de98e00f7478cd0607%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1313087177%26oauth_token%3D4%252FM1ZCp6Y115rBqxYz3v1Dq9bbTCrr%26oauth_verifier%3DkZt189Tk7tTrTiodhhk_QOxX%26oauth_version%3D1.0
1

1 Answers

0
votes

Sadly, you were right when you were double encoding your token, and worst, you got to do it for your verifier too !

To help you in the construction of your signature, be sure to check the vimeo documentation.