未收到凭证请求中的密码

时间:2021-02-12 17:58:39

标签: java android

我目前正在尝试使用代码从电子邮件/gmail 帐户获取凭据,我在网上找到了一个框架代码。但是在我的旧android上运行后,我发现虽然我可以得到id,但我无法得到密码。有原因吗?为什么?

private void requestCredentials() {
        // Request all of the user's saved username/password credentials.  We are not using
        // setAccountTypes so we will not load any credentials from other Identity Providers.
        CredentialRequest request = new CredentialRequest.Builder()
                .setPasswordLoginSupported(true)
                .setAccountTypes(IdentityProviders.GOOGLE)
                .build();

        mCredentialsClient.request(request).addOnCompleteListener(
                new OnCompleteListener<CredentialRequestResponse>() {
                    @Override
                    public void onComplete(@NonNull Task<CredentialRequestResponse> task) {
                        hideProgress();

                        if (task.isSuccessful()) {
                            // Successfully read the credential without any user interaction, this
                            // means there was only a single credential and the user has auto
                            // sign-in enabled.
                            processRetrievedCredential(task.getResult().getCredential(), false);
                            return;
                        }
    }
private void processRetrievedCredential(Credential credential, boolean isHint) {

        mEmailField.setText(credential.getId());
        mPasswordField.setText(credential.getPassword());

1 个答案:

答案 0 :(得分:0)

如官方文件所述:

<块引用>

如果检索到的凭据的 ID 与帐户的 ID 匹配 设备登录后,凭据将包含一个 ID 令牌 无需密码即可进行身份验证。

您可以在此处阅读更多相关信息:

https://developers.google.com/identity/smartlock-passwords/android/retrieve-credentials

这里:

https://developers.google.com/identity/smartlock-passwords/android/idtoken-auth