diff --git a/README.md b/README.md index adf13e87..7865502d 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,7 @@ NPM Version

-### 🚧🚧 New features planned: looking for sponsors and collaborators 🚧🚧 - -See this [issue](https://github.com/react-native-google-signin/google-signin/issues/942) +❤️❤️ [New documentation site available!](https://react-native-google-signin.github.io/docs/install) ❤️❤️ ## Features @@ -16,58 +14,11 @@ See this [issue](https://github.com/react-native-google-signin/google-signin/iss - Mock of the native module for testing with Jest - Native sign in buttons -## Requirements - -- RN >= 0.60 - ## Project setup and initialization -There are two ways to install the package: - -The latest version that - -✅ supports the new [One Tap sign-in on Android](https://developers.google.com/identity/one-tap/android/overview) which can be easily used together with the Google Sign-In for iOS - -✅ supports the React Native [New Architecture](https://reactnative.dev/docs/new-architecture-intro) - -✅ includes some API improvements and minor fixes - -is only available to [GitHub sponsors](https://github.com/sponsors/vonovak) of the maintainer. - -When you become a sponsor using one of the marked tiers, you will automatically be invited to a private repo with the latest version of the package. The package is published to a private GH packages registry under the same name as the public one. - -Alternatively, you can install from the public registry using `yarn add @react-native-google-signin/google-signin` which will install an older version. - -The public version will be kept working, but it may not include the latest fixes and features. This is to incentivize sponsorships and thus support the maintenance of the package in the long term. -My goal is to include all improvements from the private package in the public one (and remove the private one) once there is sufficient support from sponsors :+1:. - -Then follow the [Android guide](docs/android-guide.md) and [iOS guide](docs/ios-guide.md) - -## Expo installation - -> This package cannot be used in the "Expo Go" app because [it requires custom native code](https://docs.expo.io/workflow/customizing/). _However, you can add custom native code to expo by following the guide below._ - -```sh -npx expo install @react-native-google-signin/google-signin -``` - -After installing this npm package, add the [config plugin](https://docs.expo.io/guides/config-plugins/) to the [`plugins`](https://docs.expo.io/versions/latest/config/app/#plugins) array of your `app.json` or `app.config.js`: - -```json -{ - "expo": { - "android": { - "googleServicesFile": "./google-services.json" - }, - "ios": { - "googleServicesFile": "./GoogleService-Info.plist" - }, - "plugins": ["@react-native-google-signin/google-signin"] - } -} -``` +Please follow the "Installation" and "Setting up" guides at [react-native-google-signin.github.io](https://react-native-google-signin.github.io/). -Next, rebuild your app as described in the ["Adding custom native code"](https://docs.expo.io/workflow/customizing/) guide. +Then, if you're a sponsor (as explained [here](https://react-native-google-signin.github.io/docs/install)), you can continue using the guides on the dedicated documentation site. If not, please use this readme file. ## Public API @@ -100,7 +51,7 @@ An example with all options enumerated: ```js GoogleSignin.configure({ scopes: ['https://www.googleapis.com/auth/drive.readonly'], // what API you want to access on behalf of the user, default is email and profile - webClientId: '', // client ID of type WEB for your server (needed to verify user ID and offline access) + webClientId: '', // client ID of type WEB for your server. Required to get the idToken on the user object, and for offline access. offlineAccess: true, // if you want to access Google API on behalf of the user FROM YOUR SERVER hostedDomain: '', // specifies a hosted domain restriction forceCodeForRefreshToken: true, // [Android] related to `serverAuthCode`, read the docs link below *. diff --git a/docs/android-guide.md b/docs/android-guide.md deleted file mode 100644 index f8d071b4..00000000 --- a/docs/android-guide.md +++ /dev/null @@ -1,190 +0,0 @@ -## Android Guide - -Please see the **FAQ** at bottom before opening new issues - -### 1. Google project configuration - -#### 1.a - if you're using Firebase - -- Follow [this](./get-config-file.md) guide to get the configuration file. - -- Place the generated configuration file (`google-services.json`) into project according to [this guide](https://developers.google.com/android/guides/google-services-plugin#adding_the_json_file). - -#### 1.b - if you're NOT using Firebase - -- Follow the instructions to [Configure a Google API Project](https://developers.google.com/identity/sign-in/android/start#configure-a-google-api-project) from the official docs. - -Please see more details here https://support.google.com/cloud/answer/6158849#installedapplications&android if needed. -It's important that OAuth 2.0 android id has fingerprint set correspondingly to the fingerprint of certificate which is used to sign the apk. Also, package name should be the same as apk package name. - -### 2. Installation - -Please note that this package requires android gradle plugin of version >= 3, which in turn requires at least gradle 4.1. Android studio should be able to do the upgrade for you. - -1 . link the native module - -In RN >= 0.60 you should not need to do anything thanks to [autolinking](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md) - -2 . Update `android/build.gradle` with - -```gradle -buildscript { - ext { - buildToolsVersion = "27.0.3" - minSdkVersion = 16 - compileSdkVersion = 27 - targetSdkVersion = 26 - supportLibVersion = "27.1.1" - googlePlayServicesAuthVersion = "19.2.0" // <--- use this version or newer - } -... - dependencies { - classpath 'com.android.tools.build:gradle:4.2.1' // <--- use this version or newer - classpath 'com.google.gms:google-services:4.3.10' // <--- use this version or newer - } -... -allprojects { - repositories { - mavenLocal() - google() // <--- make sure this is included - jcenter() - maven { - // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm - url "$rootDir/../node_modules/react-native/android" - } - } -} -``` - -3 . Update `android/app/build.gradle` with - -```gradle -... -dependencies { - implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation "com.facebook.react:react-native:+" - implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0' // <-- add this; newer versions should work too -} - -apply plugin: 'com.google.gms.google-services' // <--- this should be the last line -``` - -#### Choose Dependency versions (optional) - -The library depends on `com.google.android.gms:play-services-auth`, as seen in [build.gradle](https://github.com/react-native-community/google-signin/blob/master/android/build.gradle). If needed, you may control their versions by the `ext` closure, as seen in [build.gradle](https://github.com/react-native-community/google-signin/blob/master/example/android/build.gradle) of the example app. - -### 3. Running on simulator - -Make sure you have a simulator with Google Play Services installed. - -To ensure best performance, you should use x86 emulator and have [HW acceleration](https://developer.android.com/studio/run/emulator-acceleration#accel-vm) working. - -### Running on device - -Nothing special here, as long as you run your app on an Android device with Google Play Services installed. - -## FAQ / Troubleshooting - -[See troubleshooting for non-firebase users below](#troubleshooting-for-non-firebase-users) - -#### I'm getting an error and I'm not able to fix it - -Configuring google sign in can sometimes be tricky. If you're hitting a wall, you can get in touch with a maintainer ([@vonovak](https://github.com/vonovak)) via his [personal site](https://react-native-training.eu/). Please note that this is a paid service. - -#### I'm getting "A non-recoverable sign in failure occurred" - -See [this comment](https://github.com/react-native-community/google-signin/issues/659#issuecomment-513555464). Or [this SO question](https://stackoverflow.com/questions/53816227/google-signin-sdk-is-failing-by-throwing-error-a-non-recoverable-sign-in-failur). - -#### Getting `DEVELOPER_ERROR` or `code: 10` error message on Android when trying to login. OR signin() hangs and never resolves the promise. - -This is configuration mismatch. Make sure that your SHA certificate fingerprint and package name you entered in Firebase are correct. If you are in development, make sure your development signing fingerprint is added as well. - -To get the SHA1: - -1. From your project root, `cd android && ./gradlew signingReport`. -2. Scroll to the top of output, see the fingerprints. Debug fingerprint is used in dev, release fingerprint is used in production. - -To add the SHA1: - -1. Sign in to Firebase and open your project. -2. Click the Settings icon and select Project settings. -3. In the Your apps card, select the package name of the app you need a to add SHA1 to. -4. Click "Add fingerprint". - -![Firebase, add Android keystore's SHA1 to your project](/img/android-fingerprint-firebase.png) - -Then re-download the `google-services.json` file, put it into your project (usually, the path is `android/app/google-services.json`) and rebuild your project. - -You may need to add your SHA certificate fingerprint to your Firebase config. Find your SHA1 fingerprint by following the instructions at [stackoverflow](https://stackoverflow.com/questions/15727912/sha-1-fingerprint-of-keystore-certificate/33479550#33479550). Then, go to https://console.firebase.google.com/, select your app, and add the SHA1 value under Project Settings (gear icon in the upper left) -> Your Apps -> SHA certificate fingerprints - -If you're passing `webClientId` in configuration object to `GoogleSignin.configure()` make sure it's correct and that it is of type web (NOT Android!). You can get your `webClientId` from [Google Developer Console](https://console.developers.google.com/apis/credentials). They're listed under "OAuth 2.0 client IDs". - -If you're running your app in debug mode and not using `webClientId` or you're sure it's correct the problem might be signature (SHA-1 or SHA-256) mismatch. You need to add the following to `android/app/build.gradle`: - -```diff -signingConfigs { -+   debug { -+        storeFile file(MYAPP_RELEASE_STORE_FILE) -+ storePassword MYAPP_RELEASE_STORE_PASSWORD -+ keyAlias MYAPP_RELEASE_KEY_ALIAS -+ keyPassword MYAPP_RELEASE_KEY_PASSWORD -+ } - release { - ... - } - } -``` - -#### Google Login does NOT work when using Internal App Sharing. - -If you get a DEVELOPER_ERROR when using Internal App Sharing, it is because Google resigns your application with its own key. In the Google Play Console go to Development Tools-> Internal App Sharing->App Certificate and there is another SHA-1 fingerprint to add to firebase. - -This is separate from the release app signing certificate explained below. - -Also see [here](https://stackoverflow.com/questions/57780620/how-to-get-android-internal-app-sharing-key-sha1-to-enable-google-apis). - -#### Google Login does NOT work when downloading my app from the play store. - -Check if "Google Play App Signing" is enabled for your app. -If it is enabled, you will need to add the "App signing certificate" `SHA-1` to your firebase console. - -You can find it at: App -> Release (in left sidebar) -> Setup -> App integrity. Under the App signing key certificate, copy `SHA-1 certificate fingerprint` into firebase console for the Android app. - -If you are not using firebase, and your app is enabled for "Google Play App Signing": -Go to "https://console.developers.google.com/" -> click "Credential" in the right panel -> Find "Client ID" for type "Android" under "OAuth 2.0 Client IDs" section -> Edit -> replace "SHA-1 certificate fingerprint" with the one from App -> Release (in left sidebar) -> Setup -> App integrity -> App signing key certificate. - -#### My project includes other react-native plugins which have different google play services versions. What to do? - -See ["Choose Dependency versions"](#choose-dependency-versions-optional) above. - -#### After upgrading and thoroughly following the guide the build fail with `Missing api_key/current_key object`. What to do? - -open `android/app/google-services.json` and replace `"api_key":[]` with `"api_key":[{ "current_key": "" }]` - -#### After the sign-in completes I get the following error `error code 12501`. What to do? - -This is a permission error. Make sure the `certificate_hash` in `android/app/google-services.json` matches your certificate. - -To get your sha1-hash - -``` -keytool -exportcert -keystore ~/.android/debug.keystore -list -v -``` - -Also make sure the application id matches the one you enter on the cloud console. - -#### I did everything and I still have problems to compile my project. - -Read this [medium article](https://medium.com/@suchydan/how-to-solve-google-play-services-version-collision-in-gradle-dependencies-ef086ae5c75f). Basically, if you have other play services libraries installed, you have to exclude some dependencies. - -### Troubleshooting for non-firebase users - -If you are not using firebase you can ignore all docs related to google services. You don't need a `google-services.json` or any `build.gradle` changes from this docs. Simply follow the instructions from the [the official docs](https://developers.google.com/identity/sign-in/android/start-integrating). However, be aware of following common issues which can lead to a `DEVELOPER ERROR` or an `A non-recoverable sign in failure occurred` error. - -#### Try different SHA1 keys - -Depending on your config you may need to add multiple SHA1 keys. Go to your android folder and run `./gradlew signingReport`. You should see different SHA1 keys for debug and release. Add them to the [google developer console](https://console.developers.google.com/apis/credentials) under the oauth section. Select Android as client type. You may also need your SHA1 key from the [play console](https://play.google.com). Find it in the app signature area and add it as well. - -#### Package name !== application id - -When adding a new oauth client, google asks you to add your package name. In some cases your package name is not equal to your application id. Check if your package name in the `AndroidManifest.xml` is the same as your application/bundle id. Find your application id in the play console or `android/app/build.gradle`. The format looks like `com.yourapp.id`. diff --git a/docs/get-config-file.md b/docs/get-config-file.md deleted file mode 100644 index 29ddcdcd..00000000 --- a/docs/get-config-file.md +++ /dev/null @@ -1,41 +0,0 @@ -# Get configuration file - -## With Firebase - -Please NOTE that you **do not** need firebase to get the necessary files and SHA1 hashes - see the guide below if you don't want to use firebase. - -If you don't already have a project in Firebase you need to create one in order to generate credentials for an iOS and Android application. - -[Firebase console](https://console.firebase.google.com/u/0/) - -1. Add your iOS and Android App inside Project settings (see image). - -![Project settings](../img/project-settings.png) - -2. Enter required information and download the config file. - -_Note: For Android, adding the SHA1 hash is an obligation_ - -You can use your debug keystore's SHA1 hash, read this [StackOverflow thread](https://stackoverflow.com/questions/15727912/sha-1-fingerprint-of-keystore-certificate) to obtain it. When running the `keytool` command, **MAKE SURE** you provide path to the correct keystore, you may have multiple keystores on your system! (eg in home directory, and also directly in the `android/app` folder). To see what keystore is being used to sign your app, go to `android/app/build.gradle` and look for `storeFile` entries. - -If you don't have a keystore, you need to generate one. To generate your keystore follow [this guide](https://facebook.github.io/react-native/docs/signed-apk-android.html). - -**IMPORTANT** if you have multiple keystores (and you likely do - eg. debug and release) you'll need to get the SHA1 hashes for all of them and save the hashes to Firebase! - -## Without Firebase - -### iOS - -Follow these instructions from the official docs: - -1. [Get an OAuth client ID](https://developers.google.com/identity/sign-in/ios/start-integrating#get_an_oauth_client_id). -1. [Add a URL scheme to your project](https://developers.google.com/identity/sign-in/ios/start-integrating#add_a_url_scheme_to_your_project) - -### Android - -Follow the instructions to [Configure a Google API Project](https://developers.google.com/identity/sign-in/android/start#configure-a-google-api-project) from the official docs. - -## WebClientId - -`webClientId` will be automatically generated once you create the app in the firebase console or configure the API. You can access it [here](https://console.developers.google.com/apis/credentials). -Make sure you select the correct project. `webClientId` should be under OAuth section. diff --git a/docs/how-cocoapods.md b/docs/how-cocoapods.md deleted file mode 100644 index a041e461..00000000 --- a/docs/how-cocoapods.md +++ /dev/null @@ -1,35 +0,0 @@ -_If you don't have a Podfile, follow the instructions:_ - -1 . `pod init` creates a Podfile. - -2 . add `GoogleSignIn` pod (see example below) - -3 . run `pod install` - -4 . from now on, use Xcode to open the `.xcodeworkspace` file (do not open the `.xcodeproj` any more) - -_Podfile example_ - -```ruby -# Uncomment the next line to define a global platform for your project -# platform :ios, '9.0' - -target 'test_google_signin' do - # Uncomment the next line if you're using Swift or would like to use dynamic frameworks - # use_frameworks! - - # Pods for test_google_signin - pod 'GoogleSignIn', '~> 6.1.0' - - target 'test_google_signin-tvOSTests' do - inherit! :search_paths - # Pods for testing - end - - target 'test_google_signinTests' do - inherit! :search_paths - # Pods for testing - end - -end -``` diff --git a/docs/ios-guide.md b/docs/ios-guide.md deleted file mode 100644 index 4dab8dfe..00000000 --- a/docs/ios-guide.md +++ /dev/null @@ -1,58 +0,0 @@ -## iOS Guide - -### 1. Installation - -#### Link the native module - -- run `pod install` in `ios/` directory to install the module - -#### Install Google Sign In SDK - -The [podspec](https://github.com/react-native-google-signin/google-signin/blob/master/RNGoogleSignin.podspec) will install a compatible version of the [GoogleSignIn pod](https://github.com/react-native-google-signin/google-signin/blob/master/RNGoogleSignin.podspec). All you need to do is run `pod install` and then recompile the iOS project. - -First time using cocoapods? [check this out](./how-cocoapods.md) - -At the end, the dependencies should be linked like in this picture (this is _with_ pods, for RN >= 0.60). - -[![link config](../img/pods-rn60.png)](../img/buildPhasesWithPods.png?raw=true) - -### 2. Google project configuration - -- Follow [this](./get-config-file.md) guide to get the configuration file. - -- Download the `GoogleService-Info.plist` file at the end of the process - -### 3. Xcode configuration - -- Configure URL types in the `Info` panel (see screenshot) - - add a URL with scheme set to your `REVERSED_CLIENT_ID` (found inside `GoogleService-Info.plist`) -- If you need to support Mac Catalyst, you will need to enable the Keychain Sharing capability on each build target. No keychain groups need to be added. - -[![link config](../img/urlTypes.png)](../img/urlTypes.png?raw=true) - -### Optional: modify your app to respond to the URL scheme - -This is only required if you have multiple listeners for `openURL` - for instance if you have both Google and Facebook OAuth (as seen in the code snippet below). - -Because only one `openURL` method can be defined, if you have multiple listeners for `openURL`, you must combine them into a single function in your `AppDelegate.m` like so: - -- Open `AppDelegate.m` -- Add an import: `#import ` (if this one will not work try `#import "RNGoogleSignin.h"`). If this file cannot be found, you need to modify your header search paths so Xcode can find headers of `react-native-google-signin`. For example, when using the non-cocoapods installation, make sure that `$(SRCROOT)/../node_modules/@react-native-google-signin/google-signin/ios` is included in your target's header search paths. -- Add a method to respond to the URL scheme. This is just an example of a method that you can add at the bottom of your file if you're using both `FBSDKApplicationDelegate` and `RNGoogleSignin` : - -```objc -// AppDelegate.m -- (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary *)options { - return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options] || [RNGoogleSignin application:application openURL:url options:options]; -} -``` - -## FAQ / Troubleshooting - -#### I'm getting an error and I'm not able to fix it - -Configuring google sign in can sometimes be tricky. If you're hitting a wall, you can get in touch with a maintainer ([@vonovak](https://github.com/vonovak)) via his [personal site](https://react-native-training.eu/). Please note that this is a paid service. - -#### On iOS the app crashes when tapping Sign In button - -You're most likely missing `Url Schemes` configuration. How to do it: ![configure URL schemes](/img/add-url-scheme-ios.png)