我想在我的android应用程序中实现GoogleSignIn功能,但是在Amazon Amplify auth文档中,没有明确的方法逐步执行此操作。 我认为有多种方法可以在Android应用程序中添加GoogleSignIn。1. AndroidClient SDK,2. OAuth(带有WebView)。 3. SignInUI
但是我想使用GoogleSignIn SDK执行此操作,目前我正在执行此步骤,使用Google android客户端登录google是否正确? :
我由于federatedSignIn方法而获得了令牌,并且我的亚马逊auth sdk全局初始化回调状态已更改为经过身份验证,但该令牌对后端无效,我认为它是Google原始令牌,没有任何更改。
fun cognitoAuthWithGoogle(account: GoogleSignInAccount) {
var idToken = account.idToken
AWSMobileClient.getInstance().federatedSignIn(IdentityProvider.GOOGLE.toString(), idToken, object : Callback<UserStateDetails> {
override fun onResult(result: UserStateDetails?) {
result.toString()
}
override fun onError(e: java.lang.Exception?) {
e?.printStackTrace()
}
})
}
fun initGoogleSignIn() {
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build()
var mGoogleSignInClient = GoogleSignIn.getClient(this, gso)
loginGoogleButton.setOnClickListener {
val signInIntent = mGoogleSignInClient.signInIntent
startActivityForResult(signInIntent, 100)
}
}
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
AWSMobileClient.getInstance().handleAuthResponse(data)
if (requestCode == 100) {
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
try {
val account = task.getResult(ApiException::class.java)
account.toString()
cognitoAuthWithGoogle(account!!)
} catch (e: ApiException) {
// Google Sign In failed, update UI appropriately
Log.w(TAG, "Google sign in failed", e)
// ...
}
}
}