npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-googlesignin

v0.8.2

Published

Google Signin for your react native applications

Downloads

11

Readme

react-native-google-sign

xcode config

Features

  • Support all 3 types of authentication methods (standard, with server-side validation or with offline access (aka server side access))
  • Native signin button
  • Consistent API between Android and iOS
  • Promise-based JS API

Installation

npm install react-native-google-signin --save

Warning: For react-native >= v0.30 use react-native-google-signin >= v0.8.0

Project setup and initialization

See Android guide and iOS guide

Public API

1. GoogleSigninButton

signin button

import {GoogleSignin, GoogleSigninButton} from 'react-native-google-signin';

render() {

  <GoogleSigninButton
    style={{width: 48, height: 48}}
    size={GoogleSigninButton.Size.Icon}
    color={GoogleSigninButton.Color.Dark}
    onPress={this._signIn.bind(this)}/>
}

Possible value for size are:

  • Size.Icon: display only Google icon. recommended size of 48 x 48
  • Size.Standard: icon with 'Sign in'. recommended size of 230 x 48
  • Size.Wide: icon with 'Sign in with Google'. recommended size of 312 x 48

Possible value for color are:

  • Color.Dark: apply a blue background
  • Color.Light: apply a light gray background

2. GoogleSignin

import {GoogleSignin, GoogleSigninButton} from 'react-native-google-signin';

- hasPlayServices

Check if device has google play services installed. Always return true on iOS.

GoogleSignin.hasPlayServices({ autoResolve: true }).then(() => {
    // play services are available. can now configure library
})
.catch((err) => {
  console.log("Play services error", err.code, err.message);
})

when autoResolve the library will prompt the user to take action to solve the issue.

For example if the play services are not installed it will prompt: prompt install

- configure

It is mandatory to call this method before login.

Example for default configuration. you get user email and basic profile info.

import {GoogleSignin, GoogleSigninButton} from 'react-native-google-signin';

GoogleSignin.configure({
  iosClientId: <FROM DEVELOPPER CONSOLE>, // only for iOS
})
.then(() => {
  // you can now call currentUserAsync()
});

Example to access Google Drive both from the mobile application and from the backend server

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
  iosClientId: <FROM DEVELOPPER CONSOLE>, // only for iOS
  webClientId: <FROM DEVELOPPER CONSOLE>, // 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
})
.then(() => {
  // you can now call currentUserAsync()
});

iOS Note: your app ClientID (iosClientId) is always required

- currentUserAsync

Typically called on the componentDidMount of your main component. This method give you the current user if already login or null if not yet signin.

GoogleSignin.currentUserAsync().then((user) => {
      console.log('USER', user);
      this.setState({user: user});
    }).done();

- currentUser

simple getter to access user once signed in.

const user = GoogleSignin.currentUser();
// user is null if not signed in

- signIn

Prompt the modal to let the user signin into your application

GoogleSignin.signIn()
.then((user) => {
  console.log(user);
  this.setState({user: user});
})
.catch((err) => {
  console.log('WRONG SIGNIN', err);
})
.done();

- getAccessToken (Android Only)

Obtain the user access token.

GoogleSignin.getAccessToken()
.then((token) => {
  console.log(token);
})
.catch((err) => {
  console.log(err);
})
.done();

iOS Note: an error with code -5 is returned if the user cancels the signin process

- signOut

remove user session from the device

GoogleSignin.signOut()
.then(() => {
  console.log('out');
})
.catch((err) => {

});

iOS Note: the signOut method does not return any event. you success callback will always be called.

- revokeAccess

remove your application from the user authorized applications

GoogleSignin.revokeAccess()
.then(() => {
  console.log('deleted');
})
.catch((err) => {

})

3. User

This is the typical information you obtain once the user sign in:

  {
    id: <user id. do not use on the backend>
    name: <user name>
    email: <user email>
    photo: <user picture profile>
    idToken: <token to authenticate the user on the backend>
    serverAuthCode: <one-time token to access Google API from the backend on behalf of the user>
    scopes: <list of authorized scopes>
    accessToken: <needed to access google API from the application> (iOS only)
  }

Android Note: To obtain the user accessToken call getAccessToken

idToken Note: idToken is not null only if you specify a valid webClientId. webClientId corresponds to your server clientID on the developers console. It HAS TO BE of type WEB

Read iOS documentation and Android documentation for more information

serverAuthCode Note: serverAuthCode is not null only if you specify a valid webClientId and set offlineAccess to true. once you get the auth code, you can send it to your backend server and exchange the code for an access token. Only with this freshly acquired token can you access user data.

Read iOS documentation and Android documentation for more information

Additional scopes

The default requested scopes are email and profile.

If you want to manage other data from your application (for example access user agenda or upload a file to drive) you need to request additional permissions. This can be accomplished by adding the necessary scopes when configuring the GoogleSignin instance.

Please visit https://developers.google.com/oauthplayground/ for a list of available scopes.

Licence

(MIT)