java - 未收到来自凭据请求的密码
问题描述
我目前正在尝试从电子邮件/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());
解决方案
正如官方文件所述:
如果检索到的凭据的 ID 与设备登录帐户的 ID 匹配,则凭据将包含一个 ID 令牌,您可以使用该 ID 令牌进行身份验证而无需密码。
你可以在这里读更多关于它的内容:
https://developers.google.com/identity/smartlock-passwords/android/retrieve-credentials
和这里:
https://developers.google.com/identity/smartlock-passwords/android/idtoken-auth
推荐阅读
- java - 使用 JUnit 测试 Spring Boot JMS 发送方方法
- typescript - 对象键的字符串数组强类型
- reactjs - React ComponentDidUpdate 方法为每个道具触发部分更改为多个道具。如何知道所有的道具都更新了并采取相应的行动?
- javascript - 为什么我的随机不和谐模块抛出 UnhandledPromiseRejectionWarning?
- html - 在 HTML 上绘图的最佳方式是什么
- firebase - 错误“类型‘字符串’不是‘值’的‘文件’类型的子类型”
- javascript - 出现“获取商店菜单需要回调”错误
- angular - 日期选择器 Angular
- python - 检测是否支持 IPv6、与操作系统无关、没有外部程序?
- regex - 在正则表达式中匹配用于检测成分品牌的序列