-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Unimodule] expo-google-sign-in
#2543
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7e5f46c
[iOS][Android][SDK] Added `Expo.Google.logoutAsync()`
EvanBacon 905f9a3
[Unimodule] Added: `expo-google-sign-in`
EvanBacon ea2055c
Merge branch '@evanbacon/google-logout' of https://github.com/expo/ex…
EvanBacon 4edc5c1
Updated NCL
EvanBacon 9d7eb39
reverted sign-out
EvanBacon 5898b55
export types, ios standalone info added
EvanBacon 0d7e190
Added: Test Suite tests
EvanBacon 3396fa4
Merge branch 'master' into @evanbacon/google-sign-in
EvanBacon 71e7bed
Reverted react-native
EvanBacon 89c13e5
deleted android prefs
EvanBacon 06f733d
PR updates
EvanBacon 3e6023b
play-services bump
EvanBacon a47bc8c
Updates to Docs, & JS API
EvanBacon b7a645c
[iOS] Added `GoogleSignIn` to standalone template `AppDelegate`
EvanBacon b86699a
Added shim for web module
EvanBacon 07992ca
[iOS] Added tests
EvanBacon fb3ac15
[Android] tests
EvanBacon 5ea6d96
Merge branch 'master' into @evanbacon/google-sign-in
EvanBacon d8242ee
Updated docs
EvanBacon cd65d6c
[iOS] removed `requiresMainQueueSetup`
EvanBacon 035954a
Merge branch 'master' into @evanbacon/google-sign-in
EvanBacon 3d999e2
Update react-native-lab/react-native
EvanBacon b05358f
export web module as object literal, fixed constants
EvanBacon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
apps/native-component-list/components/GoogleSignInButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import { Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; | ||
|
||
const googleIcon = { | ||
uri: | ||
'https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/200px-Google_%22G%22_Logo.svg.png', | ||
}; | ||
|
||
export default class GoogleSignInButton extends React.PureComponent { | ||
static defaultProps = { | ||
onPress() {}, | ||
}; | ||
render() { | ||
const { children, style, ...props } = this.props; | ||
return ( | ||
<TouchableOpacity | ||
activeOpacity={0.6} | ||
style={StyleSheet.flatten([styles.touchable, style])} | ||
{...props}> | ||
<View style={styles.content}> | ||
<Image source={googleIcon} style={styles.icon} /> | ||
<Text style={styles.text}>{children}</Text> | ||
</View> | ||
</TouchableOpacity> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
touchable: { | ||
shadowOpacity: 0.2, | ||
shadowRadius: 1.5, | ||
shadowOffset: { width: 0, height: 1 }, | ||
overflow: 'visible', | ||
shadowColor: 'black', | ||
backgroundColor: 'white', | ||
borderRadius: 4, | ||
}, | ||
content: { | ||
flexDirection: 'row', | ||
paddingHorizontal: 16, | ||
paddingVertical: 12, | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
}, | ||
icon: { width: 24, aspectRatio: 1 }, | ||
text: { color: 'gray', marginLeft: 12, fontSize: 16, fontWeight: '600' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
apps/native-component-list/screens/GoogleSignInScreen.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import React from 'react'; | ||
import { GoogleSignIn, Localization } from 'expo'; | ||
import { Image, StyleSheet, Text, View } from 'react-native'; | ||
|
||
import GoogleSignInButton from '../components/GoogleSignInButton'; | ||
|
||
export default class GoogleSignInScreen extends React.Component { | ||
static navigationOptions = { | ||
title: 'Google Sign-In', | ||
}; | ||
|
||
state = { user: null }; | ||
|
||
componentDidMount() { | ||
this._configureAsync(); | ||
} | ||
|
||
_configureAsync = async () => { | ||
const language = Localization.locale; | ||
try { | ||
await GoogleSignIn.initAsync({ | ||
isOfflineEnabled: true, | ||
isPromptEnabled: true, | ||
clientId: '603386649315-vp4revvrcgrcjme51ebuhbkbspl048l9.apps.googleusercontent.com', | ||
language, | ||
}); | ||
} catch ({ message }) { | ||
console.error('Demo: Error: init: ' + message); | ||
} | ||
this._syncUserWithStateAsync(); | ||
}; | ||
|
||
_syncUserWithStateAsync = async () => { | ||
/* | ||
const user = await GoogleSignIn.signInSilentlyAsync(); | ||
this.setState({ user }); | ||
*/ | ||
|
||
if (await GoogleSignIn.signInSilentlyAsync()) { | ||
const photoURL = await GoogleSignIn.getPhotoAsync(256); | ||
this.setState({ | ||
user: { | ||
...GoogleSignIn.currentUser.toJSON(), | ||
photoURL: photoURL || GoogleSignIn.currentUser.photoURL, | ||
}, | ||
}); | ||
} else { | ||
this.setState({ user: null }); | ||
} | ||
}; | ||
|
||
get buttonTitle() { | ||
return this.state.user ? 'Sign-Out of Google' : 'Sign-In with Google'; | ||
} | ||
|
||
render() { | ||
const { user } = this.state; | ||
return ( | ||
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> | ||
{user && <GoogleProfile {...user} />} | ||
<GoogleSignInButton onPress={this._toggleAuth}>{this.buttonTitle}</GoogleSignInButton> | ||
</View> | ||
); | ||
} | ||
|
||
_toggleAuth = () => { | ||
if (this.state.user) { | ||
this._signOutAsync(); | ||
} else { | ||
this._signInAsync(); | ||
} | ||
}; | ||
|
||
_signOutAsync = async () => { | ||
try { | ||
// await GoogleSignIn.disconnectAsync(); | ||
await GoogleSignIn.signOutAsync(); | ||
console.log('Log out successful'); | ||
} catch ({ message }) { | ||
console.error('Demo: Error: logout: ' + message); | ||
} finally { | ||
this.setState({ user: null }); | ||
} | ||
}; | ||
|
||
_signInAsync = async () => { | ||
try { | ||
await GoogleSignIn.askForPlayServicesAsync(); | ||
const { type, user } = await GoogleSignIn.signInAsync(); | ||
console.log({ type, user }); | ||
if (type === 'success') { | ||
this._syncUserWithStateAsync(); | ||
} | ||
} catch ({ message }) { | ||
console.error('login: Error:' + message); | ||
} | ||
}; | ||
} | ||
|
||
class GoogleProfile extends React.PureComponent { | ||
render() { | ||
const { photoURL, displayName, email } = this.props; | ||
return ( | ||
<View style={styles.container}> | ||
{photoURL && ( | ||
<Image | ||
source={{ | ||
uri: photoURL, | ||
}} | ||
style={styles.image} | ||
/> | ||
)} | ||
<View style={{ marginLeft: 12 }}> | ||
<Text style={styles.text}>{displayName}</Text> | ||
<Text style={styles.text}>{email}</Text> | ||
</View> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flexDirection: 'row', | ||
paddingHorizontal: 16, | ||
paddingVertical: 12, | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
marginBottom: 24, | ||
}, | ||
image: { width: 128, borderRadius: 64, aspectRatio: 1 }, | ||
text: { color: 'black', fontSize: 16, fontWeight: '600' }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it going to work for all Expo developers (for example for Facebook apps in development mode one would need to invite all other developers testing NCL for them to be able to authenticate with Facebook to an unpublished Facebook app)? Certainly it could be extracted to some constant at the top of the file. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK this module will only work in standalone. You need a URI scheme defined in your info.plist to run. This is really just for testing. The client ID value here is an override value, the real value will be inferred from a
GoogleServices-Info.plist
. I think the client ID corresponds to the custom URI scheme, so this probably only works for this individual value.I imagine that in order to get the firebase modules working, we will need a way to include a custom
GoogleServices-Info.plist
before building a standalone IPA. Once we add this method, I may just remove theclientId
value altogether.this works for everyone