Skip to content

Instantly share code, notes, and snippets.

@adrianhall
Last active September 18, 2018 20:07
Show Gist options
  • Select an option

  • Save adrianhall/807b2d8ced8e2b0a15dde001a45f23b7 to your computer and use it in GitHub Desktop.

Select an option

Save adrianhall/807b2d8ced8e2b0a15dde001a45f23b7 to your computer and use it in GitHub Desktop.
/**
* Federate with Google authentication
*/
override fun federateWithGoogle(account: GoogleSignInAccount) {
if (account.idToken != null) {
Log.d(TAG, "Federating with Google")
thread(start = true) {
with(service.identityManager.underlyingProvider) {
clear()
withLogins(mapOf("accounts.google.com" to account.idToken))
refresh()
}
val user = User().apply {
username = account.id!!
tokens[TokenType.ACCESS_TOKEN] = account.idToken!!
userAttributes["provider"] = "accounts.google.com"
userAttributes["email"] = account.email!!
}
Log.d(TAG, "Federated result: ${service.identityManager.isUserSignedIn}")
runOnUiThread { mCurrentUser.postValue(user) }
}
} else {
Log.d(TAG, "Federating with Google (ID token is null, so nothing happening)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment