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

Android平台Passkey身份验证注册失败问题求助

关于Android Passkey注册抛出SecurityError的问题

我正尝试遵循官方文档实现Passkey注册,同时参考了相关codelab(该示例在我的Android设备上可正常运行)。我创建了最小测试用例,用Java复刻了codelab中的逻辑,代码如下:

private void signUp() {
    CreatePublicKeyCredentialRequest createPublicKeyCredentialRequest = new CreatePublicKeyCredentialRequest(fetchRegistrationJsonFromServer());

    credentialManager.createCredentialAsync(
            createPublicKeyCredentialRequest,
            this,
            new CancellationSignal(),
            getMainExecutor(),
            new CredentialManagerCallback<CreateCredentialResponse, CreateCredentialException>() {
                @Override
                public void onResult(CreateCredentialResponse result) {
                    Log.d(TAG, "Registration success");
                }

                @Override
                public void onError(CreateCredentialException e) {
                    Log.e(TAG, "Registration failure - " + e.getClass().getName());

                    if (e instanceof CreatePublicKeyCredentialDomException) {
                        // Handle the passkey DOM errors thrown according to the
                        // WebAuthn spec.
                        Log.e(TAG, String.valueOf(((CreatePublicKeyCredentialDomException)e).getDomError()));
                    } else if (e instanceof CreateCredentialCancellationException) {
                        // The user intentionally canceled the operation and chose not
                        // to register the credential.
                    } else if (e instanceof CreateCredentialInterruptedException) {
                        // Retry-able error. Consider retrying the call.
                    } else if (e instanceof CreateCredentialProviderConfigurationException) {
                        // Your app is missing the provider configuration dependency.
                        // Most likely, you're missing the
                        // "credentials-play-services-auth" module.
                    } else if (e instanceof CreateCredentialUnknownException) {
                    } else if (e instanceof CreateCustomCredentialException) {
                        // You have encountered an error from a 3rd-party SDK. If
                        // you make the API call with a request object that's a
                        // subclass of
                        // CreateCustomCredentialRequest using a 3rd-party SDK,
                        // then you should check for any custom exception type
                        // constants within that SDK to match with e.type.
                        // Otherwise, drop or log the exception.
                    }
                }
            }
    );
}

private String fetchRegistrationJsonFromServer() {
    String response = Utils.readFromAssets(this, "reg.txt");

    return response.replace("<userId>", getEncodedUserId())
            .replace("<userName>", username)
            .replace("<userDisplayName>", username)
            .replace("<challenge>", getEncodedChallenge());
}

private String getEncodedUserId() {
    SecureRandom random = new SecureRandom();
    byte[] bytes = new byte[64];
    random.nextBytes(bytes);

    return Base64.encodeToString(bytes, Base64.NO_WRAP | Base64.URL_SAFE | Base64.NO_PADDING);
}

private String getEncodedChallenge() {
    SecureRandom random = new SecureRandom();
    byte[] bytes = new byte[32];
    random.nextBytes(bytes);

    return Base64.encodeToString(bytes, Base64.NO_WRAP | Base64.URL_SAFE | Base64.NO_PADDING);
}

目前测试用例执行失败,抛出类型为androidx.credentials.exceptions.domerrors.SecurityError的CreatePublicKeyCredentialDomException异常。我已按照文档正确配置Digital Asset Links。目前我认为问题可能出在注册模板上,但尝试替换"rp.id"值为com.unibeam.passkey1后仍无法解决问题,寻求帮助。

内容的提问来源于stack exchange,提问作者Ariel Malka

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 11:27:24