This is a react native library to integrate google sign in with youtube brand account using AppAuth
Android to integrate google sign in with youtube brand account using AppAuth$ npm install react-native-google-appauth --save
$ react-native link react-native-google-appauth
Add this in your android/app/src/main/AndroidManifest.xml
``
android:launchMode="singleTask">
`
#### Android
1. Open up android/app/src/main/java/[...]/MainActivity.javaimport com.bidchat.reactnative.appauth.RNGoogleAppauthPackage;
- Add to the imports at the top of the filenew RNGoogleAppauthPackage()
- Add to the list returned by the getPackages() methodandroid/settings.gradle
2. Append the following lines to :`
`
include ':react-native-google-appauth'
project(':react-native-google-appauth').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-appauth/android')
android/app/build.gradle
3. Insert the following lines inside the dependencies block in :`
`
compile project(':react-native-google-appauth')
android/app/src/main/AndroidManifest.xml
4. Add this in your `
android:launchMode="singleTask">
`
javascript
import { configure, signIn, signOut } from 'react-native-google-appauth';componentDidMount() {
const authInstance = configure({
redirectUrl: "com.bidchat.reactnative.appauth:/oauth2callback",
clientId: "[YOUR_CLIENT_ID]", // Generate from https://console.developers.google.com/ if you don't have
scopes: ["https://www.googleapis.com/auth/youtube.readonly", "openid", "email", "profile"],
additionalParameters: {} // Comming soon
});
authInstance.then((data) => {
console.log("User LoggedIn", data);
if (data && (typeof data === "object") && data.id_token) {
// this.setState({ signedIn: true, user: data });
// DO SOMETHING WITH USER INFO
} else {
// USER NOT LOGGED IN OR SESSION EXPIRED
}
})
.catch((err) => {
console.log("LoggedInError", err);
});
}
handleLogin = async () => {
try {
const data = await signIn();
console.log('Login success ----', data);
// if (data && (typeof data === "object") && data.id_token) {
// this.setState({ signedIn: true, user: data });
// }
// DO SOMETHING WITH USER INFO
} catch (err) {
console.log('ERROR ----', err);
}
}
handleLogOut = async () => {
const logout = await signOut();
if (logout && (typeof logout === "object") && logout.status) {
// this.setState({ signedIn: false, user: {} });
// USER SUCCESSFULLY LOGGEDOUT
}
}
.....
render() {
return (
.....
onPress={this.handleLogin}
title="Sign in by Google"
color="#841584"
accessibilityLabel="Click Me to login"
/>
)
}
``