【问题标题】:Smart Lock shows accounts not from my appSmart Lock 显示不是来自我的应用的帐户
【发布时间】:2018-06-13 19:28:03
【问题描述】:

我正在我的应用程序上实施谷歌智能锁,目前,我们只在应用程序端实施,一旦用户允许保存凭据,例如在重新安装时自动登录。 但是,当我从 password.google.com 中删除密码时,或者当我在 google 帐户没有为该应用程序存储凭据的设备上运行该应用程序时,库会显示一个对话框,建议其他网站和应用程序电子邮件。我需要禁用此行为,我只想建议凭据和电子邮件(如果它们属于我的应用)。

我正在使用以下代码请求凭据:

    private void requestCredentials() {
            CredentialRequest request = new CredentialRequest.Builder()
                   .setPasswordLoginSupported(true)
                   .setIdTokenRequested(true)
                   .build();
            mProgressSmartLock.show();
    credentialsClient.request(request).addOnCompleteListener(credentialsApiRequestCompleteListener());
    }

和听众:

    public OnCompleteListener<CredentialRequestResponse> credentialsApiRequestCompleteListener(){
            return new OnCompleteListener<CredentialRequestResponse>() {
                @Override
                public void onComplete(@NonNull Task<CredentialRequestResponse> task) {
                // Successfully read the credential without any user interaction, this
                // means there was only a single credential and the user has auto
                // sign-in enabled.
                mProgressSmartLock.dismiss();
                if (task.isSuccessful()) {
                    processRetrievedCredential(task.getResult().getCredential());
                    return;
                }

                    // This is most likely the case where the user has multiple saved
                // credentials and needs to pick one. This requires showing UI to
                // resolve the read request.
                Exception e = task.getException();
                if (e instanceof ResolvableApiException) {
                    ResolvableApiException rae = (ResolvableApiException) e;
                    resolveResult(rae, RC_READ);
                    return;
                }

                // This means only a hint is available
                if (e instanceof ApiException) {
                    Crashlytics.logException(e);
                }
            }
        };
    }

保存凭据:

private void saveCredentials(String email, String password) {
        final Credential credential = new Credential.Builder(email)
                .setPassword(password)
                .build();

        mProgress.show();

        credentialsClient.save(credential).addOnCompleteListener(credentialsApiSaveCompleteListener());
}

听众:

public OnCompleteListener<Void> credentialsApiSaveCompleteListener(){
    return new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                mProgress.dismiss();
                return;
            }

            Exception e = task.getException();
            if (e instanceof ResolvableApiException) {
                // The first time a credential is saved, the user is shown UI
                // to confirm the action. This requires resolution.
                ResolvableApiException rae = (ResolvableApiException) e;
                resolveResult(rae, RC_SAVE);
            } else {
                // Save failure cannot be resolved.
                mProgress.dismiss();
            }
        }
    };
}

【问题讨论】:

标签: android google-play-services google-smartlockpasswords play-services-auth-base-license google-play-services-3.3.0


【解决方案1】:

为避免出现此对话框(列出所有电子邮件地址以帮助填写表格,即使没有保存密码),如果任务的 getStatusCode() 返回 SIGN_IN_REQUIRED,请不要解析。

抱歉,此详细信息在最近的文档更改中丢失,感谢您的报告。将尽快更新,抱歉造成混淆。

【讨论】:

  • 所以我收集到的是,如果我的应用程序不支持 Google/Twitter/etc 登录并使用自己的电子邮件/密码组合,那么这个 API 就没有用,对吧?因为它总是会返回SIGN_IN_REQUIRED 并从我保存的所有登录中显示用户/密码组合。由于 afaik 无法按“我的应用程序的域”过滤该列表,它将返回所有凭据,而不仅仅是与我的应用程序网站相关的凭据,因此它对我的需求并没有真正有用。有什么方法可以按我的应用程序的域进行过滤,因此我只显示与我的网站相关的登录信息?
【解决方案2】:

如果凭据不是来自应用程序或应用程序未保存任何凭据,则statusCode 将是SIGN_IN_REQUIRED。但如果您之前保存过任何凭证,您将收到来自statusCode 的另一个INT 值。可以在Resolveable Exception判断。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-20
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多