From fbcbfc15811d843e4f4a6cc567773316ff18ef7d Mon Sep 17 00:00:00 2001 From: Rafael Milia Date: Fri, 18 Oct 2024 15:40:41 +0200 Subject: [PATCH] Update GoogleSignIn pod to 7.1.0 --- CodetrixStudioCapacitorGoogleAuth.podspec | 2 +- ios/Plugin/Plugin.swift | 45 ++++++++++++----------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/CodetrixStudioCapacitorGoogleAuth.podspec b/CodetrixStudioCapacitorGoogleAuth.podspec index 6432925..acb8cf6 100644 --- a/CodetrixStudioCapacitorGoogleAuth.podspec +++ b/CodetrixStudioCapacitorGoogleAuth.podspec @@ -10,6 +10,6 @@ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}' s.ios.deployment_target = '12.0' s.dependency 'Capacitor' - s.dependency 'GoogleSignIn', '~> 6.2.4' + s.dependency 'GoogleSignIn', '~> 7.1.0' s.static_framework = true end diff --git a/ios/Plugin/Plugin.swift b/ios/Plugin/Plugin.swift index be9b54d..8eb048d 100644 --- a/ios/Plugin/Plugin.swift +++ b/ios/Plugin/Plugin.swift @@ -77,18 +77,26 @@ public class GoogleAuth: CAPPlugin { self.signInCall?.reject(error.localizedDescription); return; } - self.resolveSignInCallWith(user: user!) + self.resolveSignInCallWith(user: user!, serverAuthCode: nil) } } else { let presentingVc = self.bridge!.viewController!; - self.googleSignIn.signIn(with: self.googleSignInConfiguration, presenting: presentingVc, hint: nil, additionalScopes: self.additionalScopes) { user, error in + self.googleSignIn.signIn( + withPresenting: presentingVc, + hint: nil, + additionalScopes: self.additionalScopes + ) { signInResult, error in if let error = error { self.signInCall?.reject(error.localizedDescription, "\(error._code)"); return; } - self.resolveSignInCallWith(user: user!); - }; + + let user = signInResult?.user; + let serverAuthCode = signInResult?.serverAuthCode; + + self.resolveSignInCallWith(user: user!, serverAuthCode: serverAuthCode); + } } } } @@ -100,18 +108,13 @@ public class GoogleAuth: CAPPlugin { call.reject("User not logged in."); return } - self.googleSignIn.currentUser!.authentication.do { (authentication, error) in - guard let authentication = authentication else { - call.reject(error?.localizedDescription ?? "Something went wrong."); - return; - } - let authenticationData: [String: Any] = [ - "accessToken": authentication.accessToken, - "idToken": authentication.idToken ?? NSNull(), - "refreshToken": authentication.refreshToken - ] - call.resolve(authenticationData); - } + + let authenticationData: [String: Any] = [ + "accessToken": self.googleSignIn.currentUser!.accessToken, + "idToken": self.googleSignIn.currentUser!.idToken ?? NSNull(), + "refreshToken": self.googleSignIn.currentUser!.refreshToken + ] + call.resolve(authenticationData); } } @@ -161,14 +164,14 @@ public class GoogleAuth: CAPPlugin { return nil; } - func resolveSignInCallWith(user: GIDGoogleUser) { + func resolveSignInCallWith(user: GIDGoogleUser, serverAuthCode: String?) { var userData: [String: Any] = [ "authentication": [ - "accessToken": user.authentication.accessToken, - "idToken": user.authentication.idToken, - "refreshToken": user.authentication.refreshToken + "accessToken": user.accessToken.tokenString, + "idToken": user.idToken?.tokenString, + "refreshToken": user.refreshToken.tokenString ], - "serverAuthCode": user.serverAuthCode ?? NSNull(), + "serverAuthCode": serverAuthCode ?? NSNull(), "email": user.profile?.email ?? NSNull(), "familyName": user.profile?.familyName ?? NSNull(), "givenName": user.profile?.givenName ?? NSNull(),