All four are used to log into a Firebase backend.

Related tags

Templates auth
Overview

Auth

This library package works with four plugins:

All four are used to log into a Firebase backend. If you're familiar with these plugins, you'll be able to quickly use this class library.

Installing

I don't always like the version number always suggested in the 'Installing' page. Instead, always go up to the 'major' semantic version number when installing my library packages. This means always entering a version number trailing with two zero, '.0.0'. This allows you to take in any 'minor' versions introducing new features as well as any 'patch' versions that involves bugfixes. Semanitic version numbers are always in this format: major.minor.patch.

  1. patch - I've made bugfixes
  2. minor - I've introduced new features
  3. major - I've essentially made a new app. It's broken backwards-compatibility and has a completely new the user experience. You won't get this version until you increment the major number in the pubspec.yaml file.

And so, in this case, add this to your package's pubspec.yaml file instead:

dependencies:
  auth:^8.0.0

How it Works

Below are a series of screenshots depicting how to initialize and authenticate or 'sign in' an individual into your app's Firebase database using a either an email and password or a Google account. The following will sign in 'silently' (i.e. automatically if the user had already signed in in the past.). Note, settings are passed as parameters in the screenshot below.

auth = Auth.init(
    scopes: [
      'email',
      'https://www.googleapis.com/auth/contacts.readonly',
    ],
    listener: (user) {
      loggedIn = user != null;
      setState(() {});
    });

auth.signInSilently(
  listen: (account) {
    loggedIn = account != null;
    setState(() {});
  },
);

These examples have the class library called in the State object's initState() function, but, of course, you could instead 'initialize' the class library in the initState() function and then 'sign in' elsewhere. Below, the init() function is used instead just to initialize the class library.

@override
void initState() {
  super.initState();

  auth = Auth.init(
    scopes: [
      'email',
      'https://www.googleapis.com/auth/contacts.readonly',
    ],
    listener: (user) {
      loggedIn = user != null;
      setState(() {});
    },
    listen: (account) {
      loggedIn = account != null;
      setState(() {});
    },
  );
  
  auth.signInSilently();
}

@override
void dispose() {
  /// Important to dispose of the Auth's resources.
  auth.dispose();
  super.dispose();
}

Screenshots

auth3 anyomous google

[] ); // ListView ">
Widget get _authResults => ListView(
      padding: const EdgeInserts.all(30.0),
      itemExtent: 80.0,
      children: <Widget>[
        Text("uid: ${auth.uid}"),
        Text("name: ${auth.displayName}"),
        Text("photo: ${auth.photoUrl}"),
        Text("new login: ${auth.isNewUser}"),
        Text("user name: ${auth.username}"),
        Text("email: ${auth.email}"),
        Text("email verified: ${auth.isEmailVerified}"),
        Text("anonymous login: ${auth.isAnonymous}"),
        Text("id token: ${auth.idToken}"),
        Text("access token: ${auth.accessToken}"),
        Text("information provider: ${auth.providerId}"),
        Text("expire time: ${auth.expirationTime}"),
        Text("auth time: ${auth.authTime}"),
        Text("issued at: ${auth.issuedAtTime}"),
        Text("signin provider: ${auth.signInProvider}"),
      ], // 
    
     []
    
    ); // ListView

Providers

This package works with multiple auth providers including Facebook and Twitter.

Facebook

Even if you've no intention of allowing users to use Facebook to log in, you will have to modify a few files any way so to use this library package. You can then ignore these files as they just need to be there. If you don't add to these three files, you'll get the following error when trying to use this Auth package:

The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.

faceSDKerror

On The Android Side

You must acknowledge to Android that the Facebook SDK is being utilized. Hence, a means to initialize it is required. So, go to the 'Android Manifest file' (android/app/src/main/AndroidManifest.xml) and add the following after the first tag, but before the last tag, . See below:

facebookManifest

You can copy and paste the code here:

">
<meta-data android:name="com.facebook.sdk.ApplicationId"
    android:value="@string/facebook_app_id"/>

<activity android:name="com.facebook.FacebookActivity"
    android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name" />

<activity
    android:name="com.facebook.CustomTabActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="@string/fb_login_protocol_scheme" />
    intent-filter>
activity>

