A Flutter plugin to use the Firebase Authentication API.
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!
The Google Sign-in plugin is required to use the firebase_auth plugin. Follow the Google sign-in plugin installation instructions.
To use the firebase_auth plugin, follow the plugin installation instructions.
Enable the Google services by configuring the Gradle scripts as such.
[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'
}
[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.
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 {
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));
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.
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.
See the example application source for a complete sample app using the Firebase authentication.
Please file issues to send feedback or report a bug. Thank you!
verifyPhoneNumber
, that would never return even in a successful call.updatePassword
in FirebaseUser
.updateEmail
and updateProfile
to FirebaseUser
.
This brings the firebase_auth
package inline with other implementations and documentation.signInWithCustomToken
Stream<FirebaseUser> onAuthStateChanged
event to listen when the user changeandroid/build.gradle
. For example:allprojects {
repositories {
jcenter()
maven { // NEW
url "https://maven.google.com" // NEW
} // NEW
}
}
example/README.md
Demonstrates how to use the firebase_auth plugin.
+1 408-555-6969
and verification code 888888
are used.URL Schemes
to the REVERSE_CLIENT_ID
from the GoogleServices-Info.plist
file.Test verifyPhoneNumber
button.Test signInWithPhoneNumber
button.For help getting started with Flutter, view our online documentation.
Add this to your package's pubspec.yaml file:
dependencies:
firebase_auth: ^0.6.5
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.
Now in your Dart code, you can use:
import 'package:firebase_auth/firebase_auth.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
0.8.1+1 | Feb 15, 2019 |
|
|
0.8.1 | Feb 11, 2019 |
|
|
0.8.0+3 | Feb 8, 2019 |
|
|
0.8.0+1 | Jan 25, 2019 |
|
|
0.8.0 | Jan 24, 2019 |
|
|
0.7.0 | Jan 29, 2019 |
|
|
0.6.6 | Nov 21, 2018 |
|
|
0.6.5 | Nov 16, 2018 |
|
|
0.6.2+1 | Oct 12, 2018 |
|
|
0.5.20 | Sep 5, 2018 |
|
|
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
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.
Fix lib/firebase_auth.dart
. (-0.50 points)
Analysis of lib/firebase_auth.dart
reported 1 hint:
line 199 col 36: Close instances of dart.core.Sink
.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.0.0-dev.28.0 <3.0.0 | ||
firebase_core | ^0.2.5+1 | 0.2.5+1 | 0.3.0+1 |
flutter | 0.0.0 | ||
meta | ^1.0.4 | 1.1.6 | 1.1.7 |
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 | |||
google_sign_in | ^3.0.4 | ||
test | ^1.3.0 |