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

Flutter Passkeys 2.1.0注册时RP ID验证失败问题求助

解决Flutter Passkeys 2.1.0注册时RP ID无法验证的PlatformException问题

你遇到的[50152] RP ID cannot be validated.异常是Android端验证Passkey依赖方ID(RP ID)时失败导致的,以下是针对性的排查和修复步骤:

1. 修正AndroidManifest.xml的Intent Filter配置

你当前把data标签放在了LAUNCHER的Intent Filter里,这会导致域名关联验证失效。需要拆分出单独的域名验证Intent Filter,并开启自动验证:

<!-- 保留原有的启动器Filter -->
<intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

<!-- 新增用于域名关联的Filter,必须开启autoVerify -->
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="https" android:host="xyz.org" />
</intent-filter>

确保你部署的assetlinks.json完全符合要求:

  • 路径必须是https://xyz.org/.well-known/assetlinks.json,不能有任何路径错误
  • 文件内容中的package_name必须和你的Android应用包名完全一致(比如com.yourcompany.yourapp)
  • 证书指纹要匹配你当前使用的签名密钥:
    • Debug环境用默认debug keystore的指纹,可通过keytool -list -v -keystore ~/.android/debug.keystore获取(密码默认是android)
    • Release环境用你的正式签名密钥指纹
  • 确保文件可以被公开访问,返回状态码200,且Content-Type为application/json

3. 修复AuthenticatorSelection参数冲突

你的代码中requireResidentKey: false和residentKey: 'required'存在参数冲突,这会导致验证逻辑异常,需要调整为一致的配置:

final authenticatorSelection = AuthenticatorSelectionType(
  requireResidentKey: true, // 和residentKey值保持一致
  residentKey: 'required',
  userVerification: 'required',
);

如果不需要常驻密钥(Resident Key),可以改为:

final authenticatorSelection = AuthenticatorSelectionType(
  requireResidentKey: false,
  residentKey: 'discouraged',
  userVerification: 'required',
);

4. 确认RP ID的可访问性

  • 确保你的测试设备可以正常访问xyz.org,没有DNS解析失败、网络拦截或HTTPS证书问题
  • 测试环境不要使用localhost或本地IP,必须使用可公开解析的域名;如果是本地开发,可通过adb shell setprop debug.firebase.appindexing.android_debug_host xyz.org强制跳过域名验证(仅用于调试)

5. 检查Challenge格式

注册请求中的challenge必须是base64url编码的原始字节数据,不能直接使用普通字符串。确认你的challenge值符合格式要求(无填充字符=,用-替代+、_替代/)。

6. 清理缓存并重新构建

最后执行以下步骤确保配置生效:

  • 运行flutter clean清理项目缓存
  • 卸载设备上的旧应用
  • 重新执行flutter run部署应用

内容的提问来源于stack exchange,提问作者Srasti Verma

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 12:15:11