From ad89996020d35ece845bdc63b4e33812c5ad6d9d Mon Sep 17 00:00:00 2001 From: Paul McDonald Date: Tue, 5 Mar 2024 13:46:04 -0800 Subject: [PATCH 01/10] Add scopes. --- lib/src/firebase_authentication_service.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/firebase_authentication_service.dart b/lib/src/firebase_authentication_service.dart index 82aaa51..fccfe6b 100644 --- a/lib/src/firebase_authentication_service.dart +++ b/lib/src/firebase_authentication_service.dart @@ -52,7 +52,7 @@ class FirebaseAuthenticationService { bool get hasUser { return firebaseAuth.currentUser != null; } - + /// Exposes the authStateChanges functionality. Stream get authStateChanges { return firebaseAuth.authStateChanges(); @@ -77,17 +77,18 @@ class FirebaseAuthenticationService { /// - iOS /// - Web Future signInWithGoogle( - {String? webLoginHint}) async { + {String? webLoginHint, List? scopes}) async { try { UserCredential userCredential; - /// On the web, the Firebase SDK provides support for automatically /// handling the authentication flow. if (kIsWeb) { GoogleAuthProvider googleProvider = GoogleAuthProvider(); googleProvider.setCustomParameters( {'login_hint': webLoginHint ?? 'user@example.com'}); - + for (var scope in scopes ?? []) { + googleProvider.addScope(scope); + } userCredential = await FirebaseAuth.instance.signInWithPopup( googleProvider, ); From f5886b589c59760e6ddc14b7027f281a1af7ae83 Mon Sep 17 00:00:00 2001 From: Paul McDonald Date: Tue, 5 Mar 2024 15:46:24 -0800 Subject: [PATCH 02/10] Remove space. --- lib/src/firebase_authentication_service.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/src/firebase_authentication_service.dart b/lib/src/firebase_authentication_service.dart index fccfe6b..0ba99a8 100644 --- a/lib/src/firebase_authentication_service.dart +++ b/lib/src/firebase_authentication_service.dart @@ -52,7 +52,6 @@ class FirebaseAuthenticationService { bool get hasUser { return firebaseAuth.currentUser != null; } - /// Exposes the authStateChanges functionality. Stream get authStateChanges { return firebaseAuth.authStateChanges(); @@ -86,9 +85,7 @@ class FirebaseAuthenticationService { GoogleAuthProvider googleProvider = GoogleAuthProvider(); googleProvider.setCustomParameters( {'login_hint': webLoginHint ?? 'user@example.com'}); - for (var scope in scopes ?? []) { - googleProvider.addScope(scope); - } + (scopes ?? []).forEach(googleProvider.addScope); userCredential = await FirebaseAuth.instance.signInWithPopup( googleProvider, ); From 095a10182399e09f159c795cfab3b71e6979f797 Mon Sep 17 00:00:00 2001 From: Paul McDonald Date: Tue, 5 Mar 2024 16:00:20 -0800 Subject: [PATCH 03/10] Refactor for non-web support --- lib/src/firebase_authentication_service.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/src/firebase_authentication_service.dart b/lib/src/firebase_authentication_service.dart index 0ba99a8..c4d91ee 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( @@ -52,6 +52,7 @@ class FirebaseAuthenticationService { bool get hasUser { return firebaseAuth.currentUser != null; } + /// Exposes the authStateChanges functionality. Stream get authStateChanges { return firebaseAuth.authStateChanges(); @@ -94,8 +95,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( @@ -508,7 +510,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'); From c7b332745667ac452bbdc5b8ce51eabd9a56e2db Mon Sep 17 00:00:00 2001 From: Paul McDonald Date: Tue, 5 Mar 2024 16:30:49 -0800 Subject: [PATCH 04/10] Add oAuthAccessToken to FirebaseAuthenticationResult --- lib/src/firebase_authentication_service.dart | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/src/firebase_authentication_service.dart b/lib/src/firebase_authentication_service.dart index c4d91ee..c997175 100644 --- a/lib/src/firebase_authentication_service.dart +++ b/lib/src/firebase_authentication_service.dart @@ -17,6 +17,7 @@ class FirebaseAuthenticationService { final Logger? log; final firebaseAuth = FirebaseAuth.instance; + String? _oAuthAccessToken; GoogleSignIn? _googleSignIn; FirebaseAuthenticationService({ @@ -35,7 +36,8 @@ class FirebaseAuthenticationService { Future _signInWithCredential( AuthCredential credential, ) async { - return firebaseAuth.signInWithCredential(credential); + _oAuthAccessToken = credential.accessToken; + return await firebaseAuth.signInWithCredential(credential); } /// Returns the current logged in Firebase User @@ -43,6 +45,10 @@ class FirebaseAuthenticationService { return firebaseAuth.currentUser; } + String? get oAuthAccessToken { + return _oAuthAccessToken; + } + /// Returns the latest userToken stored in the Firebase Auth lib Future? get userToken { return firebaseAuth.currentUser?.getIdToken(); @@ -113,6 +119,7 @@ class FirebaseAuthenticationService { idToken: googleSignInAuthentication.idToken, ); + _oAuthAccessToken = googleSignInAuthentication.accessToken; userCredential = await _signInWithCredential(credential); } @@ -125,6 +132,7 @@ class FirebaseAuthenticationService { return FirebaseAuthenticationResult( user: userCredential.user, additionalUserInfo: userCredential.additionalUserInfo, + oAuthAccessToken: userCredential.credential?.accessToken, ); } on FirebaseAuthException catch (e) { log?.e(e); @@ -597,17 +605,19 @@ 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 From 3ddc72757b2a2447aba92ecc46330cac7fbe89de Mon Sep 17 00:00:00 2001 From: Paul McDonald Date: Wed, 6 Mar 2024 09:29:45 -0800 Subject: [PATCH 05/10] Remove oAuthAccessToken getter from class, just pass it back with FirebaseAuthenticationResult --- lib/src/firebase_authentication_service.dart | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/src/firebase_authentication_service.dart b/lib/src/firebase_authentication_service.dart index c997175..e389b06 100644 --- a/lib/src/firebase_authentication_service.dart +++ b/lib/src/firebase_authentication_service.dart @@ -17,7 +17,6 @@ class FirebaseAuthenticationService { final Logger? log; final firebaseAuth = FirebaseAuth.instance; - String? _oAuthAccessToken; GoogleSignIn? _googleSignIn; FirebaseAuthenticationService({ @@ -36,7 +35,6 @@ class FirebaseAuthenticationService { Future _signInWithCredential( AuthCredential credential, ) async { - _oAuthAccessToken = credential.accessToken; return await firebaseAuth.signInWithCredential(credential); } @@ -45,10 +43,6 @@ class FirebaseAuthenticationService { return firebaseAuth.currentUser; } - String? get oAuthAccessToken { - return _oAuthAccessToken; - } - /// Returns the latest userToken stored in the Firebase Auth lib Future? get userToken { return firebaseAuth.currentUser?.getIdToken(); @@ -86,6 +80,7 @@ class FirebaseAuthenticationService { {String? webLoginHint, List? scopes}) async { try { UserCredential userCredential; + /// On the web, the Firebase SDK provides support for automatically /// handling the authentication flow. if (kIsWeb) { @@ -119,7 +114,6 @@ class FirebaseAuthenticationService { idToken: googleSignInAuthentication.idToken, ); - _oAuthAccessToken = googleSignInAuthentication.accessToken; userCredential = await _signInWithCredential(credential); } @@ -611,7 +605,8 @@ class FirebaseAuthenticationResult { final String? errorMessage; final String? exceptionCode; - FirebaseAuthenticationResult({this.user, this.additionalUserInfo, this.oAuthAccessToken}) + FirebaseAuthenticationResult( + {this.user, this.additionalUserInfo, this.oAuthAccessToken}) : errorMessage = null, exceptionCode = null; From 5ce890953f4f7024831639eb89944c2cda857501 Mon Sep 17 00:00:00 2001 From: Paul McDonald Date: Tue, 26 Mar 2024 10:46:55 -0700 Subject: [PATCH 06/10] Update pubspec.yaml --- pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index a57fc2f..db090d5 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/firebase_auth.git issue_tracker: https://github.com/Stacked-Org/framework/issues environment: @@ -32,4 +32,4 @@ dev_dependencies: flutter_test: sdk: flutter -flutter: \ No newline at end of file +flutter: From 12f1653d540bbcc0c94e65519c7d1feeeb8587a0 Mon Sep 17 00:00:00 2001 From: Paul McDonald Date: Tue, 26 Mar 2024 10:47:56 -0700 Subject: [PATCH 07/10] Update pubspec.yaml --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index db090d5..2cf8d7c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,4 +1,4 @@ -name: stacked_firebase_auth +name: firebase_auth description: A service class that provides Firebase Authentication Functionality on a single api version: 2.20.0 homepage: https://stacked.filledstacks.com/ From a59e6404bc9880b1cc7c01b0c9349afd1153906a Mon Sep 17 00:00:00 2001 From: Paul McDonald Date: Tue, 26 Mar 2024 10:49:20 -0700 Subject: [PATCH 08/10] Update pubspec.yaml --- pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 2cf8d7c..1cc1f70 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,8 +1,8 @@ -name: firebase_auth +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/pmmucsd/firebase_auth.git +repository: https://github.com/pmmucsd/stacked_firebase_auth.git issue_tracker: https://github.com/Stacked-Org/framework/issues environment: From 1ce477e4780773dbd83cfac5d26650efd547930c Mon Sep 17 00:00:00 2001 From: Paul McDonald Date: Fri, 15 Nov 2024 17:22:16 -0800 Subject: [PATCH 09/10] Update pubspec.yaml --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 1cc1f70..8f0219a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: sdk: flutter # Firebase - firebase_core: ^2.15.0 + firebase_core: ^3.8.0 firebase_auth: ^4.7.1 firebase_auth_platform_interface: ^7.0.0 From 00bb9147a21b5c7611d35940d19dfa87836cb5ab Mon Sep 17 00:00:00 2001 From: Paul McDonald Date: Fri, 15 Nov 2024 17:24:48 -0800 Subject: [PATCH 10/10] Update pubspec.yaml --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 8f0219a..e246b90 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: # Firebase firebase_core: ^3.8.0 - firebase_auth: ^4.7.1 + firebase_auth: ^5.3.3 firebase_auth_platform_interface: ^7.0.0 # Firebase Authentications