Setting up Google single sign in
Posted / Публикувана 2017-01-16 in category / в категория: Android
|
Warning: count(): Parameter must be an array or an object that implements Countable in /home/bolyarco/www-ikratko/ogrelab/wp-content/plugins/microkids-related-posts/microkids-related-posts.php on line 645
This post is more like a note to myself. Setting up Google sign in is not something I do very often. It happens on average once a year and each time I have to do it I have to struggle with the crappy documentation (because I manage to forget the implementation details).
So:
1 .Go to Google developer console at https://console.developers.google.com/apis/
2. Create new project, Click 'Credentials' menu item
3. Click the Create credentials button -> OAuth client ID -> Web application -> Create. Don't mind the "Web application" thing, you need this for the android app. Enter some name and then Save. Google will generate two things for it: Client ID and Client secret. Client ID is used in the android app when creating GoogleSignInOptions like this:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.google_client_id)) .build();
Client secret is used on the server side only.
4. Now we have to create android credentials for both debug and release (optionally) .
4.1. Debug
Click the Create credentials button -> OAuth client ID -> Android
For name use 'Android client debug' (for example)
For signing-certificate finger print use:
keytool -exportcert -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore
to show the fingerprint (use SHA-1)
For package name use the package name from your AndroidManifest.xml. You may need to add '.debug' suffix if gradle is configured to add it when building debug version.
4.2. Release
Do the same but using the release key
keytool -exportcert -keystore android_release_keys.keystore -list -v
4. Go to https://developers.google.com/identity/sign-in/android/start-integrating
Click 'Get a configuration' file button. Select the app and package (usually release package, i.e. without debug). 'Continue and configure services'
There is a button 'Enable google sign in", Click it.
There is a button "Generate conf files". Click it.
There is a button 'Download google-services.json'. DON'T click it.
Go again to https://developers.google.com/identity/sign-in/android/start-integrating
Select the app, but enter the debug package, i.e. with the .debug suffix.'Continue and configure services'
There is a button 'Enable google sign in", Click it.
There is a button "Generate conf files". Click it.
There is a button 'Download google-services.json'. Click it and download the file. This file contains the configuration for both release and debug builds.
Copy the file in the root of the app module folder (that is NOT the project root).
Now everything should work.
|