morgs32
morgs32

Reputation: 1459

Can't hit Google plus api after oauth with Firebase

2 hours trying to get this to work and I can't. Firebase authenticates the user just fine, but then it can't fetch anything from the Google Plus API. The error you will get:

{
    domain: "global"
    location: "Authorization"
    locationType: "header"
    message: "Invalid Credentials"
    reason: "authError"

}

The code is this:

    Auth.$authWithOAuthPopup(provider, {
      scope: ['profile', 'email']
    }).then(function(authData) {

          console.log(authData.token);
          gapi.client.setApiKey('<APIKEY>');
          gapi.client.load('plus','v1', function(){
            var request = gapi.client.plus.people.get({
              'userId': 'me'
            });
            request.execute(function(resp) {
              console.log('Retrieved profile for:' + resp.displayName);
              debugger;
            });
          });

    }, showError);

It must have something to do with Firebase making the call on our behalf. Because this codepen, in which we do our own authentication, works fine: http://codepen.io/morgs32/pen/KVgzBw

Don't forget to set clientId and apiKey in the codepen.

If you can figure this one out you're gonna get gold on christmas.

Upvotes: 3

Views: 251

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599591

You're trying to use authData.token to access Google. But authData.token is a JWT token for accessing Firebase.

To access Google, you should use authData.google.accessToken.

Also see this page in the Firebase documentation on using the Google provider.

Upvotes: 3

Related Questions