stacked_firebase_auth
単一の API で Firebase 認証機能を提供するサービスクラス
このパッケージは、さまざまなログインメカニズムと併用可能な `FirebaseAuthenticationService` を提供します。
{"sdk":"flutter"}^3.4.0^5.2.0^7.0.0^6.2.1^6.1.1^6.2.0^2.3.0^3.0.3^4.0.0{"sdk":"flutter"}以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。
This package is meant to work with the Stacked framework and provides a FirebaseAuthenticationService that provides the following logins:
It wraps the functionality for those four auth providers. Examples to come soon. This package has initially been published to improve the BoxtOut tutorial for setting up Firebase Auth.
This package is relying on the following great packages to support the social providers:
Build section, chose Authentication, then click on Get started to enable it.You can find official doc and information on https://firebase.google.com/docs/auth.
💡 More info about this process here: https://firebase.google.com/docs/flutter/setup
firebase login.dart pub global activate flutterfire_cli.flutterfire configure. You will be asked to select the project you want to configure and the platforms you want to enable.lib/main.dart, you will now be able to add await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); to initialise the default instance of Firebase.// Add those imports
import 'package:example/firebase_options.dart';
import 'package:firebase_core/firebase_core.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// Add this line
Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
await setupLocator();
setupDialogUi();
setupBottomSheetUi();
runApp(const MainApp());
}
ios\Podfile to include platform :ios, '12.0'android/app/build.gradle to define minSdkVersion to 21defaultConfig {
...
minSdkVersion 21
targetSdkVersion 33
...
}
flutter pub add stacked_firebase_auth to add the package to your dependencieslib\app\app.dart file, add LazySingleton(classType: FirebaseAuthenticationService),at the end of the dependencies list.@StackedApp(
routes: [ ... ],
dependencies: [
// Other dependencies
LazySingleton(classType: FirebaseAuthenticationService),
],
bottomsheets: [ ... ],
dialogs: [ ... ],
)
class App {}
stacked generateFirebaseAuthenticationService from locator<FirebaseAuthenticationService>().Note that according to https://developer.apple.com/sign-in-with-apple/get-started, starting June 30, 2020, apps that use login services must also offer a "Sign in with Apple" option when submitting to the Apple App Store.
This package is heavily relying on google_sign_in. Please follow the configuration process described on their doc the the platforms you want to support.
You will find how-to
flutterfire configure again to update config filesios/Runner/Info.plistOnce done you can use the following method to trigger Google Sign-in flow:
Future<FirebaseAuthenticationResult> signInWithGoogle({String? webLoginHint})
This package is heavily relying on sign_in_with_apple. Please follow the configuration process described on their doc the the platforms you want to support.
You will find how-to
To know if Apple Signin is available on the platform and if you need to display the button, you can use
Future<bool> isAppleSignInAvailable()
Then, to trigger the flow, just use
Future<FirebaseAuthenticationResult> signInWithApple({
required String? appleRedirectUri,
required String? appleClientId,
bool askForFullName = true,
})
This package is heavily relying on flutter_facebook_auth. Please follow the configuration process described on their doc the the platforms you want to support.
You will find how-to
ios/Runner/Info.plist,/android/app/src/main/res/values/strings.xml and /android/app/src/main/AndroidManifest.xml)Once done you can use the following method to trigger Facebook Sign-in flow:
Future<FirebaseAuthenticationResult> signInWithFacebook({String? webLoginHint})
💡 More info about this authentication here: https://firebase.google.com/docs/auth/flutter/password-auth
loginWithEmail({required String email, required String password})createAccountWithEmail({required String email, required String password})sendResetPasswordLink(String email)validatePassword(String password)updatePassword(String password)updateEmail(String email)updateDisplayName(String displayName)updatePhotoURL(String photoUrl)💡 More info about this authentication here: https://firebase.google.com/docs/auth/flutter/anonymous-auth
loginAnonymously() to enable the flowFuture logout() to logout.signInWithGoogleMake sure you enabled Google provider on your Firebase App > Authentication.
Then, make sure you followed the iOS integration and included required keys in ios/Runner/Info.plist.
You need to have the following configuration:
<!-- Google Signin Configuration -->
<key>GIDClientID</key>
<string>[YOUR IOS CLIENT ID]</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<!-- TODO Replace this value: -->
<!-- Copied from GoogleService-Info.plist key REVERSED_CLIENT_ID -->
<string>com.googleusercontent.apps.[REVERSED_CLIENT_ID]</string>
</array>
</dict>
</array>
<!-- @END Google Signin Configuration -->
signInWithFacebookMake sure you enabled Facebook provider on your Firebase App > Authentication.
Then, make sure you followed the iOS integration and included required keys in ios/Runner/Info.plist.
You need to have the following configuration:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb{your-app-id}</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>{your-app-id}</string>
<key>FacebookClientToken</key>
<string>CLIENT-TOKEN</string>
<key>FacebookDisplayName</key>
<string>{your-app-name}</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
</array>
CFBundleURLSchemes in ios/Runner/Info.plist when using both Facebook and Google?You should merge values in Info.plist, instead of adding a duplicate key.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb{your-app-id}</string>
<string>com.googleusercontent.apps.[REVERSED_CLIENT_ID]</string>
</array>
</dict>
</array>
Make sure you enabled Google provider on your Firebase App > Authentication.
The following message might appear: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10:, null, null).
To solve that, make sure you added correctly the SHA1 or SHA256 signature of your app in the Android app configuration in Firebase.
More info here: https://developers.google.com/android/guides/client-auth.
⚠️ Debug and prod build have different SHA signatures.
FirebaseAuthenticationResultflutter_facebook_auth dependency and its implementationflutter_facebook_auth dependency and its implementation since it was causing a MissingPluginException if the app isn't setup for Facebook Authℹ️ For the full changelog, see CHANGELOG.md.