# rn-google-sign-in

> React native google sign in

Latest version **1.0.10** (published 2018-04-05) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install rn-google-sign-in
pnpm add rn-google-sign-in
yarn add rn-google-sign-in
bun add rn-google-sign-in
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2018-04-05 |
| First published | 2018-03-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 105.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | asimetriq ÖU |
| Maintainers | asimetriq |
| Keywords | react-native, google, google signin, oauth |

## Links

- npm: https://www.npmjs.com/package/rn-google-sign-in
- Repository: https://github.com/Asimetriq/rn-google-sign-in
- Issues: https://github.com/Asimetriq/rn-google-sign-in/issues
- npm.io page: https://npm.io/package/rn-google-sign-in

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 1.0.10 (latest) — 2018-04-05
- 1.0.9 — 2018-03-31
- 1.0.8 — 2018-03-30
- 1.0.7 — 2018-03-28
- 1.0.5 — 2018-03-28
- 1.0.4 — 2018-03-28
- 1.0.3 — 2018-03-28
- 1.0.2 — 2018-03-28
- 1.0.1 — 2018-03-28
- 1.0.0-alpha.9 — 2018-03-27
- 1.0.0-alpha.8 — 2018-03-27
- 1.0.0-alpha.7 — 2018-03-26
- 1.0.0-alpha.6 — 2018-03-25
- 1.0.0-alpha.4 — 2018-03-25
- 1.0.0-alpha.3 — 2018-03-25
- … 2 more at https://npm.io/package/rn-google-sign-in/versions

## README

> Initially forked from [react-native-google-signin](https://github.com/devfd/react-native-google-signin)

Project aims to provide react-native implementation for latest Google Sign-in SDK's used in Android and iOS
with exception of no native sign-in button component.

Project is actively used in our own apps and maintained.

## 1. Creating google project

To work with Google's oAuth you will need to create your project via [google cloud console](https://console.cloud.google.com) or [firebase](https://firebase.google.com/).

After this step you will have your `GoogleService-Info.plist` (iOS) and `google-services.json` (Android) files that you need to add to your codebase.

If you have difficulties with google project creation, please do some online research or submit Stack Overflow question.

## 2. Install NPM module

`npm install rn-google-sign-in` or `yarn add rn-google-sign-in`

## 3. iOS Setup

> Supports projects with min target sdk set to ios 10

1.  Install [cocoapods](https://cocoapods.org) (if you don't have them already)

2.  Inside of your projects `/ios` directory run `pod init`

3.  Step above will generate a `Podfile`, open it and add `pod 'GoogleSignIn'` as a dependency

4.  From terminal run `pod install`

5.  Open your project in XCode using `.xworkspace` file, not `.xcodeproj`

6.  Right click on your projects `Libraries` folder -> "Add files to ..." find `node_modules/rn-google-sign-in/ios/RNGoogleSignIn.xcodeproj` and add it.

7.  In XCode under your targets **Build Phases** expand "Link Binary With Libraries" section and add `libRNGoogleSignIn.a`

8.  In XCode under your targets **Build Settings** search for "Header Search Paths" and add `$(SRCROOT)/../node_modules/rn-google-sign-in/ios/RNGoogleSignIn`

9.  In XCode under your targets **Info** expand "Url Types", create new one and in **URL Schemes** section add whatever the value of `REVERSED_CLIENT_ID` is inside of your `GoogleService-Info.plist`file you got from google

10. Add following the top of your projects `AppDelegate.m` file

```objectivec
#import "RNGoogleSignIn.h"
```

11. Finnaly add this before `@end` statement in the bottom of your `AppDelegate.m`

```objectivec
- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
        options:(NSDictionary<NSString *, id> *)options {

  // Handle Google Deep Links
  BOOL googleLink = [RNGoogleSignIn
                     application:application
                     openURL:url
                     sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                     annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];

  return googleLink;
}
```

## 4. Android Setup

> NOTE: Your simulator needs to have google play services installed to work with google oAuth, you will also need to make sure your development signing is implemented correctly.

1.  In your projects `android/settings.gradle` add

```gradle
include ':rn-google-sign-in', ':app'
project(':rn-google-sign-in').projectDir = new File(rootProject.projectDir, '../node_modules/rn-google-sign-in/android')
```

3.  In your projects `android/build.gradle` add

```gradle
dependencies {
    ...
    classpath 'com.google.gms:google-services:3.0.0' // <--- add thxsis
}
```

4.  In your projects `android/app/build.gradle` add

```gradle
dependencies {
    ...
    compile(project(":rn-google-sign-in")){
        exclude group: "com.google.android.gms"
    }
    compile 'com.google.android.gms:play-services-auth:11.8.0'
}

apply plugin: 'com.google.gms.google-services'
```

5.  Inside your `MainApplication.java` add

```java
import com.asimetriq.googlesignin.RNGoogleSignInPackage;  // <-- add

public class MainApplication extends Application implements ReactApplication {

  // ......

  @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new RNGoogleSignInPackage() // <-- add
      );
    }

  // ......

}
```

## 5. Usage

```js
import { GoogleSignin } from "rn-google-sign-in";
```

### configure (REQUIRED)

Mandotary method that needs to be called before starting work with the library,
configures google sdk data, returns promise once done.

```js
GoogleSignin.configure({
  iosClientId: "", // [iOS] Required avaliable in developer console or GoogleService-Info.plist
  webClientId: "", // client ID of type WEB for your server (needed to verify user ID and 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
  forceConsentPrompt: true, // [Android] if you want to show the authorization prompt at each login
  accountName: "" // [Android] specifies an account name on the device that should be used
});
```

### hasPlayServices

Check if device has google play services installed. Always returns true on iOS.
With `autoResolve` the library will prompt the user to take action to solve the issue.

```js
try {
    await GoogleSignin.hasPlayServices({ autoResolve: true });
    // Play services are avaliable
} catch (e) {
    console.error(e);
}
```

### currentUserAsync

Asynchroneusly retrieves user data if there was previous sign in, null otherwise

```js
const user = await GoogleSignin.currentUserAsync();
console.log(user);
```

### currentUser

Access user data

```js
GoogleSignin.currentUser();
```

### signIn

Prompt modal to let user sign in in on his/her device

```js
try {
    const user = await GoogleSignin.signIn();
    console.log(user);
} catch (e) {
    console.log(e);
}
```

### getAccessToken (Android)

Obtain users access token

```js
try {
  const token = GoogleSignin.getAccessToken();
  console.log(token);
} catch (e) {
  console.error(e);
}
```

### signOut

Sign user out from device

```js
try {
    await GoogleSignin.signOut();
} catch (e) {
    console.error(e);
}
```

### revokeAccess

Remove your application from users authorized applications

```js
try {
    await GoogleSignin.revokeAccess();
} catch (e) {
    console.error(e)l
}
```

---
_Source: https://npm.io/package/rn-google-sign-in · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
