简体   繁体   English

使用 Google Smartlock Api 在应用程序和网站之间自动集成

[英]Automatic integration between app and website with Google Smartlock Api

I'm trying to set up an app which uses Google Smartlock feature to fetch credentials stored in Google's password manager and automatically log in. For this, I have set up a test website , where an user can login (while browsing in Google Chrome), and if she chooses to save the password for the site, it'll be saved in Google's password manager.我正在尝试设置一个应用程序,该应用程序使用 Google Smartlock 功能获取存储在 Google 密码管理器中的凭据并自动登录。为此,我设置了一个测试网站,用户可以在其中登录(在 Google Chrome 中浏览时) ,如果她选择保存该网站的密码,该密码将保存在 Google 的密码管理器中。 The sample app that I have should be able to automatically fetch the stored credentials and use them to log in to the app content page.我拥有的示例应用程序应该能够自动获取存储的凭据并使用它们登录到应用程序内容页面。

I have followed the documentation thoroughly.我已经彻底遵循了文档。 Here's the Digital Assets file hosted at the website root :这是托管在网站根目录下的数字资产文件:

[{
  "relation": ["delegate_permission/common.get_login_creds"],
  "target": {
    "namespace": "web",
    "site": "https://officeloginsso.azurewebsites.net"
  }
 },
 {
  "relation": ["delegate_permission/common.get_login_creds"],
  "target": {
    "namespace": "android_app",
    "package_name": "com.mslogin.t_sopal.msloginsso",
    "sha256_cert_fingerprints": [
      "XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX"
    ]
  }
 },{
  "relation": ["delegate_permission/common.get_login_creds"],
  "target": {
    "namespace": "android_app",
    "package_name": "com.login.codelab.sopalsmartlock",
    "sha256_cert_fingerprints": [
      "XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX"
    ]
  }
}]

The Manifest file snippet that includes the link to the json file :包含 json 文件链接的清单文件片段:

<application>    
<meta-data android:name="asset_statements" android:resource="@string/asset_statements" />
</application>

Strings.xml :字符串.xml:

<string name="asset_statements" translatable="false">
      [{
        \"include\": \"https://officeloginsso.azurewebsites.net/.well-known/assetlinks.json\"
      }]
  </string>

The app has been published (with regional restriction) and the json file has been hosted, which returns response :该应用程序已发布(有区域限制)并且已托管 json 文件,该文件返回响应:

 HTTP/1.1 200 OK
 Content-Type: application/json

Despite having done these, the app still can't pick up the username/password stored through the website.尽管已经完成了这些,该应用程序仍然无法获取通过网站存储的用户名/密码。 Is there something I am missing here?有什么我在这里想念的吗?

Per discussions in the comments, the resolution was to ensure that the asset links file matches the package and signature of a published Play Store app and that the apk being tested is signed with the same certificate as the published app (ie, not signed from a debug / development keystore).根据评论中的讨论,解决方案是确保资产链接文件与已发布的 Play 商店应用程序的包和签名相匹配,并且正在测试的 apk 使用与已发布应用程序相同的证书进行签名(即,不是从调试/开发密钥库)。 You can use an alpha/beta channel if you want to test before releasing to a production channel.如果您想在发布到生产渠道之前进行测试,您可以使用 Alpha/Beta 渠道。

