android - 获取 Google 签名的用户信息
问题描述
我有一个应用程序可以获取 Google 凭据,以便将用户注册到我的 API。我需要idToken
谷歌流程提供的。
按照本教程,我能够登录。
然后,我有一个启动画面。我希望它验证用户是否已被 Google 允许进入主要活动。如果没有,请转到登录活动。
但是根据教程的代码,它使用下面的代码询问 Firebase,它当然为我提供了一个 Firebase 令牌,而不是 Google 令牌。
override fun onStart() {
super.onStart()
val user = FirebaseAuth.getInstance().currentUser
if (user != null) {
startActivity(MainActivity.getLaunchIntent(this))
finish()
}
}
所以,问题是:如何获取谷歌信息来检索令牌,以便我的 API 可以验证令牌是否?
解决方案
If someone else need to implements something alike, I'll share how I did it.
There is a silentSignIn
from Google SDK which allows to do it.
So, this is the code:
val signInOptions = getSignInOptions(this)
val googleSignInClient = GoogleSignIn.getClient(this, signInOptions)
googleSignInClient.silentSignIn().addOnCompleteListener {
val account: GoogleSignInAccount? = it.result
if (account != null) {
// success
}
else {
// failure
}
}
推荐阅读
- python - 如何在 Python3 中编码十六进制?
- c# - C# 将默认命名空间转换为前缀命名空间
- python - 检测图像中的多个矩形
- reactjs - 自定义排序函数的排序顺序 Ag-grid
- swiftui - SwiftUI - 属性更改时视图不刷新
- c++ - 错误:没有匹配函数调用 'es_queue::set_rpc_vector(std::vector >&, std::__cxx11::string)'
- angular6 - 如何在 Angular 8 中实现 PayUMoney 支付网关
- reactjs - 如何使用 Enzyme 和 Jest 测试回调 refs
- php - 回显 PHP 字符串值作为悬停时的标题?
- c# - RDLC 导出为具有高分辨率背景图像的 pdf