diff --git a/lib/src/firebase_authentication_service.dart b/lib/src/firebase_authentication_service.dart index 82aaa51..e389b06 100644 --- a/lib/src/firebase_authentication_service.dart +++ b/lib/src/firebase_authentication_service.dart @@ -17,7 +17,7 @@ class FirebaseAuthenticationService { final Logger? log; final firebaseAuth = FirebaseAuth.instance; - final GoogleSignIn _googleSignIn = GoogleSignIn(); + GoogleSignIn? _googleSignIn; FirebaseAuthenticationService({ @Deprecated( @@ -35,7 +35,7 @@ class FirebaseAuthenticationService { Future _signInWithCredential( AuthCredential credential, ) async { - return firebaseAuth.signInWithCredential(credential); + return await firebaseAuth.signInWithCredential(credential); } /// Returns the current logged in Firebase User @@ -77,7 +77,7 @@ class FirebaseAuthenticationService { /// - iOS /// - Web Future signInWithGoogle( - {String? webLoginHint}) async { + {String? webLoginHint, List? scopes}) async { try { UserCredential userCredential; @@ -87,7 +87,7 @@ class FirebaseAuthenticationService { GoogleAuthProvider googleProvider = GoogleAuthProvider(); googleProvider.setCustomParameters( {'login_hint': webLoginHint ?? 'user@example.com'}); - + (scopes ?? []).forEach(googleProvider.addScope); userCredential = await FirebaseAuth.instance.signInWithPopup( googleProvider, ); @@ -96,8 +96,9 @@ class FirebaseAuthenticationService { /// On native platforms, a 3rd party library, like GoogleSignIn, is /// required to trigger the authentication flow. else { + _googleSignIn = GoogleSignIn(scopes: scopes ?? []); final GoogleSignInAccount? googleSignInAccount = - await _googleSignIn.signIn(); + await _googleSignIn!.signIn(); if (googleSignInAccount == null) { log?.i('Process is canceled by the user'); return FirebaseAuthenticationResult.error( @@ -125,6 +126,7 @@ class FirebaseAuthenticationService { return FirebaseAuthenticationResult( user: userCredential.user, additionalUserInfo: userCredential.additionalUserInfo, + oAuthAccessToken: userCredential.credential?.accessToken, ); } on FirebaseAuthException catch (e) { log?.e(e); @@ -510,7 +512,7 @@ class FirebaseAuthenticationService { try { _clearPendingData(); await firebaseAuth.signOut(); - await _googleSignIn.signOut(); + await _googleSignIn?.signOut(); await FacebookAuth.instance.logOut(); } catch (e) { log?.e('Could not sign out of social account. $e'); @@ -597,17 +599,20 @@ class FirebaseAuthenticationResult { /// Firebase additional user information final AdditionalUserInfo? additionalUserInfo; + final String? oAuthAccessToken; /// Contains the error message for the request final String? errorMessage; final String? exceptionCode; - FirebaseAuthenticationResult({this.user, this.additionalUserInfo}) + FirebaseAuthenticationResult( + {this.user, this.additionalUserInfo, this.oAuthAccessToken}) : errorMessage = null, exceptionCode = null; FirebaseAuthenticationResult.error({this.errorMessage, this.exceptionCode}) : user = null, + oAuthAccessToken = null, additionalUserInfo = null; /// Returns true if the response has an error associated with it diff --git a/pubspec.yaml b/pubspec.yaml index a57fc2f..e246b90 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: stacked_firebase_auth description: A service class that provides Firebase Authentication Functionality on a single api version: 2.20.0 homepage: https://stacked.filledstacks.com/ -repository: https://github.com/Stacked-Org/firebase_auth.git +repository: https://github.com/pmmucsd/stacked_firebase_auth.git issue_tracker: https://github.com/Stacked-Org/framework/issues environment: @@ -13,8 +13,8 @@ dependencies: sdk: flutter # Firebase - firebase_core: ^2.15.0 - firebase_auth: ^4.7.1 + firebase_core: ^3.8.0 + firebase_auth: ^5.3.3 firebase_auth_platform_interface: ^7.0.0 # Firebase Authentications @@ -32,4 +32,4 @@ dev_dependencies: flutter_test: sdk: flutter -flutter: \ No newline at end of file +flutter: