How can I access the Google accessToken and idToken with expo-google-signIn?

Hey guys, this might sound like a pretty mundane question, but how would I access the idToken and accessToken returned with the expo-google-sign-in library?

When I console.log(user) it gives me a null accessToken and idToken, but I notice that these are in fact declared within the classes of this library. Do I need to add a specific scope or parameter to my request for this?

Any help would be appreciated.


1 Like

Hmm…they should be available under this class. Not sure why you’d be getting null for both, unless something is going wrong in the authentication.

Does signInAsync return with type: 'success'?

When I log user data returned when type===‘success’, there is an accesstoken, but the idToken shows as null. Refresh token, token expiry are all null as well.

Am I doing something wrong?

Any clientID?

I pass in a clientID as a prop to initAsync if that’s what you mean

I’m wondering the same thing. Am I right in saying there’s no need to even pass the clientId in for Android? I’m trying to get this to work so that I can pass the idToken and accessToken to sign in to Firebase. I also get a “success” but idToken is null.

Try adding some scopes maybe? It’s just really weird. OAuth should be returning clientID but it’s not. Maybe something’s wrong with the module

@davidli3100, have you got it working now?

Nope, still returns as null for me. I’m going to try and make a PR to the expo package

It’s still not returning an idToken even after I made a new firebase project and added a new client ID. Am I doing something wrong?

For anyone who finds his thread. You must access the tokens via user.auth.idToken and user.auth.accessToken:

// Block 1
try {
  await GoogleSignIn.initAsync();
} catch ({ message }) {
  alert('GoogleSignIn.initAsync(): ' + message);

// Block 2
try {
  await GoogleSignIn.askForPlayServicesAsync();
  const { type, user } = await GoogleSignIn.signInAsync();
  if (type === 'success') {
  } else {
} catch (error) {
  alert('login: Error:\n' + error.message + '\n' + JSON.stringify(error));

See accessToken and idToken are undefined when calling GoogleSignIn.signInAsync() · Issue #4762 · expo/expo · GitHub

Is your idToken returned as null?

Hi @davidli3100, nope, got it working now finally. See the github issue for the latest code.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.