fullstackreact / react-native-firestack

A firestack v3 react-native implementation
MIT License
715 stars 134 forks source link

[v3] Google OAuth (via react-native-oauth) -> Firebase #159

Open ajonno opened 7 years ago

ajonno commented 7 years ago

I need a bit of help with this one. I've implemented react-native-oauth (iOS) for Google auth, and its returning a payload, all is good there.

what I cant work out now is how do i "tie" that into Firebase, so that i can complete things and register/create the user on Firebase ? the response payload from ..-auth0 has 'credentials' and 'access-token' that I can see. can i use that to then authenticate with Firebase (Im using the Firestack lib :-)

ajonno commented 7 years ago

Any help is appreciated we're on a bit of a tight deadline with this one

auser commented 7 years ago

@ajonno You should be able to register with the token: https://github.com/fullstackreact/react-native-firestack#signinwithprovider

ajonno commented 7 years ago

i did try that with Facebook and was fine/works.

but Google didnt like the access_token. ill double back to post the error response here shortly

ajonno commented 7 years ago

here is the error:

  1. the manager.authorize(.. IS succeeding for Google auth
  2. Firestack is throwing the error attached

here is the code block. i suspect im missing a param somewhere?

manager.authorize('google', {scopes: 'profile email'})
         .then(resp =>   {
            console.log('GOOGLE authorize response: ', resp)

            firestack.signInWithProvider('google', resp.response.credentials.access_token, '') // facebook need only access token.
            .then((user)=>{
               console.log('(FIRESTACK) GOOGLE AUTH response:', user)
            }) 
            .catch(err => console.log(err));

         })
         .catch(err => console.log(err));

image

matthewjamieson commented 7 years ago

+1 same issue for me as well

matthewjamieson commented 7 years ago

Found the Solution. change resp.response.credentials.access_token to resp.response.credentials.idToken

https://github.com/fullstackreact/react-native-firestack/issues/130

https://gist.github.com/auser/87e6a25da0b25c465dd0db097b8864ca#file-firebase_google_login-js-L108