Google-signin: [Android] accessToken not returned

Created on 27 Oct 2016  ·  12Comments  ·  Source: react-native-google-signin/google-signin

I'm running into the issue of not getting an accessToken attached to the returned user object in Android using react-native: 0.35 and react-native-google-signin: 0.8.1

At https://github.com/devfd/react-native-google-signin/blob/v0.8.1/GoogleSignin.android.js#L77,
the access token is not being returned with the user object. I'm assuming the return value from RNGoogleSignInSilentSuccess is not mutable. If I do a JSON stringify/parse of user, the accessToken is passed properly as a property of this._user. Is there something I'm missing about how to get the accessToken in Android?

  currentUserAsync() {
    return new Promise((resolve, reject) => {
      const sucessCb = DeviceEventEmitter.addListener('RNGoogleSignInSilentSuccess', (user) => {
        this._user = user;

        RNGoogleSignin.getAccessToken(user).then((token) => {
          this._user.accessToken = token;
          console.log(this._user);                // will show no access token!
          this._removeListeners(sucessCb, errorCb);
          resolve(this._user);
        })
💥 Bug ❌ Invalid

Most helpful comment

I have the same issue with the same conclusion. I tried to look in React Native where the object is created but I can't find it.
For now I got this fix:

RNGoogleSignin.getAccessToken(user).then((token) => {
  this._user.accessToken = token;
  this._removeListeners(sucessCb, errorCb);
  resolve({...this._user, accessToken: token});
})

but not sure how viable this is.

All 12 comments

same issue, it seems to be broken on 0.8.1
also the doc talks about "- getAccessToken (Android Only)" but this function doesn't exist it seems

I have the same issue with the same conclusion. I tried to look in React Native where the object is created but I can't find it.
For now I got this fix:

RNGoogleSignin.getAccessToken(user).then((token) => {
  this._user.accessToken = token;
  this._removeListeners(sucessCb, errorCb);
  resolve({...this._user, accessToken: token});
})

but not sure how viable this is.

I had success importing both GoogleSignin from node_modules and importing NativeModules from react-native. Using GoogleSignin I was able to get the current user and then pass it to NativeModules.RNGoogleSignin.getAccessToken.

@centaurreader Did you get an actual valid access token? I tried this, and get a garbage value that does not look like a token at all

{ _45: 0, _81: 0, _65: null, _54: null }

I was able to get a working token

On Sat, Dec 10, 2016 at 10:44 AM Ujwal Setlur notifications@github.com
wrote:

@centaurreader https://github.com/centaurreader Did you get an actual
valid access token? I tried this, and get a garbage value that does not
look like a token at all

{ _45: 0, _81: 0, _65: null, _54: null }


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/devfd/react-native-google-signin/issues/147#issuecomment-266221353,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AHZ1juLRhVhRDOoHiDx-fKuDAuZWZkrbks5rGtbngaJpZM4Khu1g
.

Hmm, which versions of react-native, react-native-google-signin and Android versions?
Fortunately, I really don't need the access token, so was able to work around it, but I am curious why it didn't work for me...

Get Outlook for iOS

On Sun, Dec 11, 2016 at 7:46 PM -0800, "Paul Browning" notifications@github.com wrote:

I was able to get a working token

On Sat, Dec 10, 2016 at 10:44 AM Ujwal Setlur notifications@github.com

wrote:

@centaurreader https://github.com/centaurreader Did you get an actual

valid access token? I tried this, and get a garbage value that does not

look like a token at all

>

{ _45: 0, _81: 0, _65: null, _54: null }

>

You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub

https://github.com/devfd/react-native-google-signin/issues/147#issuecomment-266221353,

or mute the thread

https://github.com/notifications/unsubscribe-auth/AHZ1juLRhVhRDOoHiDx-fKuDAuZWZkrbks5rGtbngaJpZM4Khu1g

.

>


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

react-native: 0.37.0
react-native-google-signin: 0.8.1
android: 7.0

Thanks! I am close, but not quite the same, but will try with these!

Get Outlook for iOS

On Mon, Dec 12, 2016 at 8:57 AM -0800, "Paul Browning" notifications@github.com wrote:

react-native: 0.37.0

react-native-google-signin: 0.8.1

android: 7.0


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

@Bhullnatik fix works

No longer a issue on latest version. Please checkout our example app.

Create new issue if this persists.

Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tundak picture tundak  ·  4Comments

guidotajan picture guidotajan  ·  4Comments

smartcris picture smartcris  ·  3Comments

pawellewandowski picture pawellewandowski  ·  4Comments

rami-amar picture rami-amar  ·  4Comments