How to get idToken from expo-auth-session Google.useAuthRequest() ?

expo-auth-session Google.useAuthRequest() returns google’s idToken value as undefined.

request:

 const [request, response, promptAsync] = Google.useAuthRequest({
    expoClientId: 'GOOGLE_GUID.apps.googleusercontent.com',
    androidClientId:  'GOOGLE_GUID.apps.googleusercontent.com',
  })

response:

"authentication": TokenResponse {
    "accessToken": "received correct access token",
    "expiresIn": "3599",
    **"idToken": undefined,**
    "issuedAt": 1614595369,
    "refreshToken": undefined,
    "scope": "email profile https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email openid",
    "tokenType": "Bearer",
  },

Is there a way to retrieve the idToken from Google ?

@dorapax, try changing your useAuthRequest by useIdTokenAuthRequest… It worked for me!

I tried below and it worked for me.

const [requestIdToken, responseIdToken, promptAsyncIdToken] =
    Google.useAuthRequest({
      **responseType: 'id_token',**
      androidClientId: GOOGLE_CLIENT_ID_ANDROID,
      iosClientId: GOOGLE_CLIENT_ID_IOS,
      expoClientId: GOOGLE_CLIENT_WEB_EXPO,
      scopes: ['profile', 'email'],
    })
1 Like

@luiz.lemberg are you using firebase for authentication ? As far as I know useIdTokenAuthRequest is working only for firebase.

@dorapax, no, i’m not using firebase for authentication, I’ve just setup my API credentials on google developer console

Has anyone solved the issue because , i am facing the same issue - getting idToken and refreshToken undefined on useAuthRequest response. I want to get idToken and accessToken with a request

Same issue here, previously we were using Google.logInAsync() from ‘expo-google-app-auth’ which provided both an accessToken and an idToken. Using Google.useAuthRequest() from ‘expo-auth-session/providers/google’ is providing one or the other depending on the responseType used in the config in both Expo Go and Expo Web.

Does anyone know how I can get both from Google.useAuthRequest or another method to get an accessToken from an idToken (or the other way around). I see that AuthSession.exchangeCodeAsync() can be used to ‘Exchange an authorization code for an access token that can be used to get data from the provider.’ but I can’t get it working.