AWS Mobile Hub Google身份验证iOS

时间:2017-09-13 08:03:27

标签: swift amazon-web-services aws-sdk-ios

我正在尝试在iOS中实施AWS Mobile Hub。单击“使用Google登录”按钮时,我会在Identity Browser上看到我的身份ID。这里没有问题。然后我想访问GIDGoogleUser。我初始化了GIDGoogleUser但我无法访问用户信息:

 let googleUser = GIDGoogleUser.init()

然后我检查了用户是否使用google登录:

    if(AWSGoogleSignInProvider.init().isLoggedIn){
         print("Success")
}else{
         print("Authentication error")
}

我在xcode中看到'身份验证错误'输出。我的错误在哪里?我怎样才能获得谷歌用户的电子邮件和全名?

AppDelegate.swift:

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        AWSGoogleSignInProvider.sharedInstance().setScopes(["profile","email", "openid"])
  AWSSignInManager.sharedInstance().register(
            signInProvider: AWSGoogleSignInProvider.sharedInstance())


 let didFinishLaunching = AWSSignInManager.sharedInstance().interceptApplication(
                application, didFinishLaunchingWithOptions: launchOptions)

        if (!isInitialized) {
            AWSSignInManager.sharedInstance().resumeSession(completionHandler: {
                (result: Any?, error: Error?) in
                print("Result: \(result) \n Error:\(error)")
            })
            isInitialized = true
        }

        return didFinishLaunching
}

1 个答案:

答案 0 :(得分:0)

本周我一直试图解决同样的问题,发现实际上不可能使用AWSGoogleSignInProvider。

如果您浏览AWS Mobile SDK代码,则会发现它维护了内部声明的GIDGoogleUser单例实例。由于AWS开发工具包中的GIDGoogleUser是一个单独的类声明,因此在代码中调用GIDGoogleUser.init()会创建该单例的第二个实例。那时发生了不好的事情。遗憾的是,AWS SDK不会通过其API提供GIDGoogleUser的内部实例。

我仍在寻找合理的解决方法。