AWS Mobile Hub Google Authentication iOS

192 views Asked by At

I'm trying to implement AWS Mobile Hub in iOS. I see my Identity ID on Identity Browser when clicked "Sign in with Google" button. There is not problem here. Then I want to access GIDGoogleUser. I initialized GIDGoogleUser but I cannot access user info :

 let googleUser = GIDGoogleUser.init()

Then I checked is user logged in with google :

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

I see 'authentication error' output in xcode. Where is my mistake ? And how can I get google user's email and full name ?

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

There are 1 answers

0
smithco On

I have been trying to solve the same problem this week and found that is not actually possible to do with AWSGoogleSignInProvider.

If you go through the AWS Mobile SDK code, you'll find that it maintains an internally declared instance of the GIDGoogleUser singleton. As the GIDGoogleUser in AWS SDK is a separate class declaration, the call to GIDGoogleUser.init() in your code, creates a second instance of that singleton. Bad things happen at that point. Unfortunately, the AWS SDK does not make their internal instance of GIDGoogleUser available through their API.

I'm still looking for a reasonable workaround.