Now go to the 'styles' (android/app/src/main/res/values/styles.xml) file and add the following:

Your App Name here. 000000000000 fb000000000000 ">
<string name="app_name">Your App Name here.string>

<string name="facebook_app_id">000000000000string>

<string name="fb_login_protocol_scheme">fb000000000000string>

With that, you can get on with your app even if you're not going to log in with Facebook. Here's what it would possibly look like in your particular file:

facebookresfile

Note: Place this file in .gitignore so not to save this Facebook App ID numbers on a public Github repository.

Setup Facebook Login

You will have to go to your Facebook Developers account and create or select the app you'll use.

Under Settings, click on the show button to copy down your App ID and App Secret those later (Firebase will need them).

AppSecret

Read quickstart section from Facebook documentation to set up Facebook on the Android side.

The following steps in particular will get your app working with Facebook:

  1. Select an App or Create a New App
  2. Edit Your Resources and Manifest
  3. Associate Your Package Name and Default Class with Your App
  4. Provide the Development and Release Key Hashes for Your App

Tell Firebase

Remember, all this effort is to connect to a backend Firebase database. You some things to do in the Firebase Projects Console.

You'll have to go into the Sign-in method tab and enable the Facbook option and any other options you may wish to use to log into this Firebase app:

signInProviders

Use Twitter

You can use Twitter as well if you want to. You'll just need to create an app on Twitter and then supply the Consumer API keys to this library package.

Go to Twitter Apps page

keysTokens

On Medium

This is a class library is covered again in the Medium article, Auth in Flutter.

AuthArticle

Other Dart Packages

Other Dart packages from the author can also be found at Pub.dev

