Giter Site home page Giter Site logo

Comments (21)

devfd avatar devfd commented on May 18, 2024 3

the non-obvious thing from Google documentation is that clientId has to be of type Web Application

from your google project console, on the API Manager -> Credentials page, select New credentials -> OAuth Client ID and make sure to select Web Application

the newly generated clientID is the one ;)

from google-signin.

lesniakania avatar lesniakania commented on May 18, 2024 1

@vladvasyuk Please see my pull request: #26
That was only change I needed in this library to get this working.

Additionally, I needed to update my app to react-native 0.18 (I have some problems with that, but upgrading node to 5.2.0 (npm 3.3.12) helped me).

If you don't want to upgrade react-native, you'd probably need to change this line to compile "com.facebook.react:react-native:0.17.0".

The flow of the sign in looks like this:

  1. Create client id of the type android, download google-services.json config file, put it to the android/app directory
  2. Create client id for web and use it in react-native-google-signin library init
  3. You should get basic user info + idToken and authServerCode
  4. If you have separate backend server
    • if you just want to login user, without using later Google API, just send idToken to the server and verify user identity from there
    • if you want to use Google API, send authServerCode to your server and exchange it along with your secret for the accessToken

I'm happy to help you more on priv if you want - [email protected]

These resources helped me:

from google-signin.

lesniakania avatar lesniakania commented on May 18, 2024

I have exactly the same issue with the same configuration. I downgraded react-native-google-signin to 0.2.4, and I don't have 12501 error now, but accessToken is null....

from google-signin.

vladvasyuk avatar vladvasyuk commented on May 18, 2024

@lesniakania have you tried clientid of type "Web application", as @devfd devfd said? This solution didn't help me :(

from google-signin.

devfd avatar devfd commented on May 18, 2024

well that's weird, the sample app is working fine even with a clientId

check that:

  • clientId is of type 'Web application'
  • your application FQDN matches the one registered under Android API key in your google console

from google-signin.

lesniakania avatar lesniakania commented on May 18, 2024

@vladvasyuk it partially worked for me.
Firslty I had issues with this line: https://github.com/apptailor/react-native-google-signin/blob/master/android/build.gradle#L21

I needed to change it to 0.17.0 as for some reason I had errors while using let { ListView } = React; syntax. It looked a little bit like React 0.18.0-rc would compile, but I have 0.17.0 in my app and can't get 0.18.0-rc because of lack of compatibilty with other libraries.

When I changed that and use Web application type of clientId, I finally managed to get accessToken. But firstly I think it's idToken, not accessToken, I changed also this in my local copy of react-native-google-signin, to use requestServerAuthCode and getServerAuthCode, it worked, but I'm not sure if it's still what I need.

In short - everything works for me fine for iOS but I still have issues with Android version. It looks like tokens returned by Android version are different than returned by iOS version.

from google-signin.

ddzyndra avatar ddzyndra commented on May 18, 2024

I still have this issue and getting 12501 error code. @lesniakania I tried your code from pull request, it didn't help. I tried example from this project, set up all client id (android and web app) and it also didn't work. I have tried different versions of react native and this package. No result.

I tried completely native example from google https://github.com/googlesamples/google-services/tree/master/android/signin and it works fine, I can get server Auth Code.

I don't know how to fix it. maybe I need some special settings in gradle file ? Can anyone share his working example ?

Many thanks

from google-signin.

devfd avatar devfd commented on May 18, 2024

when trying the sample app included in this project, simply:
cd example; react-native run-android

and you are good to go. the client id is already configured correctly.

please confirm everything is working as expected.

also you can set up a public github repo with your App so that we can help you better

from google-signin.

ddzyndra avatar ddzyndra commented on May 18, 2024

Yes, I did as you wrote.
cd example
npm install
react-native run-android

and got ERROR signin in Object {error: "unknown status code: 12501", code: 12501}

from google-signin.

devfd avatar devfd commented on May 18, 2024

alright strange. on what device you are testing ?

from google-signin.

lesniakania avatar lesniakania commented on May 18, 2024

Maybe try

rm -rf android/build
rm -rf android/app/build

And also quit from your React packager console (and make sure that you don't have any zombie processes - ps aux | grep packager) before running react-native run-android

from google-signin.

haydenth avatar haydenth commented on May 18, 2024

So I'm having the same issue now with 0.19. Do you end up having to create two sets of credentials and two clientIds? One for the android app (google_secrets.json) and another one for the oauth?

from google-signin.

lesniakania avatar lesniakania commented on May 18, 2024

Yes, because that is how oauth flow should actually works.
The idea is that you have one set of credentials on the client (here, on Android side, you use client id in google-services.json).
You use this credentials to obtain temporary server authorization code which you can exchange for access token you'd need to actually use Google API.
But to obtain access token you need server auth code + secret. The idea is that you obtain this token using your backend server, where your secret is save.
So you send this temporary auth code to your backend server and exchange it along with secret for access token doing request to https://www.googleapis.com/oauth2/v4/token from your backend.
That's why second pair of credentials must be of 'web' type.

You can read more (here)[https://developers.google.com/identity/protocols/OAuth2ForDevices] and (here)[https://developers.google.com/identity/sign-in/android/offline-access].

from google-signin.

ddzyndra avatar ddzyndra commented on May 18, 2024

I'm testing on different devices: LG G4 Android 6.0, Samsung Galaxy s4 android 5.1

@lesniakania Thanks, I have tried your solutions, but it didn't help.
I dont understand what I'm doing wrong. I have set up android and web app client id, downloaded google-services.json file. I guess maybe I have some errors in configuration, but don't know how to find it.

I have set up public repo on github with my test app https://github.com/ddzyndra/googleSignIn
Can you take a look on that and give some advice ?

from google-signin.

devfd avatar devfd commented on May 18, 2024

@ddzyndra your google configuration seems to be off. you are missing API Keys. they are auto-created by the configuration wizzard.

Also your build.gradle should not include compile "com.google.android.gms:play-services-auth:8.3.0"

Please start again from a fresh install, carefully follow the instructions and you should be fine ;)

correct config

from google-signin.

ddzyndra avatar ddzyndra commented on May 18, 2024

Thank you, @devfd very much for your help :) Yes, I have API Keys, I posted wrong screenshot. Did you get my example working? do you use debug or release key store?

Does it depend on node version ?

from google-signin.

lesniakania avatar lesniakania commented on May 18, 2024

@ddzyndra sorry, I have crazy week, I will look at your code tomorrow evening.

from google-signin.

ddzyndra avatar ddzyndra commented on May 18, 2024

sorry guys, it looks like I have found my problem. I changed the owner of .gradle file and ran react-native run-android without sudo. And it works now.

Thank you @devfd and @lesniakania for your help!

from google-signin.

seanscal avatar seanscal commented on May 18, 2024

I'm getting this issue now. @ddzyndra how did changing the owner fix it and how do i go about doing that?

from google-signin.

seanscal avatar seanscal commented on May 18, 2024

apologies, didnt restart my node server after doing all this... my issue is fixed

from google-signin.

mahdit83 avatar mahdit83 commented on May 18, 2024

I had the same problem and here is the answer: http://stackoverflow.com/a/41413713/1498586

and this is sample code in github: https://github.com/mahdit83/FireBaseAuthDemo

from google-signin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.