首页 > 解决方案 > 未收到来自凭据请求的密码

问题描述

我目前正在尝试从电子邮件/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());

标签: javaandroid

解决方案


正如官方文件所述:

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

你可以在这里读更多关于它的内容:

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

和这里:

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


推荐阅读