Comments
  • Release build fails due flutter_twitter dependency

    Release build fails due flutter_twitter dependency

    Hello, app build is failing in release mode due to flutter_twitter dependency. There is no problem in debug mode.

    `flutter run --release Launching lib\main.dart on MYA L41 in release mode...

    FAILURE: Build failed with an exception.

    • What went wrong: Execution failed for task ':flutter_twitter:verifyReleaseResources'.

    A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade Android resource linking failed C:\Users\ASUS.gradle\caches\transforms-2\files-2.1\4b381a4f7d559d64bcbc7773e0474fc4\core-1.0.0\res\values\values.xml:57:5-88:25 : AAPT: error: resource android:attr/fontVariationSettings not found.

     C:\Users\ASUS\.gradle\caches\transforms-2\files-2.1\4b381a4f7d559d64bcbc7773e0474fc4\core-1.0.0\res\values\values.xml:57:5-88:25
    

    : AAPT: error: resource android:attr/ttcIndex not found.

    • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

    • Get more help at https://help.gradle.org

    BUILD FAILED in 1m 12s Running Gradle task 'assembleRelease'... Running Gradle task 'assembleRelease'... Done 73.3s The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility. Building plugin cloud_firestore... The plugin cloud_firestore could not be built due to the issue above. Running Gradle task 'assembleAarRelease'... `

    opened by deadsoul44 12
  • Version conflict

    Version conflict

    Because auth >=7.3.2 depends on firebase_core >=0.7.0 <1.0.0 and auth >=7.0.0 <7.3.2 depends on firebase_auth ^0.18.0, auth >=7.0.0 requires firebase_core >=0.7.0 <1.0.0 or firebase_auth ^0.18.0.
    And because ... depends on auth ^7.0.0, either firebase_core >=0.7.0 <1.0.0 or firebase_auth ^0.18.0.
    So, because ... depends on both firebase_auth ^1.0.0 and firebase_core ^1.0.0, version solving failed.
    pub finished with exit code 1
    
    opened by deadsoul44 5
  • Unable to sign in with Google

    Unable to sign in with Google

    auth: ^7.3.2 [√] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.19042.804], locale en-US)

    I'm unable to sign in with Google while using your example code. (To be fair,) I'm wedging it into my existing application.

    The first thing I noticed was that this:

    auth = Auth.init(
          scopes: [
            'email',
    ...
    

    was telling me The method 'init' isn't defined for the type 'Auth', which I thought was strange. So, I removed .init, and moved on.

    Next, I plopped your code into my sign-in page.

    RaisedButton(
      onPressed: () {
        auth
            .signInWithGoogle()
            .then((signIn) => signInFunc(signIn: signIn))
            .catchError((Object err) {
          if (err is! Exception) {
            err = err.toString();
          }
          errorMessage = auth.message;
        });
      },
      child: const Text('Sign In With Google'),
    ),
    

    The app compiles and runs, but when I tap the Sign In With Google button, I get the following error:

    MissingPluginException(No implementation found for method init on channel plugins.flutter.io/google_sign_in)

    I didn't have google_sign_in in my pubspec.yaml, so I added it thinking that might be the problem, but it hasn't helped.

    Any suggestions?

    opened by hanskokx 5
  • Use twitter_login instead of flutter_twitter

    Use twitter_login instead of flutter_twitter

    Use twitter_login which supports null-safety instead of flutter_twitter which was updated more than 2 years ago.

    https://pub.dev/packages/twitter_login

    opened by deadsoul44 4
  • Flutter facebook login uses deprecated Api

    Flutter facebook login uses deprecated Api

    Hi - the plugin that you use for Facebook login uses a deprecated API - UIWebView. This has been deprecated since April 2020, meaning any NEW apps submitted after this date will be rejected. It will be great if we have a choice to use a native facebook solution or your old web flow approach.

    opened by sallypeters 4
  • flutter_facebook_login instead of facebook web view login

    flutter_facebook_login instead of facebook web view login

    Hello, thanks for the great library. Is it possible to make use of flutter_facebook_login or implement similar behavior instead of Facebook web view login? Because, in web view login, user has to write email and password manually and as far as I know it will not be auto filled next time user tries to login.

    opened by deadsoul44 4
  • `Auth.isEmailVerified` not returning true

    `Auth.isEmailVerified` not returning true

    Hello!

    I have a user create an account using Auth.createUserWithEmailAndPassword Auth.isEmailVerified returns false. I then send an email verification

    Auth.sendEmailVerification();

    The user then clicks on the email verification.

    Auth.isEmailVerified still returns false.

    Any ideas?

    opened by DanMossa 4
  • Error: Getter not found: 'Success'.

    Error: Getter not found: 'Success'.

    I started to get this error although I did not update any dependency. Flutter clean did not work.

    Running Gradle task 'assembleDebug'...
    /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/auth-7.3.0/lib/src/auth.dart:1009:50: Error: Getter not found: 'Success'.
            if (result.status == FacebookLoginStatus.Success) {
                                                     ^^^^^^^
    /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/auth-7.3.0/lib/src/auth.dart:1012:57: Error: Getter not found: 'Cancel'.
            } else if (result.status == FacebookLoginStatus.Cancel) {
                                                            ^^^^^^
    /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/auth-7.3.0/lib/src/auth.dart:1015:57: Error: Getter not found: 'Error'.
            } else if (result.status == FacebookLoginStatus.Error) {
                                                            ^^^^^
    
    
    FAILURE: Build failed with an exception.
    

    This issue also happens on pub.dev in static analysis.

    opened by deadsoul44 3
  • Breaking changes in google sign in plugin

    Breaking changes in google sign in plugin

    Hi Greg,

    Thanks for another great package from you. I have just tried the Auth package but encountered the following error.

    image

    It looks like there is some braking changes in google sign in plug in.

    Could you please take a look?

    Thanks again.

    opened by jasonlaw 3
  • SignInWithGoogle crashes on Android

    SignInWithGoogle crashes on Android

    I'm getting this exception on android 9.0 with latest version of this plugin: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/lifecycle/LifecycleEventObserver; E/AndroidRuntime( 3132): at java.lang.Class.newInstance(Native Method) E/AndroidRuntime( 3132): at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:69) E/AndroidRuntime( 3132): at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:43) E/AndroidRuntime( 3132): at android.app.Instrumentation.newActivity(Instrumentation.java:1215) E/AndroidRuntime( 3132): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3007) E/AndroidRuntime( 3132): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3256) E/AndroidRuntime( 3132): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) E/AndroidRuntime( 3132): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) E/AndroidRuntime( 3132): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) E/AndroidRuntime( 3132): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1947) E/AndroidRuntime( 3132): at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime( 3132): at android.os.Looper.loop(Looper.java:214) E/AndroidRuntime( 3132): at android.app.ActivityThread.main(ActivityThread.java:7037) E/AndroidRuntime( 3132): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime( 3132): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) E/AndroidRuntime( 3132): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965) E/AndroidRuntime( 3132): Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.lifecycle.LifecycleEventObserver" on path: DexPathList[[zip file "/data/app/com.guala.koalarm-ZHyc8QrMaukWx9JlaxDelw==/base.apk"],nativeLibraryDirectories=[/data/app/com.guala.koalarm-ZHyc8QrMaukWx9JlaxDelw==/lib/arm64, /data/app/com.guala.koalarm-ZHyc8QrMaukWx9JlaxDelw==/base.apk!/lib/arm64-v8a, /system/lib64]]

    opened by melvinm99 3
  • Problem with Google Signin

    Problem with Google Signin

    Hello,

    Thank you for the great package again.

    I have a problem with google signin. I am trying to use the signInWithGoogle method.

    I had to modify the auth.dart file to print the following exception: PlatformException(exception, Unknown signInOption, null)

    Gist link for the signin page: https://gist.github.com/deadsoul44/f95c72c3d7a3529d4ac2efce751a3866

    I am able to get the google user account with the "vanilla" google signin.

    Stacktrace: I/flutter (20513): Caught: PlatformException(exception, Unknown signInOption, null) I/flutter (20513): Stack: #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7) I/flutter (20513): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33) I/flutter (20513): <asynchronous suspension> I/flutter (20513): #2 MethodChannelGoogleSignIn.init (package:google_sign_in_platform_interface/src/method_channel_google_sign_in.dart:26:20) I/flutter (20513): #3 GoogleSignIn._ensureInitialized (package:google_sign_in/google_sign_in.dart:228:62) I/flutter (20513): #4 GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:210:11) I/flutter (20513): <asynchronous suspension> I/flutter (20513): #5 GoogleSignIn._addMethodCall (package:google_sign_in/google_sign_in.dart:266:18) I/flutter (20513): <asynchronous suspension> I/flutter (20513): #6 GoogleSignIn.signIn (package:google_sign_in/google_sign_in.dart:336:9) I/flutter (20513): #7 Auth.signInWithGoogle (package:auth/auth.dart:686:43) I/flutter (20513): #8 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:43:6) I/flutter (20513): #9 Auth.signInWithGoogle (package:auth/auth.dart:674:32) I/flutter (20513): #10 _LoginPageState.build.<anonymous closure>

    As a workaround, I tried to initialize the auth with explicitly defining signInOption and it worked: auth = Auth.init( signInOption: SignInOption.standard, scopes: [ 'email', 'https://www.googleapis.com/auth/contacts.readonly', ], );

    opened by deadsoul44 2
  • Twitter callback URL does not fire

    Twitter callback URL does not fire

    Thanks for the plugin. I see you have updated both Facebook and twitter to handle the deprecated API'S. In using TWITTER - I get my TWITTER login showing but after I authenticate - my app is not returned to.

    I just get stuck on :

    image

    Twitter has been configured properly and I have these callbacks :

    image

    info.plist has also been setup with the twitter key in UrlSchemes :

    image

    My project is an OBJ-C iOS project using default AppDelegate.

    Is there anything else that needs to be configured to get the twitter callback redirecting back to my app with your plugin ?

    opened by alexda12 19
  • Trying to login with google and facebook

    Trying to login with google and facebook

    hi i'm new to flutter, when i try to login with google everything okay but if i try login with the same email on facebook this error appear "ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL" on the debug console but i cannot catch the error or the exception on ths part:

    `auth.signInWithFacebook().then(signInFunc).catchError((err,stackTrace) { auth.currentUser();

                                      debugPrint(err);
    
                                        print('error caught: $err');
                                     // if (err is! Exception) err = err.toString();
                                      //errorMessage = auth.message;
                                    });`
    

    how can i catch the exception?

    opened by innerk 2
  • Sign in with Apple

    Sign in with Apple

    Is it possible to also add sign in with Apple?

    For iOS: https://pub.dev/packages/apple_sign_in For Android: https://developer.apple.com/documentation/signinwithapplerestapi

    Thank you.

    opened by deadsoul44 3
Owner
Andrious Solutions Ltd.
Software Development Solutions Provider
Andrious Solutions Ltd.
Four-In-A-Row in Flutter

Flutter FIAR Four-in-a-row game in Flutter Game modes Player vs Player (only local) Player vs Cpu Dumb Hard Hardest Demo (Cpu Hard vs Cpu Hardest) Get

Salvatore Giordano 12 Sep 12, 2022
How login , register and log out Firebase Textformfield with focusNode. InheritedWidget example.

flutter_fire_base_register How login, register and log out Firebase. Textformfield with focusNode InheritedWidget exam. Stream provider usage. App Hom

Taylan YILDIZ 1 May 8, 2021
A simple log catch server powered by flutter.

flutter_logcat A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started i

bebe 1 Jan 9, 2022
The ArDrive Web App allows a user to log in to securely view, upload and manage their ArDrive files.

ArDrive Web The ArDrive Web App allows a user to log in to securely view, upload and manage their ArDrive files. Have any questions? Join the ArDrive

ArDrive App 36 Dec 14, 2022
A flutter plugin to get facebook deep links and log app events using the latest Facebook SDK to include support for iOS 14

Facebook Sdk For Flutter LinkedIn GitHub facebook_sdk_flutter allows you to fetch deep links, deferred deep links and log facebook app events. This wa

Saad Farhan 23 Dec 17, 2022
A visualized dynamic programming for log collection based on flutter.

A visualized dynamic programming for log collection based on flutter. Pub使用 1. Depend on it Add this to your package's pubspec.yaml dependencies: mag

Wuba 48 Nov 22, 2022
Movie App used MVC pattern, Getx for state managment, sqflite for backend database

movie_app A new Flutter application. Getting Started This project used MVC pattern, Getx for state managment, sqflite for backend database, firebase/W

HM Badhon 3 Sep 13, 2022
Tasawq App — Flutter framework and Firebase An application that objectives to display all nearby stores of all kinds and real estate.

Tasawq App — Flutter framework and Firebase An application that objectives to display all nearby stores of all kinds and real estate. Multi-vendor, standard user login to view nearby products and stores for rating, follow-up, messaging and more

null 1 Nov 10, 2022
Download files from Firebase Storage with Flutter. List all images, videos, or other files from Firebase and download them.

Flutter Tutorial - Download Files From Firebase Storage Download files from Firebase Storage with Flutter. List all images, videos, or other files fro

Johannes Milke 28 Dec 4, 2022
This project include all the assets I used in this tutorial

clothes_app_starter A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you star

Ruize Nie 11 Jun 29, 2022
Examples of all types of widgets used for animation in Flutter.

Anny Flutter application for learning animations concept. Checkout the live demo here. License Copyright 2020 Ashutosh Singh Licensed under the A

Ashutosh Singh 23 Nov 22, 2022
An application used to manage all your tabs in a clean, scrollable, categorized format.

Tabmanager Created by Sami-ul You can contact me here: [email protected] Recent updates Made the app run faster by using the backend to serve t

Sami 7 Nov 2, 2022
Csv to list for web - Convert a CSV into a list in order to populate a firebase database

My goal is to convert a CSV into a list in order to populate a firebase database

null 0 Jan 26, 2022
This is an auction application just like eBay. Using firebase as the backend for signup & sign-in functionality. In addition to that, it's a two pages application with user bid in input and count down view.

Nilam This is an auction application just like eBay. Using firebase as the backend for signup & sign-in functionality. In addition to that, it's a two

Md. Siam 5 Nov 9, 2022
Working Instagram Clone (Frontend + Backend) created with Flutter and Firebase

Instagram_clone Instagram Clone (Both frontend and backend) created with Flutter and Firebase. Show some ❤️ and star the repo to support the project.

Mohak Gupta 684 Dec 31, 2022
Demo Project to show how to use Phone Authentication in Flutter with Firebase backend

Firebase Phone Authentication using Firebase Demo Project to show how to do Phone Authentication in Flutter using Firebase backend. Screenshots At Fir

Kune Mohith 78 Sep 27, 2022
Food-app-flutter - A simple food ordering application with an admin panel coded with flutter and uses firebase as a backend

shop_ui A new Flutter project. Getting Started This project is a starting point

Ryan Egbejule-jalla 3 Oct 5, 2022