In general, here are the things to check (some mentioned in the question):一般来说,以下是要检查的事项(问题中提到了一些):

  • ensure your asset links file is valid json containing both app (the Play Store package and cert fingerprint) and any associated sign-in domains (desktop, mobile web, regional domains, etc. each of which needs it's own assetlinks.json at the well-known location, but may point to a canonical copy) without a path component (eg no trailing slash)确保您的资产链接文件是有效的 json,其中包含应用程序(Play 商店包和证书指纹)和任何关联的登录域(桌面、移动网络、区域域等。每个域都需要自己的 assetlinks.json) - 已知位置,但可能指向规范副本)没有路径组件(例如没有尾部斜杠)

  • check (eg with curl -I) that the file is served with an HTTP 200 (no redirects) from the well-known location (must be available at exactly /.well-known/assetlinks.json ) with "Content-Type: application/json" header and is accessible to bots/crawlers检查(例如用卷曲-I)该文件送达从已知位置的HTTP 200(无重定向)(必须是可用正好/.well-known/assetlinks.json )与“内容类型:应用程序/json" 标头,机器人/爬虫可以访问

  • verify that asset_statements in the app manifest is under application and is valid escaped json and points to the asset links file in the well-known https location.验证在应用程序清单asset_statements正在application和有效逃脱JSON和指向资产的链接文件中的知名HTTPS位置。 The app need to be published before we can detect this, but you can use an alpha/beta channel for testing, so long as that apk has the latest version code在我们检测到此应用程序之前需要发布该应用程序,但您可以使用 alpha/beta 通道进行测试,只要该 apk 具有最新版本代码

Once these requirements are met and the app is published in the Play Store, the association will be enabled automatically with 1-2 business days.一旦满足这些要求并且应用在 Play 商店中发布,关联将在 1-2 个工作日内自动启用。 Details of these requirements are available at https://developers.google.com/identity/smartlock-passwords/android/associate-apps-and-sites有关这些要求的详细信息,请访问https://developers.google.com/identity/smartlock-passwords/android/associate-apps-and-sites

Since you have defined the assetlinks.json in this path由于您已在此路径中定义了assetlinks.json

https://officeloginsso.azurewebsites.net/.well-known/assetlinks.json https://officeloginsso.azurewebsites.net/.well-known/assetlinks.json

is very important to define into your robots.txt file this lines:在您的robots.txt文件中定义以下几行非常重要:

User-agent: *
Allow: /.well-known/

to allow GoogleBot access to your file:允许 GoogleBot 访问您的文件:

https://officeloginsso.azurewebsites.net/.well-known/assetlinks.json https://officeloginsso.azurewebsites.net/.well-known/assetlinks.json

read about robots.txt .阅读robots.txt

To integrate Smart Lock for Passwords into your Android app, you must add calls to the Credentials API to your app's start-up and sign-in flow.要将 Smart Lock for Passwords 集成到您的 Android 应用程序中,您必须将对Credentials API 的调用添加到应用程序的启动和登录流程中。

To retrieve credentials:要检索凭据:

  • When the app starts, if no user is already signed in, call CredentialsApi.request() .当应用启动时,如果没有用户登录,则调用CredentialsApi.request()

  • If getStatus().isSuccess() returns true, get the user's credentials with getCredential() and use them to sign in.如果getStatus().isSuccess()返回 true,则使用getCredential()获取用户凭据并使用它们登录。

  • If getStatus().isSuccess() returns false and getStatusCode() returns RESOLUTION_REQUIRED , user input is required to pick a credential.如果getStatus().isSuccess()返回 false 并且getStatusCode()返回RESOLUTION_REQUIRED ,则需要用户输入才能选择凭证。 Call startResolutionForResult() to prompt the user to select a saved account, then call getParcelableExtra(Credential.EXTRA_KEY) to get the user's credentials and use them to sign in.调用startResolutionForResult()提示用户选择一个已保存的帐户,然后调用getParcelableExtra(Credential.EXTRA_KEY)获取用户的凭据并使用它们进行登录。

Note: If signing in with the retrieved credentials fails because the password is incorrect or the account doesn't exist, delete the credentials from Smart Lock.注意:如果使用检索到的凭据登录失败,因为密码不正确或帐户不存在,请从 Smart Lock 中删除凭据。

This document shows how to integrate Smart Lock for Passwords into your Android app.文档展示了如何将 Smart Lock for Passwords 集成到您的 Android 应用程序中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM