Google Sign In - MLSDev/LiveDataSocialAuth GitHub Wiki
Sign In
To sign in with the Google account build a GoogleAuth object and call the signIn() method. Observe the auth result with any LifecycleOwner instance. The signIn() method returns the LiveData object with the AuthResult value type
GoogleAuth.Builder(this)
.requestEmail()
.requestProfile()
.enableSmartLock()
.build()
.signIn()
.observe(this, Observer { authResult ->
if (it.isSuccess) {
// Do your further stuff with the [authResult.account] here
} else {
// Handle the [authResult.exception] here
}
})
Call the enableSmartLock() if you want to use Smart Lock for Passwords on Android
Sign Out
Call the signOut() method in the GoogleAuth object. The observable value is Status
googleAuth.logOut()
.observe(this, Observer { status ->
if (it.success) {
// The user has been signed out
} else {
// Show the [status.message] if needed
// Do your stuff on error
}
})
Revoke access
To get access to the revokeAccess() method you need to cast the googleAuth to the GoogleAuth because of the googleAuth represents the abstraction layer class SocialAuth
(googleAuth as GoogleAuth).revokeAccess()
.observe(this, Observer { status ->
if (status.success) {
// Do your stuff on success
} else {
// Do your stuff on error
}
})
this represents the LifecycleOwner