|
1 | | -<!-- |
2 | | -This README describes the package. If you publish this package to pub.dev, |
3 | | -this README's contents appear on the landing page for your package. |
| 1 | +# Firebase UI OAuth OIDC |
4 | 2 |
|
5 | | -For information about how to write a good package README, see the guide for |
6 | | -[writing package pages](https://dart.dev/guides/libraries/writing-package-pages). |
| 3 | +[](https://pub.dev/packages/firebase_ui_oauth_oidc) |
7 | 4 |
|
8 | | -For general information about developing packages, see the Dart guide for |
9 | | -[creating packages](https://dart.dev/guides/libraries/create-library-packages) |
10 | | -and the Flutter guide for |
11 | | -[developing packages and plugins](https://flutter.dev/developing-packages). |
12 | | ---> |
| 5 | +OIDC Sign In for [Firebase UI Auth](https://pub.dev/packages/firebase_ui_auth) |
13 | 6 |
|
14 | | -TODO: Put a short description of the package here that helps potential users |
15 | | -know whether this package might be useful for them. |
| 7 | +## Installation |
16 | 8 |
|
17 | | -## Features |
| 9 | +Add dependency |
18 | 10 |
|
19 | | -TODO: List what your package can do. Maybe include images, gifs, or videos. |
| 11 | +```sh |
| 12 | +flutter pub add firebase_ui_auth |
| 13 | +flutter pub add firebase_ui_oauth_oidc |
20 | 14 |
|
21 | | -## Getting started |
| 15 | +flutter pub global activate flutterfire_cli |
| 16 | +flutterfire configure |
| 17 | +``` |
22 | 18 |
|
23 | | -TODO: List prerequisites and provide or point to information on how to |
24 | | -start using the package. |
| 19 | +Enable OIDC provider on [firebase console](https://console.firebase.google.com/). |
25 | 20 |
|
26 | 21 | ## Usage |
27 | 22 |
|
28 | | -TODO: Include short and useful examples for package users. Add longer examples |
29 | | -to `/example` folder. |
| 23 | +```dart |
| 24 | +import 'package:firebase_core/firebase_core.dart'; |
| 25 | +import 'package:firebase_ui_auth/firebase_ui_auth.dart'; |
| 26 | +import 'package:firebase_ui_oauth_apple/firebase_ui_oauth_oidc.dart'; |
| 27 | +
|
| 28 | +void main() { |
| 29 | + WidgetsFlutterBinding.ensureInitialized(); |
| 30 | + await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); |
| 31 | +
|
| 32 | + FirebaseUIAuth.configureProviders([ |
| 33 | + AppleProvider(), |
| 34 | + ]); |
| 35 | +
|
| 36 | + runApp(MyApp()); |
| 37 | +} |
| 38 | +
|
| 39 | +class MyApp extends StatelessWidget { |
| 40 | + const MyApp({Key? key}) : super(key: key); |
| 41 | +
|
| 42 | + @override |
| 43 | + Widget build(BuildContext context) { |
| 44 | + return MaterialApp( |
| 45 | + home: SignInScreen( |
| 46 | + actions: [ |
| 47 | + AuthStateChangeAction<SignedIn>((context, state) { |
| 48 | + // redirect to other screen |
| 49 | + }) |
| 50 | + ], |
| 51 | + ), |
| 52 | + ); |
| 53 | + } |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +Alternatively you could use the `OAuthProviderButton` |
30 | 58 |
|
31 | 59 | ```dart |
32 | | -const like = 'sample'; |
| 60 | +class MyScreen extends StatelessWidget { |
| 61 | + @override |
| 62 | + Widget build(BuildContext context) { |
| 63 | + return AuthStateListener<OAuthController>( |
| 64 | + listener: (oldState, newState, controller) { |
| 65 | + if (newState is SignedIn) { |
| 66 | + // navigate to other screen. |
| 67 | + } |
| 68 | + }, |
| 69 | + child: OAuthProviderButton( |
| 70 | + provider: AppleProvider(), |
| 71 | + ), |
| 72 | + ); |
| 73 | + } |
| 74 | +} |
33 | 75 | ``` |
34 | 76 |
|
35 | | -## Additional information |
| 77 | +Also there is a standalone version of the `AppleSignInButton` |
36 | 78 |
|
37 | | -TODO: Tell users more about the package: where to find more information, how to |
38 | | -contribute to the package, how to file issues, what response they can expect |
39 | | -from the package authors, and more. |
| 79 | +```dart |
| 80 | +class MyScreen extends StatelessWidget { |
| 81 | + @override |
| 82 | + Widget build(BuildContext context) { |
| 83 | + return AppleSignInButton( |
| 84 | + loadingIndicator: CircularProgressIndicator(), |
| 85 | + onSignedIn: (UserCredential credential) { |
| 86 | + // perform navigation. |
| 87 | + } |
| 88 | + ); |
| 89 | + } |
| 90 | +} |
| 91 | +``` |
0 commit comments