@@ -8,38 +8,43 @@ import GoogleSignIn
88 */
99@objc ( GoogleAuth)
1010public class GoogleAuth : CAPPlugin {
11- var pluginCall : CAPPluginCall ?
11+ var signInCall : CAPPluginCall ?
12+ let googleSignIn : GIDSignIn = GIDSignIn . sharedInstance ( ) ;
1213
1314 public override func load( ) {
1415 guard let path = Bundle . main. path ( forResource: " GoogleService-Info " , ofType: " plist " ) else { return }
1516 guard let dict = NSDictionary ( contentsOfFile: path) as? [ String : AnyObject ] else { return }
1617 guard let clientId = dict [ " CLIENT_ID " ] as? String else { return }
1718
18- GIDSignIn . sharedInstance ( ) . clientID = clientId;
19- GIDSignIn . sharedInstance ( ) . delegate = self ;
20- GIDSignIn . sharedInstance ( ) . uiDelegate = self ;
19+ googleSignIn. clientID = clientId;
20+ googleSignIn. delegate = self ;
21+ googleSignIn. uiDelegate = self ;
22+
23+ if let scopes = getConfigValue ( " scopes " ) as? [ String ] {
24+ googleSignIn. scopes = scopes;
25+ }
2126
2227 NotificationCenter . default. addObserver ( self , selector: #selector( handleOpenUrl ( _ : ) ) , name: Notification . Name ( CAPNotifications . URLOpen. name ( ) ) , object: nil ) ;
2328 }
2429
2530 @objc
2631 func signIn( _ call: CAPPluginCall ) {
27- pluginCall = call;
32+ signInCall = call;
2833
2934 DispatchQueue . main. async {
30- if GIDSignIn . sharedInstance ( ) . hasAuthInKeychain ( ) {
31- GIDSignIn . sharedInstance ( ) . signInSilently ( ) ;
35+ if self . googleSignIn . hasAuthInKeychain ( ) {
36+ self . googleSignIn . signInSilently ( ) ;
3237 } else {
33- GIDSignIn . sharedInstance ( ) . signIn ( ) ;
38+ self . googleSignIn . signIn ( ) ;
3439 }
3540 }
3641 }
3742
3843 @objc
3944 func signOut( _ call: CAPPluginCall ) {
4045 DispatchQueue . main. async {
41- GIDSignIn . sharedInstance ( ) . signOut ( ) ;
42- }
46+ self . googleSignIn . signOut ( ) ;
47+ }
4348 call. success ( ) ;
4449 }
4550
@@ -61,11 +66,11 @@ public class GoogleAuth: CAPPlugin {
6166 }
6267
6368 let sourceApplication = options [ UIApplication . OpenURLOptionsKey. sourceApplication] as? String ;
64- GIDSignIn . sharedInstance ( ) . handle ( url, sourceApplication: sourceApplication, annotation: [ : ] ) ;
69+ googleSignIn . handle ( url, sourceApplication: sourceApplication, annotation: [ : ] ) ;
6570 }
6671
6772 func processCallback( user: GIDGoogleUser ) {
68- pluginCall ? . success ( [
73+ signInCall ? . success ( [
6974 " authentication " : [
7075 " accessToken " : user. authentication. accessToken,
7176 " idToken " : user. authentication. idToken,
@@ -78,7 +83,7 @@ public class GoogleAuth: CAPPlugin {
7883extension GoogleAuth : GIDSignInDelegate {
7984 public func sign( _ signIn: GIDSignIn ! , didSignInFor user: GIDGoogleUser ! , withError error: Error ! ) {
8085 if let error = error {
81- pluginCall ? . error ( error. localizedDescription) ;
86+ signInCall ? . error ( error. localizedDescription) ;
8287 return ;
8388 }
8489
0 commit comments