react-native-google-signin / google-signin Public

React Native Google Sign In

NPM Version

Reading: aka.ms remoteconnect code login google photos

7.0.0-alpha available

Please see more here, documentation for v7 alpha currently lives in this branch.

🚧🚧 Maintenance notice 🚧🚧

See this issue

Features

  • Support all 3 types of authentication methods (standard, with server-side validation or with offline access (aka server side access))
  • Promise-based API consistent between Android and iOS
  • Typings for TypeScript and Flow
  • Native signin buttons

Project setup and initialization

For RN >= 0.60 please use version installed from @react-native-google-signin/google-signin

yarn add @react-native-google-signin/google-signin

For RN <= 0.59 use version 2 installed from react-native-google-signin

yarn add react-native-google-signin

Then follow the Android guide and iOS guide

Public API

1. GoogleSignin

configure(options)

It is mandatory to call this method before attempting to call signIn() and signInSilently(). This method is sync meaning you can call signIn / signInSilently right after it. In typical scenarios, configure needs to be called only once, after your app starts. In the native layer, this is a synchronous call.

Example usage with default options: you get user email and basic profile info.

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

* forceCodeForRefreshToken docs

signIn()

Prompts a modal to let the user sign in into your application. Resolved promise returns an userInfo object. Rejects with error otherwise.

signInSilently()

May be called eg. in the componentDidMount of your main component. This method returns the current user and rejects with an error otherwise.

Related: shaders for minecraft 1.17.1 java edition seeds | WTBBLUE

To see how to handle errors read signIn() method

isSignedIn()

This method may be used to find out whether some user is currently signed in. It returns a promise which resolves with a boolean value (it never rejects). In the native layer, this is a synchronous call. This means that it will resolve even when the device is offline. Note that it may happen that isSignedIn() resolves to true and calling signInSilently() rejects with an error (eg. due to a network issue).

getCurrentUser()

This method resolves with null or userInfo object. The call never rejects and in the native layer, this is a synchronous call. Note that on Android, accessToken is always null in the response.

clearCachedAccessToken(accessTokenString)

This method only has an effect on Android. You may run into a 401 Unauthorized error when a token is invalid. Call this method to remove the token from local cache and then call getTokens() to get fresh tokens. Calling this method on iOS does nothing and always resolves. This is because on iOS, getTokens() always returns valid tokens, refreshing them first if they have expired or are about to expire (see docs).

getTokens()

Resolves with an object containing { idToken: string, accessToken: string, } or rejects with an error. Note that using accessToken for identity assertion on your backend server is discouraged.

signOut()

Signs out the current user.

revokeAccess()

Removes your application from the user authorized applications. Read more about it here and here.

hasPlayServices(options)

Checks if device has Google Play Services installed. Always resolves to true on iOS.

Presence of up-to-date Google Play Services is required to show the sign in modal, but it is not required to perform calls to configure and signInSilently. Therefore, we recommend to call hasPlayServices directly before signIn.

hasPlayServices accepts one parameter, an object which contains a single key: showPlayServicesUpdateDialog (defaults to true). When showPlayServicesUpdateDialog is set to true the library will prompt the user to take action to solve the issue, as seen in the figure below.

You may also use this call at any time to find out if Google Play Services are available and react to the result as necessary.

prompt install

statusCodes

These are useful when determining which kind of error has occured during sign in process. Import statusCodes along with GoogleSignIn. Under the hood these constants are derived from native GoogleSignIn error codes and are platform specific. Always prefer to compare wtbblue.com to wtbblue.com_IN_CANCELLED or wtbblue.com_PROGRESS and not relying on raw value of the wtbblue.com.

Name Description SIGN_IN_CANCELLED When user cancels the sign in flow IN_PROGRESS Trying to invoke another operation (eg. signInSilently) when previous one has not yet finished. If you call eg. signInSilently twice, 2 calls to signInSilently in the native module will be done. The promise from the first call to signInSilently will be rejected with this error, and the second will resolve / reject with the result of the native module. SIGN_IN_REQUIRED Useful for use with signInSilently() – no user has signed in yet PLAY_SERVICES_NOT_AVAILABLE Play services are not available or outdated, this can only happen on Android

Example how to use statusCodes.

2. GoogleSigninButton

signin button

Props

size

View more: minecraft backpack mod 1.12.2 forge world titan | WTBBLUE

Possible values:

  • 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.

Default: wtbblue.comdard. Given the size prop you pass, we'll automatically apply the recommended size, but you can override it by passing the style prop as in style={{ width, height }}.

color

View more: minecraft backpack mod 1.12.2 forge world titan | WTBBLUE

Possible values:

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

Boolean. If true, all interactions for the button are disabled.

onPress

Handler to be called when the user taps the button

Inherited View props…

3. userInfo

Example userInfo which is returned after successful sign in.

Want to contribute?

Check out the contributor guide!

Notes

Calling the methods exposed by this package may involve remote network calls and you should thus take into account that such calls may take a long time to complete (eg. in case of poor network connection).

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.

Troubleshooting

Please see the troubleshooting section in the Android guide and iOS guide.

Licence

(MIT)

Related: how to make a face in minecraft

Leave a Comment