Skip to main content

firebase_auth_secure_storage_flutter 0.1.0 copy "firebase_auth_secure_storage_flutter: ^0.1.0" to clipboard
firebase_auth_secure_storage_flutter: ^0.1.0 copied to clipboard

Unofficial secure storage for the Firebase Auth session of firebase_auth_providers_dart in Flutter apps: the Keychain, the Android Keystore, libsecret and DPAPI through flutter_secure_storage.

example/lib/main.dart

// Keeps the session of a FirebaseUserAuth in the secure store of the platform.
//
// With firebase_auth_dart_platform (the official firebase_auth API), pass the
// same storage to FirebaseAuthDart.use instead:
//
//   final SecureAuthStorage storage = SecureAuthStorage();
//   FirebaseAuthDart.use(storageFor: (FirebaseApp app) => storage);
//
// Run it against an emulator started with
// `firebase emulators:start --only auth` (project demo-test). On macOS the app
// must be signed: see "macOS" in the README of the package.

import 'package:firebase_auth_providers_dart/firebase_auth_providers_dart.dart';
import 'package:firebase_auth_secure_storage_flutter/firebase_auth_secure_storage_flutter.dart';
import 'package:flutter/widgets.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(_Message(await _signIn()));
}

Future<String> _signIn() async {
  final FirebaseUserAuth auth = FirebaseUserAuth(
    apiKey: 'demo-api-key',
    storage: SecureAuthStorage(),
    emulatorHost: '127.0.0.1:9099',
  );
  try {
    await auth.restore();
    if (auth.uid == null) {
      await auth.signInAnonymously();
    }
    return 'Signed in as ${auth.uid}; the session survives a restart.';
  } on SecureAuthStorageException catch (e) {
    // No keyring, a locked keychain, a missing entitlement: the message says
    // which, and what to do.
    return '$e';
  } on Exception catch (e) {
    // The Auth emulator is not running, for example.
    return 'Sign-in failed: $e';
  } finally {
    await auth.dispose();
  }
}

class _Message extends StatelessWidget {
  const _Message(this.text);

  final String text;

  @override
  Widget build(BuildContext context) {
    debugPrint(text);
    return Directionality(
      textDirection: TextDirection.ltr,
      child: Center(child: Text(text)),
    );
  }
}
0
likes
150
points
150
downloads

Documentation

API reference

Publisher

verified publisherupcode.dev

Weekly Downloads

Unofficial secure storage for the Firebase Auth session of firebase_auth_providers_dart in Flutter apps: the Keychain, the Android Keystore, libsecret and DPAPI through flutter_secure_storage.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#firebase #authentication #secure-storage #keychain

License

Apache-2.0 (license)

Dependencies

crypto, firebase_auth_providers_dart, flutter, flutter_secure_storage

More

Packages that depend on firebase_auth_secure_storage_flutter