Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GoogleSignIn pod to 7.1.0 #403

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CodetrixStudioCapacitorGoogleAuth.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,11 @@ or see more [CapacitorGoogleAuth-Vue3-example](https://github.com/reslear/Capaci

1. Create in Google cloud console credential **Client ID for iOS** and get **Client ID** and **iOS URL scheme**

2. Add **identifier** `REVERSED_CLIENT_ID` as **URL schemes** to `Info.plist` from **iOS URL scheme**<br>
(Xcode: App - Targets/App - Info - URL Types, click plus icon)
2. Add **identifier** `GIDClientID` to `Info.plist`<br>
`<key>GIDClientID</key><string>VALUE</string>`

3. Set **Client ID** one of the ways (by order of importance in the plugin):
1. Set `clientId` in initialize method
2. Set `iosClientId` in `capacitor.config.json`
3. Set `clientId` in `capacitor.config.json`
4. Set `CLIENT_ID` in `GoogleService-Info.plist`
3. Add **identifier** `REVERSED_CLIENT_ID` as **URL schemes** to `Info.plist` from **iOS URL scheme**<br>
(Xcode: App - Targets/App - Info - URL Types, click plus icon)

### Android

Expand Down
45 changes: 24 additions & 21 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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(),
Expand Down