SuperAPI AI 工具集

auth0-flutter-web

安全与审计

查看项目

更新于 10-16 08:05

技能介绍

用途:为 Flutter Web 应用接入 Auth0 的登录、登出与会话恢复,本技能面向 Web 平台,SDK 会包装 Auth0 SPA JS SDK 实现浏览器端认证。

主要能力:支持 loginWithRedirect 重定向登录与 loginWithPopup 弹窗登录;onLoad 在启动时从缓存恢复会话;credentials 获取缓存凭据并在过期时自动续期(需 offline_access 等 scope 与 Allowed Web Origins 配置);logout 支持 returnToUrl 返回应用;提供 UserProfile 信息如 name、email、pictureUrl。

使用方式:前置要求 Flutter 3.24.0+、Dart 3.5.0+、Auth0 账号与 Auth0 CLI。在项目根目录执行 flutter pub add auth0_flutter,确认 pubspec.yaml 中为 auth0_flutter: ^2.1.0。在 web/index.html 的 head 中加入 SPA JS script 标签,用 Auth0 CLI 的 auth0 apps update 注册回调、登出与 Web Origins。随后创建 AuthService 并在 main.dart 接入,按状态管理选择 setState、Provider、Riverpod 或 Bloc 模式。验证可执行 flutter build web,并用 flutter run -d chrome --web-port 3000 本地测试。

适用场景:Flutter Web 单页应用需要 Auth0 登录的浏览器端集成。

限制:不适用于 Flutter 移动端(iOS/Android 应使用 auth0-flutter-native)、原生 iOS、原生 Android、React/Angular/Vue SPA 或 Node.js/Express 服务端;SPA 使用 PKCE 无客户端密钥,Domain 与 Client ID 为公开配置;弹窗登录必须由用户直接交互触发,否则可能被浏览器拦截;本地端口需与回调 URL 一致。具体配置细节与更多模式以官方文档为准。