You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用aad_oauth实现微软多因素认证时遇MissingPluginException

问题描述

开发Flutter应用时,使用aad_oauth包实现微软多因素认证,登录过程中触发MissingPluginException错误,错误信息如下:

I/flutter (18709): Login failed: MissingPluginException(No implementation found for method delete on channel plugins.it_nomads.com/flutter_secure_storage)

相关业务代码:

class _LoginScreenState extends State<LoginScreen> {
  final TextEditingController _emailController = TextEditingController();
  late final AadOAuth oauth;

  @override
  void initState() {
    super.initState();
    final config = Config(
      tenant: '2f5964b2-44fc-420d-8974-xxxx',
      clientId: 'ed4c80e3-847b-4b0a-85a9-xxxxx',
      scope: 'openid profile email',
      redirectUri: 'msauth://com.xxxxxx/auth',
      navigatorKey: LoginScreen.navigatorKey,
    );
    oauth = AadOAuth(config);
  }

  void _login() async {
    try {
      await oauth.login();
      final accessToken = await oauth.getAccessToken();
      if (accessToken != null) {
        Navigator.pushReplacement(
          context,
          MaterialPageRoute(builder: (context) => SuccessScreen()),
        );
      }
    } catch (e) {
      print('Login failed: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
        padding: EdgeInsets.all(24.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [

            SizedBox(height: 20),
            Text(
              'Sign in',
              style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
              textAlign: TextAlign.center,
            ),
            SizedBox(height: 20),
            TextField(
              controller: _emailController,
              decoration: InputDecoration(
                labelText: 'Email, phone, or Skype',
                border: OutlineInputBorder(),
                filled: true,
                fillColor: Colors.white,
              ),
              keyboardType: TextInputType.emailAddress,
            ),
            SizedBox(height: 16),
            ElevatedButton(
              onPressed: _login,
              child: Padding(
                padding: EdgeInsets.symmetric(vertical: 12),
                child: Text(
                  'Next',
                  style: TextStyle(fontSize: 16),
                ),
              ),
              style: ElevatedButton.styleFrom(
                backgroundColor: Colors.blue[700],
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(4),
                ),
              ),
            ),
            SizedBox(height: 16),
            TextButton(
              onPressed: () {},
              child: Text('Can\'t access your account?'),
            ),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    _emailController.dispose();
    super.dispose();
  }
}

已配置的AndroidManifest内容:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data
        android:scheme="msauth"
        android:host="com.xx.xx" />
</intent-filter>

需求:解决该MissingPluginException异常,排查是否遗漏配置步骤或存在同类问题的通用解决方案。


解决方案

该错误根源是aad_oauth依赖的flutter_secure_storage插件未正确初始化或安装,以下是具体修复步骤:

  • 确认并安装依赖
    检查pubspec.yaml是否包含flutter_secure_storage,若缺失则添加后执行flutter pub get:

    dependencies:
      flutter_secure_storage: ^9.0.0 # 使用最新稳定版
    
  • 清理重构项目
    执行flutter clean清除旧构建缓存,然后完全重启应用(热重载/热重启无法修复插件通道注册问题),最后重新运行flutter run。

  • 补充Android权限配置
    针对Android 13及以上版本,需在AndroidManifest.xml中添加生物识别相关权限(flutter_secure_storage部分功能依赖):

    <uses-permission android:name="android.permission.USE_BIOMETRIC" />
    <uses-permission android:name="android.permission.USE_FINGERPRINT" />
    
  • 调整插件版本兼容性
    部分版本的aad_oauth与flutter_secure_storage存在兼容性冲突,可尝试切换aad_oauth到稳定兼容版本,比如:

    dependencies:
      aad_oauth: ^0.4.0 # 选择经过验证的稳定版本
    
  • 检查Flutter环境
    确保使用Flutter稳定版SDK,避免dev/beta版本的兼容性问题,执行flutter doctor排查环境异常。


内容的提问来源于stack exchange,提问作者Dasun Dola

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 04:22:32