firebase_auth 0.8.0+3

firebase_auth plugin #

A Flutter plugin to use the Firebase Authentication API.

pub package

For Flutter plugins for other Firebase products, see

Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!

Usage #

Configure the Google sign-in plugin #

The Google Sign-in plugin is required to use the firebase_auth plugin. Follow the Google sign-in plugin installation instructions.

Import the firebase_auth plugin #

To use the firebase_auth plugin, follow the plugin installation instructions.

Android integration #

Enable the Google services by configuring the Gradle scripts as such.

  1. Add the classpath to the [project]/android/build.gradle file.
dependencies {
  // Example existing classpath
  classpath ''
  // Add the google services classpath
  classpath ''
  1. Add the apply plugin to the [project]/android/app/build.gradle file.
apply plugin: ''

Note: If this section is not completed you will get an error like this:

Default FirebaseApp is not initialized in this process [package name].
Make sure to call FirebaseApp.initializeApp(Context) first.

Note: When you are debugging on android, use a device or AVD with Google Play services. Otherwise you will not be able to authenticate.

Use the plugin #

Add the following imports to your Dart code:

import 'package:firebase_auth/firebase_auth.dart';

Initialize GoogleSignIn and FirebaseAuth:

final GoogleSignIn _googleSignIn = GoogleSignIn();
final FirebaseAuth _auth = FirebaseAuth.instance;

You can now use the Firebase _auth to authenticate in your Dart code, e.g.

Future<FirebaseUser> _handleSignIn() async {
  final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
  final GoogleSignInAuthentication googleAuth = await googleUser.authentication;

  final AuthCredential credential = GoogleAuthProvider.getCredential(
    accessToken: googleAuth.accessToken,
    idToken: googleAuth.idToken,
  final FirebaseUser user = await _auth.signInWithCredential(credential);
  print("signed in " + user.displayName);
  return user;

Then from the sign in button onPress, call the _handleSignIn method using a future callback for both the FirebaseUser and possible exception.

    .then((FirebaseUser user) => print(user))
    .catchError((e) => print(e));

Phone Auth #

You can use Firebase Authentication to sign in a user by sending an SMS message to the user's phone. The user signs in using a one-time code contained in the SMS message.

iOS setup #

  1. Enable Phone as a Sign-In method in the Firebase console
  • When testing you can add test phone numbers and verification codes to the Firebase console.
  1. Enable App verification

Note: App verification may use APNs, if using a simulator (where APNs does not work) or APNs is not setup on the device you are using you must set the URL Schemes to the REVERSE_CLIENT_ID from the GoogleServices-Info.plist file.

Android setup #

  1. Enable Phone as a Sign-In method in the Firebase console
  • When testing you can add test phone numbers and verification codes to the Firebase console.

Example #

See the example application source for a complete sample app using the Firebase authentication.

Issues and feedback #

Please file issues to send feedback or report a bug. Thank you!

0.8.0+3 #

  • Log a more detailed warning at build time about the previous AndroidX migration.

0.8.0+2 #

  • Update Google sign-in example in the README.

0.8.0+1 #

  • Update a broken dependency.

0.8.0 #

  • Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library.

0.7.0 #

  • Introduce third-party auth provider classes that generate AuthCredentials
  • Breaking Change Signing in, linking, and reauthenticating now require an AuthCredential
  • Breaking Change Unlinking now uses providerId
  • Breaking Change Moved reauthentication to FirebaseUser

0.6.7 #

  • FirebaseAuth and FirebaseUser are now fully documented.
  • PlatformExceptions now report error codes as stated in docs.
  • Credentials can now be unlinked from Accounts with new methods on FirebaseUser.

0.6.6 #

  • Users can now reauthenticate in response to operations that require a recent sign-in.

0.6.5 #

  • Fixing async method verifyPhoneNumber, that would never return even in a successful call.

0.6.4 #

  • Added support for Github signin and linking Github accounts to existing users.

0.6.3 #

  • Add multi app support.

0.6.2+1 #

  • Bump Android dependencies to latest.

0.6.2 #

  • Add access to user metadata.

0.6.1 #

  • Adding support for linkWithTwitterCredential in FirebaseAuth.

0.6.0 #

  • Added support for updatePassword in FirebaseUser.
  • Breaking Change Moved updateEmail and updateProfile to FirebaseUser. This brings the firebase_auth package inline with other implementations and documentation.

0.5.20 #

  • Replaced usages of guava's: ImmutableList and ImmutableMap with platform Collections.unmodifiableList() and Collections.unmodifiableMap().

0.5.19 #

  • Update test package dependency to pick up Dart 2 support.
  • Modified dependency on google_sign_in to point to a published version instead of a relative path.

0.5.18 #

  • Adding support for updateEmail in FirebaseAuth.

0.5.17 #

  • Adding support for FirebaseUser.delete.

0.5.16 #

  • Adding support for setLanguageCode in FirebaseAuth.

0.5.15 #

  • Bump Android and Firebase dependency versions.

0.5.14 #

  • Fixed handling of auto phone number verification.

0.5.13 #

  • Add support for phone number authentication.

0.5.12 #

  • Fixed ArrayIndexOutOfBoundsException in handleStopListeningAuthState

0.5.11 #

  • Updated Gradle tooling to match Android Studio 3.1.2.

0.5.10 #

  • Updated iOS implementation to reflect Firebase API changes.

0.5.9 #

  • Added support for signing in with a Twitter account.

0.5.8 #

  • Added support to reload firebase user

0.5.7 #

  • Added support to sendEmailVerification

0.5.6 #

  • Added support for linkWithFacebookCredential

0.5.5 #

  • Updated Google Play Services dependencies to version 15.0.0.

0.5.4 #

  • Simplified podspec for Cocoapods 1.5.0, avoiding link issues in app archives.

0.5.3 #

  • Secure fetchProvidersForEmail (no providers)

0.5.2 #

  • Fixed Dart 2 type error in fetchProvidersForEmail.

0.5.1 #

  • Added support to fetchProvidersForEmail

0.5.0 #

  • Breaking change. Set SDK constraints to match the Flutter beta release.

0.4.7 #

  • Fixed Dart 2 type errors.

0.4.6 #

  • Fixed Dart 2 type errors.

0.4.5 #

  • Enabled use in Swift projects.

0.4.4 #

  • Added support for sendPasswordResetEmail

0.4.3 #

  • Moved to the io.flutter.plugins organization.

0.4.2 #

  • Added support for changing user data

0.4.1 #

  • Simplified and upgraded Android project template to Android SDK 27.
  • Updated package description.

0.4.0 #

  • Breaking change. Upgraded to Gradle 4.1 and Android Studio Gradle plugin 3.0.1. Older Flutter projects need to upgrade their Gradle setup as well in order to use this version of the plugin. Instructions can be found here.
  • Relaxed GMS dependency to [11.4.0,12.0[

0.3.2 #

  • Added FLT prefix to iOS types
  • Change GMS dependency to 11.4.+

0.3.1 #

  • Change GMS dependency to 11.+

0.3.0 #

  • Breaking Change: Method FirebaseUser getToken was renamed to getIdToken.

0.2.5 #

  • Added support for linkWithCredential with Google credential

0.2.4 #

  • Added support for signInWithCustomToken
  • Added Stream<FirebaseUser> onAuthStateChanged event to listen when the user change

0.2.3+1 #

  • Aligned author name with rest of repo.

0.2.3 #

  • Remove dependency on Google/SignIn

0.2.2 #

  • Remove dependency on FirebaseUI

0.2.1 #

  • Added support for linkWithEmailAndPassword

0.2.0 #

  • Breaking Change: Method currentUser is async now.

0.1.2 #

  • Added support for signInWithFacebook

0.1.1 #

  • Updated to Firebase SDK to always use latest patch version for 11.0.x builds

0.1.0 #

  • Updated to Firebase SDK Version 11.0.1
  • Breaking Change: You need to add a maven section with the "" endpoint to the repository section of your android/build.gradle. For example:
allprojects {
    repositories {
        maven {                              // NEW
            url ""   // NEW
        }                                    // NEW

0.0.4 #

  • Add method getToken() to FirebaseUser

0.0.3+1 #

  • Updated

0.0.3 #

  • Added support for createUserWithEmailAndPassword, signInWithEmailAndPassword, and signOut Firebase methods

0.0.2+1 #

  • Updated

0.0.2 #

  • Bump buildToolsVersion to 25.0.3

0.0.1 #

  • Initial Release


firebase_auth_example #

pub package

Demonstrates how to use the firebase_auth plugin.

Phone Auth #

  1. Enable phone authentication in the Firebase console.
  2. Add test phone number and verification code to the Firebase console.
  • For this sample the number +1 408-555-6969 and verification code 888888 are used.
  1. For iOS set the URL Schemes to the REVERSE_CLIENT_ID from the GoogleServices-Info.plist file.
  2. Click the Test verifyPhoneNumber button.
  • If APNs is not enabled or a simulator is being used, verification will be done via a Captcha.
  1. Once the phone number is verified the app displays the test verification code.
  2. Click the Test signInWithPhoneNumber button.
  3. Signed in user's details are displayed in the UI.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  firebase_auth: ^0.8.0+3

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:firebase_auth/firebase_auth.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 29, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Fix lib/src/firebase_auth.dart. (-0.50 points)

Analysis of lib/src/firebase_auth.dart reported 1 hint:

line 45 col 36: Close instances of dart.core.Sink.

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field was unreachable.

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (firebase_core).


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
firebase_core ^0.3.0 0.3.4 0.4.3+2
flutter 0.0.0
meta ^1.0.4 1.1.8
Transitive dependencies
collection 1.14.11 1.14.12
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
google_sign_in ^3.0.4
test ^1.3.0