搜索分类、插件与代码仓

插件详情v2.1.5

firebase_auth_rest

基于 REST 的跨平台 Dart/Flutter 包装器,用于 Firebase 身份验证 API

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
292
喜欢数
23
Pub 分数
150

安装插件

flutter pub add firebase_auth_rest

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个与平台无关的 Dart/Flutter 包装器,用于 Firebase Authentication REST API,可在 Android、iOS、Web、macOS、Windows 和 Linux 上实现无缝认证。它将 Firebase 的 REST 端点抽象为简洁易用的接口,无需使用原生 SDK。非常适合希望以最少设置实现跨平台认证并完全控制认证流程的开发者。该包轻量且设计用于在无法使用原生 Firebase SDK 的环境中可靠运行。

适合场景

  • 跨平台身份验证
  • 服务器端身份验证集成
  • Web 和桌面应用程序身份验证
  • 自定义身份验证流程
  • 离线优先的应用程序

主要特点

  • 基于 REST 的 Firebase 集成
  • 多平台支持
  • 无原生 SDK 依赖
  • 简单的 API 接口
  • 安全的令牌处理

适合对象

  • 面向多个平台的开发者
  • 项目避免使用原生 Firebase SDK
  • 需要对身份验证进行细粒度控制的应用程序
  • 后端集成的 Flutter 应用
  • 轻量级身份验证解决方案

使用建议

  • 需要手动管理刷新令牌
  • 仅限 REST API 功能
  • 无内置 UI 组件
  • 取决于网络可用性
  • REST 调用需要适当的错误处理

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

firebase_auth_rest

CI/CD Pub Version

A platform independent Dart/Flutter Wrapper for the Firebase Authentication API based on REST

Features

  • Pure Dart-based implementation
    • works on all platforms supported by dart
  • Uses the official REST-API endpoints
  • Provides high-level classes to manage authentication and users
  • Supports multiple parallel Logins of different users
  • Supports automatic background refresh
  • Supports all login methods
  • Proivides low-level REST classes for direct API access (import firebase_auth_rest/rest.dart)

Installation

Simply add firebase_auth_rest to your pubspec.yaml and run pub get (or flutter pub get).

Usage

The libary consists of two primary classes - the FirebaseAuth and the FirebaseAccount. You can use the FirebaseAuth class to perform "global" API actions that are not directly tied to a logged in user - This are things like creating accounts and signing in a user, but also functions like resetting a password that a user has forgotten.

The sign in/up methods of FirebaseAuth will provide you with a FirebaseAccount. It holds the users authentication data, like an ID-Token, and can be used to perform various account related operations, like changing the users email address or getting the full user profile. It also automatically refreshes the users credentials shortly before timeout - allthough that can be disabled and done manually.

Thw following code is a simple example, which can be found in full length, including errorhandling, at https://pub.dev/packages/firebase_auth_rest/example. It loggs into firebase as anonymous user, prints credentials and account details and then proceeds to permanently delete the account.

// Create auth instance and sign up as anonymous user
final fbAuth = FirebaseAuth(Client(), "API-KEY");
final account = await fbAuth.signUpAnonymous();

// print credentials und user details
print("Local-ID: ${account.localId}");
final userInfo = await account.getDetails();
print("User-Info: $userInfo");

// delete and dispose the account
await account.delete();
account.dispose();

Documentation

The documentation is available at https://pub.dev/documentation/firebase_auth_rest/latest/. A full example can be found at https://pub.dev/packages/firebase_auth_rest/example.

Testing

If you intend to run the integration tests, you will have to create a firebase project with the authentication enabled. You must enable E-Mail and anonymous authentication and disable the E-Mail enumeration protection. Note: This is only required to run the integration tests. For a normal firebase project you should never disable E-Mail enumeration protection. Finally, you have to create a .env file with the FIREBASE_API_KEY from the project.

Alternatively you can use the firebase emulator for testing. In that case, you will have to set the FIREBASE_EMULATOR_HOST and FIREBASE_EMULATOR_PORT in the .env file as well.

所属分类

依赖

依赖清单 3 项

源码仓库

使用此插件的项目