Google-signin: Android AccessToken from SignIn

Created on 26 Mar 2017  路  10Comments  路  Source: react-native-google-signin/google-signin

Hi,

I can't get an accessToken on android from a signIn().
I got the following response object :

{
email
id
idToken
name
photo
scopes
serverAuthCode
}

but no accessToken.

On iOS I got :

{
accessToken
serverAuthCode
accessTokenExpirationDate
id
familyName
email
givenName
photo
name
idToken
}

Which seems normal according to the doc (not very convenient but w/e) BUT :

I tried to use the GoogleSignin.getAccessToken() function with my android device but the app crashes and says that the function doesn't exist.

 TypeError: _reactNativeGoogleSignin.GoogleSignin.getAccessToken is not a function
    at googleSignIn

Thank you !

Edit : I just saw @Elektro1776 opened a similar issue but closed it on his own (https://github.com/devfd/react-native-google-signin/issues/211)

Edit2 : Just saw the issue was fixed on https://github.com/devfd/react-native-google-signin/commit/25b197559509ae267168ba9013cc23e6e2598c7c but the changes are not there after installing the plugin

馃挜 Bug

Most helpful comment

Same problem, ended up using something like this instead of hacking the module code:

import { Platform, NativeModules } from 'react-native'

const { RNGoogleSignin } = NativeModules;


...


GoogleSignin.signIn()
.then((user) => {

  if(Platform.OS.toLowerCase() === "ios"){

    // user.accessToken

  }else{

    RNGoogleSignin.getAccessToken(user).then((token) => {

        // token

    })
    .catch(err => {
      console.log('Could not get google access token: '+err);
    });

  }


})
.catch((err) => {
  console.log('Could not auth with google: ', err);
})
.done();

All 10 comments

I have same issue. I have tried this commit so I can get accessToken from user object. But lock like some issue security here. Object user become nomal object and easy to access and change.

Before:

{
id: [getter/setter],
scope: [getter/setter],
...
}

Affer:

{
id: '123...',
scope: [
[getter/setter],
[getter/setter]
],
accessToken: 'ya29.GlsbBImkd...',
...
}

Same problem, ended up using something like this instead of hacking the module code:

import { Platform, NativeModules } from 'react-native'

const { RNGoogleSignin } = NativeModules;


...


GoogleSignin.signIn()
.then((user) => {

  if(Platform.OS.toLowerCase() === "ios"){

    // user.accessToken

  }else{

    RNGoogleSignin.getAccessToken(user).then((token) => {

        // token

    })
    .catch(err => {
      console.log('Could not get google access token: '+err);
    });

  }


})
.catch((err) => {
  console.log('Could not auth with google: ', err);
})
.done();

ya. same issue i was faced but solved by using this.
please take a look to link given below:
http://stackoverflow.com/questions/29765905/how-to-get-the-access-token-from-google-sign-in-javascript-sdk/43201100#43201100

Is this library not being actively maintained? https://github.com/devfd/react-native-google-signin/pull/174 fixes the issue referenced here. Its been several months since that PR was created.

@jordanfloyd I commented on the PR, it needs to resolve its conflicts before being merged.

@Kerumen what about https://github.com/devfd/react-native-google-signin/commit/25b197559509ae267168ba9013cc23e6e2598c7c then? This also fixes the issue referenced here. Timeline for an updated release? 0.9.0 is unusable as is because there is no way to retrieve the access token on android through the JS module. I have to pull in the native module myself.

@jordanfloyd I've just released 0.10.0

@Kerumen awesome, thank you!

This issue is because Google Play Services is not up to date. Update it on the device and you should receive the token.

Yup this is fixed on the latest version. Please check out our example app.

Was this page helpful?
0 / 5 - 0 ratings