Skip to content

Commit

Permalink
feat(ui): add firebase_ui_auth and oauth providers (#9343)
Browse files Browse the repository at this point in the history
* feat(ui): add firebase_ui_auth and oauth providers

* chore(ui): fix unit tests

* chore(ui): fix e2e tests

* chore(ui): fix example dependency

* chore(ui): fix OAuthProviderButton test

* chore(ui): fix email verification domain

* fix(ui): fix keyboard overlapping sign in screen ui

* feat(ui): reload user when app goes back to foreground

* fix(ui): fix reauthenticate dialog

* fix(ui): fix dependencies

* fix(ui): fix default resizeToAvoidBottomInset

* fix(ui): fix review comments

* fix(ui): use Text.rich instead of RichText

* fix(ui): fix phone and sms code input for RTL locales

* fix(ui): fix sign in action button on delete account action

* fix(ui): fix description, repository and homepage URLs

* chore(ui): trigger CI

* docs(ui_auth): fix review commets

* chore(ui_auth): drop unnecessary assets folder
  • Loading branch information
lesnitsky committed Oct 17, 2022
1 parent ff05af5 commit db5a5e1
Show file tree
Hide file tree
Showing 452 changed files with 26,432 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/firebase_ui_auth/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.packages
build/
10 changes: 10 additions & 0 deletions packages/firebase_ui_auth/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: f1875d570e39de09040c8f79aa13cc56baab8db1
channel: stable

project_type: package
7 changes: 7 additions & 0 deletions packages/firebase_ui_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## 1.0.0-dev.0

- Bump "firebase_ui_auth" to `1.0.0-dev.0`.

## 0.0.1

* TODO: Describe initial release.
26 changes: 26 additions & 0 deletions packages/firebase_ui_auth/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright 2017, the Chromium project authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
80 changes: 80 additions & 0 deletions packages/firebase_ui_auth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Firebase UI Auth

[![pub package](https://img.shields.io/pub/v/firebase_ui_auth.svg)](https://pub.dev/packages/firebase_ui_auth)

Firebase UI Auth is a set of Flutter widgets and utilities designed to help you build and integrate your user interface with Firebase Authentication.

> Please contribute to the [discussion](https://github.com/firebase/flutterfire/discussions/6978) with feedback.
## Platoform support

| Feature/platform | Android | iOS | Web | macOS | Windows | Linux |
| ------------------ | ------- | --- | ---------------- | ---------------- | ---------------- | ---------------- |
| Email ||||| ✓ <sup>(1)</sup> | ✓ <sup>(1)</sup> |
| Phone |||||||
| Email link |||||||
| Email verification ||| ✓ <sup>(2)</sup> | ✓ <sup>(2)</sup> | ✓ <sup>(1)</sup> | ✓ <sup>(1)</sup> |
| Sign in with Apple |||||||
| Google Sign in ||||| ✓ <sup>(1)</sup> | ✓ <sup>(1)</sup> |
| Twitter Login ||||| ✓ <sup>(1)</sup> | ✓ <sup>(1)</sup> |
| Facebook Sign in ||||| ✓ <sup>(1)</sup> | ✓ <sup>(1)</sup> |

1. Available with [flutterfire_desktop](https://github.com/invertase/flutterfire_desktop)
2. No deep-linking into app, so email verification link opens a web page

## Installation

```sh
flutter pub add firebase_ui_auth
```

## Getting Started

Here's a quick example that shows how to build a `SignInScreen` and `ProfileScreen` in your app

```dart
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
const providers = [EmailAuthProvider()];
return MaterialApp(
initialRoute: FirebaseAuth.instance.currentUser == null ? '/sign-in' : '/profile',
routes: {
'/sign-in': (context) {
return SignInScreen(
providers: providers,
actions: [
AuthStateChangeAction<SignedIn>((context, state) {
Navigator.pushReplacementNamed(context, '/profile');
}),
],
);
},
'/profile': (context) {
return ProfileScreen(
providers: providers,
actions: [
SignedOutAction((context) {
Navigator.pushReplacementNamed(context, '/sign-in');
}),
],
);
},
},
);
}
}
```

Learn more [here](https://github.com/firebase/flutterfire/packages/firebase_ui_auth/doc/README.md).

## Roadmap / Features

- For issues, please create a new [issue on the repository](https://github.com/firebase/flutterfire/issues).
- For feature requests, & questions, please participate on the [discussion](https://github.com/firebase/flutterfire/discussions/6978) thread.
- To contribute a change to this plugin, please review our [contribution guide](https://github.com/firebase/flutterfire/blob/master/CONTRIBUTING.md) and open a [pull request](https://github.com/firebase/flutterfire/pulls).
4 changes: 4 additions & 0 deletions packages/firebase_ui_auth/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
62 changes: 62 additions & 0 deletions packages/firebase_ui_auth/doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Firebase UI for authentication

Firebase UI for authentication provides a simple and easy way to implement authentication in your Flutter app.
The library provides fully featured UI screens to drop into new or existing applications, along with
lower level abstractions for developers looking for tighter control.

## Installation

Activate FlutterFire CLI

```sh
dart pub global activate flutterfire_cli
```

Install dependencies

```sh
flutter pub add firebase_core
flutter pub add firebase_auth
# required for email link sign in and email verification
flutter pub add firebase_dynamic_links
flutter pub add firebase_ui_auth
```

## Configuration

Configure firebase using cli:

```sh
flutterfire configure
```

Initialize firebase app:

```dart
void main() {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
}
```

## macOS entitlements

If you're building for macOS, make sure to add necessary entitlements. Learn more [from the official Flutter documentation](https://docs.flutter.dev/development/platform-integration/macos/building).

## Next steps

To understand what Firebase UI for authentication offers, the following documentation pages walk you through the various topics on
how to use the package within your Flutter app.

- Available auth providers:

- [EmaiAuthProvider](./providers/email.md) - allows registering and signing in using email and password.
- [EmailLinkAuthProvider](./providers/email-link.md) - allows registering and signing in using a link sent to email.
- [PhoneAuthProvider](./providers/phone.md) - allows registering and signing in using a phone number
- [UniversalEmailSignInProvider](./providers/universal-email-sign-in.md) - gets all connected auth providers for a given email.
- [OAuth](./providers/oauth.md)

- [Localization](../../firebase_ui_localizations/README.md)
- [Theming](./theming.md)
- [Navigation](./navigation.md)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions packages/firebase_ui_auth/doc/navigation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Navigation

Firebase UI uses Flutter navigation capabilities to navigate between pages.

By default, it uses "Navigator 1." when a new screen needs to be shown as a result of user interaction (`Navigator.push(context, route)` is used).

For applications using the standard navigation APIs, navigation will work out of the box and require no intervention. However, for applications using
a custom routing package, you will need to override the default navigation actions to integrate with your routing strategy.

## Custom routing

For this example, the application will create [named routes](https://docs.flutter.dev/cookbook/navigation/named-routes). Within the UI logic, we can
override the default actions (e.g. signing in or signing out) the UI performs to instead integrate with those named routes.

First, we define the root route that checks for authentication state and renders a `SignInScreen` or `ProfileScreen`:

```dart
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
const providers = [EmailProvider()];
return MaterialApp(
initialRoute: FirebaseAuth.instance.currentUser == null ? '/sign-in' : '/profile',
routes: {
'/sign-in': (context) => SignInScreen(providers: providers),
'/profile': (context) => ProfileScreen(providers: providers),
},
);
}
}
```

By default, when a user triggers a sign-in via the `SignInScreen`, no action default occurs. Since we are not subscribing to the authentication
state (via the `authStateChanges` API), we need to manually force the navigator to push to a new screen (the `/profile` route).

To do this, add a `AuthStateChangeAction` action to the `actions` property of the widget, for example for a successful sign in:

```dart
SignInScreen(
actions: [
AuthStateChangeAction<SignedIn>((context, _) {
Navigator.of(context).pushReplacementNamed('/profile');
}),
],
// ...
)
```

You could also react to the user signing out in a similar manner:

```dart
ProfileScreen(
actions: [
SignedOutAction((context, _) {
Navigator.of(context).pushReplacementNamed('/sign-in');
}),
],
// ...
)
```

Some UI widgets also come with internal actions which triggers navigation to a new screen. For example the `SignInScreen` widget allows users to
reset their password by pressing the "Forgot Password" button, which internally navigates to a `ForgotPasswordScreen`. To override this action and
navigate to a named route, provide the `actions` list with a `ForgotPasswordAction`:

```dart
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
const providers = [EmailProvider()];
return MaterialApp(
initialRoute: FirebaseAuth.instance.currentUser == null ? '/sign-in' : '/profile',
routes: {
'/sign-in': (context) {
return SignInScreen(
providers: providers,
actions: [
ForgotPasswordAction((context, email) {
Navigator.of(context).pushNamed(
'/forgot-password',
arguments: {'email': email},
);
}),
],
);
},
'/profile': (context) => ProfileScreen(providers: providers),
'/forgot-password': (context) => MyCustomForgotPasswordScreen(),
},
);
}
}
```

To learn more about the available actions, check out the [FirebaseUIActions API reference](https://pub.dev/documentation/firebase_ui_auth/latest/firebase_ui_auth/FirebaseUIActions-class.html).

## Other topics

## Other topics

- [EmaiAuthProvider](./providers/email.md) - allows registering and signing using email and password.
- [EmailLinkAuthProvider](./providers/email-link.md) - allows registering and signing using a link sent to email.
- [PhoneAuthProvider](./providers/phone.md) - allows registering and signing using a phone number
- [UniversalEmailSignInProvider](./providers/universal-email-sign-in.md) - gets all connected auth providers for a given email.
- [OAuth](./providers/oauth.md)
- [Localization](../../firebase_ui_localizations/README.md)
- [Theming](./theming.md)

0 comments on commit db5a5e1

Please sign in to comment.