SuperAPI AI 工具集

auth0-flutter-native

智能体与模型

查看项目

更新于 10-15 17:21

技能介绍

用途:为 Flutter 移动端(iOS/Android)接入 Auth0 认证,实现登录、登出以及受生物识别保护的凭证存储,基于官方 SDK auth0_flutter。移动端通过设备系统浏览器执行 Web Auth(Universal Login),令牌存入平台 keychain/keystore,可选生物识别保护。

主要能力:Auth0(domain, clientId) 创建客户端;webAuthentication().login() 在系统浏览器中发起 Universal Login,登出用 logout();credentialsManager 提供 credentials()、hasValidCredentials()、clearCredentials(),登录后自动存储凭证;LocalAuthentication 可启用生物识别保护;支持自定义 URL scheme。

使用方式:环境需 Flutter 3.24.0+、Dart 3.5.0+,Android minSdkVersion 21+、compileSdkVersion 34+,iOS 14.0+(Universal Link 回调需 iOS 17.4+)。安装:flutter pub add auth0_flutter(文档已知版本 2.1.0,建议先查最新版本)。Android 需在 build.gradle 的 defaultConfig 中添加 manifestPlaceholders = [auth0Domain: "YOUR_AUTH0_DOMAIN", auth0Scheme: "https"];Kotlin DSL 为 manifestPlaceholders["auth0Domain"]/["auth0Scheme"]。iOS 默认 HTTPS Universal Link 流程无需改 Info.plist,但需在 Xcode 添加 Associated Domains(webcredentials:YOUR_AUTH0_DOMAIN);旧版 iOS 或自定义 scheme 需加 CFBundleURLTypes。回调地址需注册:https://YOUR_DOMAIN/android/PACKAGE_NAME/callback 和 https://YOUR_DOMAIN/ios/BUNDLE_ID/callback。Domain 与 Client ID 为公开配置,原生应用使用 PKCE、无 client secret。建议登录 scopes 含 'offline_access' 以便静默续期。应用启动时用 hasValidCredentials() + credentials() 恢复会话。

适用场景:Flutter iOS/Android 移动应用的 Auth0 登录、登出、会话恢复与凭证保护。

限制:Flutter Web 不适用(应用 auth0-flutter-web / Auth0Web);不支持原生 iOS/Android、React Native、React SPA、Node/Express 服务端。Android 自定义 scheme 必须全小写,需与 Dart 中 webAuthentication(scheme:) 一致;生物识别提示要求 MainActivity 继承 FlutterFragmentActivity;模拟器无法测试生物识别与完整登录跳转,需真机测试。异常应捕获 WebAuthenticationException 与 CredentialsManagerException。