Name: react-native-google-signin
Owner: Yipit
Description: Google Signin for your react native applications
Created: 2017-09-29 22:46:48.0
Updated: 2018-05-15 11:57:13.0
Pushed: 2018-03-06 21:53:31.0
Homepage: null
Size: 19735
Language: Objective-C
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
install react-native-google-signin --save
t-native link react-native-google-signin
If you use React Native < v0.40
stick with v0.8.1
(npm install react-native-google-signin@0.8 --save
).
If you use React Native < v0.47
stick with v0.10.0
(npm install react-native-google-signin@0.10 --save
).
See Android guide and iOS guide
rt {GoogleSignin, GoogleSigninButton} from 'react-native-google-signin';
er() {
oogleSigninButton
style={{width: 48, height: 48}}
size={GoogleSigninButton.Size.Icon}
color={GoogleSigninButton.Color.Dark}
onPress={this._signIn.bind(this)}/>
Possible value for `size
` are:
Possible value for `color
` are:
rt {GoogleSignin, GoogleSigninButton} from 'react-native-google-signin';
Check if device has google play services installed. Always return true on iOS.
leSignin.hasPlayServices({ autoResolve: true }).then(() => {
// play services are available. can now configure library
ch((err) => {
nsole.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:
It is mandatory to call this method before login.
Example for default configuration. you get user email and basic profile info.
rt {GoogleSignin, GoogleSigninButton} from 'react-native-google-signin';
leSignin.configure({
sClientId: <FROM DEVELOPER CONSOLE>, // only for iOS
n(() => {
you can now call currentUserAsync()
Example to access Google Drive both from the mobile application and from the backend server
leSignin.configure({
opes: ["https://www.googleapis.com/auth/drive.readonly"], // what API you want to access on behalf of the user, default is email and profile
sClientId: <FROM DEVELOPER CONSOLE>, // only for iOS
bClientId: <FROM DEVELOPER CONSOLE>, // client ID of type WEB for your server (needed to verify user ID and offline access)
flineAccess: true // if you want to access Google API on behalf of the user FROM YOUR SERVER
stedDomain: '' // specifies a hosted domain restriction
rceConsentPrompt: true // [Android] if you want to show the authorization prompt at each login
countName: '' // [Android] specifies an account name on the device that should be used
n(() => {
you can now call currentUserAsync()
iOS Note: your app ClientID (`iosClientId
`) is always required
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.
leSignin.currentUserAsync().then((user) => {
console.log('USER', user);
this.setState({user: user});
}).done();
simple getter to access user once signed in.
t user = GoogleSignin.currentUser();
ser is null if not signed in
Prompt the modal to let the user signin into your application
leSignin.signIn()
n((user) => {
nsole.log(user);
is.setState({user: user});
ch((err) => {
nsole.log('WRONG SIGNIN', err);
e();
Obtain the user access token.
leSignin.getAccessToken()
n((token) => {
nsole.log(token);
ch((err) => {
nsole.log(err);
e();
iOS Note: an error with code `-5
` is returned if the user cancels the signin process
remove user session from the device
leSignin.signOut()
n(() => {
nsole.log('out');
ch((err) => {
iOS Note: the signOut method does not return any event. you success callback will always be called.
remove your application from the user authorized applications
leSignin.revokeAccess()
n(() => {
nsole.log('deleted');
ch((err) => {
This is the typical information you obtain once the user sign in:
id: <user id. do not use on the backend>
name: <user name>
givenName: <user given name> (Android only)
familyName: <user family name> (Android only)
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>
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
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.
(MIT)