firebase_auth_dart_platform library

An implementation of FlutterFire's Firebase Auth platform interface on top of the pure-Dart client firebase_auth_providers_dart.

An app keeps the official firebase_auth API (FirebaseAuth.instance.signInWithEmailAndPassword(...)), and FirebaseUserAuth of firebase_auth_providers_dart does the work underneath, over the Firebase Auth REST API:

  • On Linux, where neither firebase_auth nor firebase_core has an implementation, adding this package is enough: Flutter calls FirebaseAuthDart.registerWith before main.
  • On any other platform, call FirebaseAuthDart.use at the start of main, before the first use of Firebase, to replace the official implementation.
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  FirebaseAuthDart.use();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
  await FirebaseAuth.instance.signInAnonymously();
}

Classes

AppVerification
The proof that a phone request comes from a real app, sent with accounts:sendVerificationCode and the start of an SMS second factor.
CallbackPresenter
Shows a flow with a function the app supplies. Needs dart:io for the loopback server; on this platform a flow run with it throws an UnsupportedError.
ConsolePresenter
A terminal. Needs dart:io; on this platform show and prompt throw an UnsupportedError.
DartFirebaseAuth
The implementation of FirebaseAuthPlatform on top of FirebaseUserAuth of firebase_auth_providers_dart: one client per FlutterFire app.
FirebaseAuthDart
Selects firebase_auth_providers_dart as the implementation of the official firebase_auth package.
OAuthAuthorizationCode
The authorization code of a loopback sign-in, with what the token endpoint wants next to it (RFC 6749 section 4.1.3 and RFC 7636): the server that exchanges it needs all four.
OAuthLoopbackProvider
An identity provider for the browser sign-in of desktop apps and command line tools (authorizeWithOAuthLoopback and FirebaseUserAuth.signInWithOAuthLoopback, VM only): the OAuth 2.0 authorization code flow with PKCE (S256) whose redirect comes back to a one-shot HTTP server on 127.0.0.1 (RFC 8252, "OAuth 2.0 for Native Apps").
SecurePresenter
A way to show a flow to the person and to collect its answer. Flows choose and drive presenters (SecureFlow.run); what a presenter can do is told by the interfaces it implements:
SystemBrowserPresenter
Shows a flow in the system browser. Needs dart:io; on this platform show throws an UnsupportedError.

Functions

defaultSessionFile() → String?
No file system here: there is no default file.

Typedefs

AuthStorageFactory = AuthStorage Function(FirebaseApp app)
Returns the storage of the session of the FlutterFire app (see FirebaseAuthDart.use).
OAuthCodeExchange = FutureOr<Map<String, Object?>> Function(OAuthAuthorizationCode code)
Exchanges an authorization code for the provider's tokens somewhere else than at the token endpoint: on a server of yours that holds the client secret. It returns the JSON object of the token endpoint (id_token, access_token, expires_in, ...). Throw a FirebaseAuthException to choose the error of the sign-in; any other error becomes invalid-credential.
OAuthProvidersFactory = Iterable<OAuthLoopbackProvider> Function(FirebaseApp app)
Returns the loopback providers of the FlutterFire app (see FirebaseAuthDart.use).

Exceptions / Errors

DartFirebaseAuthException
A FirebaseAuthException of the platform interface that also keeps what the server answered, for logs: firebase_auth passes it to the app as it is, so catch (e) can test e is DartFirebaseAuthException.