firebase_auth 0.5.12

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 100

firebase_auth plugin

A Flutter plugin to use the Firebase Authentication API.

pub package

For Flutter plugins for other Firebase products, see FlutterFire.md.

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 'com.android.tools.build:gradle:3.1.2'
  // Add the google services classpath
  classpath 'com.google.gms:google-services:3.2.1'
}
  1. Add the apply plugin to the [project]/android/app/build.gradle file.
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

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

java.lang.IllegalStateException:
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 FirebaseAuth:

final FirebaseAuth _auth = FirebaseAuth.instance;

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

Future<FirebaseUser> _handleSignIn() async {
  GoogleSignInAccount googleUser = await _googleSignIn.signIn();
  GoogleSignInAuthentication googleAuth = await googleUser.authentication;
  FirebaseUser user = await _auth.signInWithGoogle(
    accessToken: googleAuth.accessToken,
    idToken: googleAuth.idToken,
  );
  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.

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

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.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 "https://maven.google.com" endpoint to the repository section of your android/build.gradle. For example:
allprojects {
    repositories {
        jcenter()
        maven {                              // NEW
            url "https://maven.google.com"   // NEW
        }                                    // NEW
    }
}

0.0.4

  • Add method getToken() to FirebaseUser

0.0.3+1

  • Updated README.md

0.0.3

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

0.0.2+1

  • Updated README.md

0.0.2

  • Bump buildToolsVersion to 25.0.3

0.0.1

  • Initial Release

example/lib/main.dart

// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';

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

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Firebase Auth Demo',
      home: new MyHomePage(title: 'Firebase Auth Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Future<String> _message = new Future<String>.value('');

  Future<String> _testSignInAnonymously() async {
    final FirebaseUser user = await _auth.signInAnonymously();
    assert(user != null);
    assert(user.isAnonymous);
    assert(!user.isEmailVerified);
    assert(await user.getIdToken() != null);
    if (Platform.isIOS) {
      // Anonymous auth doesn't show up as a provider on iOS
      assert(user.providerData.isEmpty);
    } else if (Platform.isAndroid) {
      // Anonymous auth does show up as a provider on Android
      assert(user.providerData.length == 1);
      assert(user.providerData[0].providerId == 'firebase');
      assert(user.providerData[0].uid != null);
      assert(user.providerData[0].displayName == null);
      assert(user.providerData[0].photoUrl == null);
      assert(user.providerData[0].email == null);
    }

    final FirebaseUser currentUser = await _auth.currentUser();
    assert(user.uid == currentUser.uid);

    return 'signInAnonymously succeeded: $user';
  }

  Future<String> _testSignInWithGoogle() async {
    final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
    final GoogleSignInAuthentication googleAuth =
        await googleUser.authentication;
    final FirebaseUser user = await _auth.signInWithGoogle(
      accessToken: googleAuth.accessToken,
      idToken: googleAuth.idToken,
    );
    assert(user.email != null);
    assert(user.displayName != null);
    assert(!user.isAnonymous);
    assert(await user.getIdToken() != null);

    final FirebaseUser currentUser = await _auth.currentUser();
    assert(user.uid == currentUser.uid);

    return 'signInWithGoogle succeeded: $user';
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          new MaterialButton(
              child: const Text('Test signInAnonymously'),
              onPressed: () {
                setState(() {
                  _message = _testSignInAnonymously();
                });
              }),
          new MaterialButton(
              child: const Text('Test signInWithGoogle'),
              onPressed: () {
                setState(() {
                  _message = _testSignInWithGoogle();
                });
              }),
          new FutureBuilder<String>(
              future: _message,
              builder: (_, AsyncSnapshot<String> snapshot) {
                return new Text(snapshot.data ?? '',
                    style: const TextStyle(
                        color: const Color.fromARGB(255, 0, 155, 0)));
              }),
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  firebase_auth: ^0.5.12

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages 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';
  
Version Uploaded Documentation Archive
0.6.6 Nov 21, 2018 Go to the documentation of firebase_auth 0.6.6 Download firebase_auth 0.6.6 archive
0.6.5 Nov 16, 2018 Go to the documentation of firebase_auth 0.6.5 Download firebase_auth 0.6.5 archive
0.6.2+1 Oct 12, 2018 Go to the documentation of firebase_auth 0.6.2+1 Download firebase_auth 0.6.2+1 archive
0.5.20 Sep 5, 2018 Go to the documentation of firebase_auth 0.5.20 Download firebase_auth 0.5.20 archive
0.5.19 Aug 21, 2018 Go to the documentation of firebase_auth 0.5.19 Download firebase_auth 0.5.19 archive
0.5.18 Aug 10, 2018 Go to the documentation of firebase_auth 0.5.18 Download firebase_auth 0.5.18 archive
0.5.15 Jul 23, 2018 Go to the documentation of firebase_auth 0.5.15 Download firebase_auth 0.5.15 archive
0.5.14 Jul 18, 2018 Go to the documentation of firebase_auth 0.5.14 Download firebase_auth 0.5.14 archive
0.5.12 Jul 2, 2018 Go to the documentation of firebase_auth 0.5.12 Download firebase_auth 0.5.12 archive
0.5.11 Jun 1, 2018 Go to the documentation of firebase_auth 0.5.11 Download firebase_auth 0.5.11 archive

All 46 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
100
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
100
Learn more about scoring.

We analyzed this package on Dec 6, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
meta ^1.0.4 1.1.6
Transitive dependencies
collection 1.14.11
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test