gpt4 book ai didi

ios - 为什么 Google 登录用户没有显示在用户池中?

转载 作者:行者123 更新时间:2023-11-28 23:29:23 26 4
gpt4 key购买 nike

我正在尝试通过 Swift 在我的 iOS 应用程序中实现 AWS Cognito。

我按照 AWS Amplify iOS SDK document 中所示的步骤操作, 和 Google Sign-in for iOS Guides .

现在我可以在我的应用程序中使用 google 帐户登录用户,并且我使用 AWSMobileClient.sharedInstance().federatedSignIn() 方法尝试将用户添加到我的用户池和 ID 池中。 (我不确定这是实现此目的的正确方法...但是下面程序中的“联合登录正常!!!”行确实打印出来了。)

问题是用户使用 Google 帐户登录后,我在 AWS 控制台中看不到任何信息。我的用户池和 ID 池中的数字没有增加。在我的用户池中自动创建了一个 Google 用户组,但其中没有任何用户。

谁能告诉我我错过了什么?谢谢!

AppDelegate.swift

class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let error = error {
print("\(error.localizedDescription)")
} else {
let userId = user.userID
let idToken = user.authentication.idToken
let fullName = user.profile.name
let givenName = user.profile.givenName
let familyName = user.profile.familyName
let email = user.profile.email
}
}

func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!,
withError error: Error!) {
print(error.localizedDescription)
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url as URL?,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation])
}
}

登录VC.swift

import UIKit
import AWSMobileClient
import GoogleSignIn

class SignInVC: UIViewController, GIDSignInUIDelegate, GIDSignInDelegate {
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance()?.delegate = self
GIDSignIn.sharedInstance().uiDelegate = self
}

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let error = error {
print("\(error.localizedDescription)")
} else {
let idToken = user.authentication.idToken

AWSMobileClient.sharedInstance().federatedSignIn(providerName: IdentityProvider.google.rawValue, token: idToken!) { (userState, error) in
if let error = error {
print("Federated Sign In failed: \(error.localizedDescription)")
}
else {
print("Federated Signin is OK!!!")
}
}
}
}
func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!,
withError error: Error!) {
print(error.localizedDescription)
}

@IBOutlet weak var googleSignInButton: GIDSignInButton!
@IBAction func GIDSignInButtontap(_ sender: Any) {
GIDSignIn.sharedInstance()?.signIn()
}
@IBAction func googleSignOutButton(_ sender: Any) {
GIDSignIn.sharedInstance()?.signOut()
}
}

最佳答案

不幸的是,federatedSignIn() 方法名称有点误导。如 the doc 中所述,它目前仅适用于 Cognito Identity Pool :

Currently, the federation feature in the AWSMobileClient supports Cognito Identity Pools only.

我可以重现您遇到的行为。查看源码on this commit .

When looking at the Amplify source code ,此方法仅跟踪状态并注册 token 。即使您传递了无效的 token (我尝试使用 000),它也不会返回任何错误

也不可能获得 JWT token ,这被跟踪为功能请求:https://github.com/aws-amplify/aws-sdk-ios/issues/1128

我可以考虑三种解决方法:

  • 改用 AWSCognitoAuth 类。
  • 使用 Amplify 提供的 UI(仅限 Cognito 用户池身份验证,无联合选项)
  • 使用 Cognito 托管 UI(请参阅 working code here)

Cognito 托管 UI 允许执行联合登录或 Cognito 登录。上面的链接是一个完整的工作项目,例如。

关于ios - 为什么 Google 登录用户没有显示在用户池中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57344835/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com