使用入门
使用集合让一切井井有条 根据您的偏好保存内容并对其进行分类。
概览
借助 Digital Asset Links 协议和 API,应用或网站可以发布有关其他应用或网站的公开、可验证的声明。例如,网站可以声明自己与特定 Android 应用相关联,也可以声明希望与其他网站共享用户凭据。
以下是 Digital Asset Links 的一些可能用途:
- 网站 A 声明,应在移动设备上的指定应用中打开指向其网站的链接(如果已安装该应用)。
- 网站 A 声明可与网站 B 共享其 Chrome 用户凭据,这样一来,用户在登录网站 A 后无需登录网站 B。
- 应用 A 声明它可以与网站 B 共享设备设置(例如位置信息)。
关键术语
- 主账号:主账号是做出该声明的应用或网站。在 Digital Asset Links 中,主账号始终是托管声明列表的应用或网站。
- 语句列表:语句包含在包含一个或多个语句的语句列表中。声明列表是明文且可公开访问的位置,位于由主账号控制且难以仿冒或篡改的位置。该文件可以是独立文件,也可以是其他较大内容的一部分。例如,在网站上,它是整个文件;在 Android 应用中,它是应用清单中的一个部分。 任何人都可以使用非专有方法查看和验证声明。如需了解详情,请参阅对帐单列表文档。
- 语句: 语句是一种结构紧凑的 JSON 结构,由“关系”(语句所说的事项,例如“启用凭据共享”)和目标(关系适用的网站或应用)组成。relationrelation因此,每个语句都像是一个句子,其中“principal”表示与“目标”有关的关系。
- 语句使用者:语句使用者向主账号请求语句列表,检查是否存在针对指定主账号的语句,如果存在,则可以执行指定的操作。如需了解详情,请参阅恢复文档的语句.
快速使用示例
下面是一个简化的示例,展示了 www.example.com 网站如何使用 Digital Asset Links 来指定指向该网站中所有网址的链接应在指定的应用(而不是浏览器)中打开:
- 网站 www.example.com 在 https://www.example.com/.well-known/assetlinks.json 上发布了一份声明列表。这是声明列表在网站上的官方名称和位置;任何其他位置或具有任何其他名称的声明列表对于此网站均无效。在我们的示例中,语句列表包含一个语句,允许其 Android 应用在其网站上打开链接:
[{ "relation": ["delegate_permission/common.handle_all_urls"], "target" : { "namespace": "android_app", "package_name": "com.example.app", "sha256_cert_fingerprints": ["hash_of_app_certificate"] } }]
语句列表支持 [ ] 标记内的语句数组,但我们的示例文件仅包含一条语句。 sha256_cert_fingerprints
是应用签名证书的 SHA256 指纹。如需了解详情,请参阅 Android App Links 文档。 - 上述语句中列出的 Android 应用具有一个 intent 过滤器,用于指定它要处理的网址的架构、主机和路径模式:在本例中为 https://www.example.com。该 intent 过滤器包含 Android M 中新增的一个特殊属性
android:autoVerify
,它表示 Android 应在安装应用时验证 intent 过滤器中所述的网站上的语句。 - 用户安装应用。Android 会看到具有
autoVerify
属性的 intent 过滤器,并检查指定网站上是否存在语句列表;如果存在,Android 会检查该文件是否包含向应用授予链接处理的语句,并根据证书哈希验证应用。如果检查了所有结果,Android 会将所有 https://www.example.com intent 转发到 example.com 应用。 - 用户点击其设备上的 https://www.example.com/puppies 链接。此链接可以是任何位置中:浏览器、Google Search Appliance 建议中或其他位置。Android 会将 intent 转发到 example.com 应用。
- example.com 应用收到该 intent 并选择处理该 intent,从而在应用中打开 puppies 页面。如果应用由于某种原因拒绝处理该链接,或者该应用未安装在设备上,则系统会将该链接发送到符合该 intent 模式的下一个默认 intent 处理程序(通常是浏览器)。
重要注意事项和限制:
- 该协议不会对做出该语句的主帐号进行身份验证,但该语句位于与主帐号高度关联的特定位置,并且受主帐号控制。
- 该协议不会对语句目标进行身份验证,但它会为调用方提供一种方式来对目标进行身份验证(例如,语句通过证书哈希和软件包名称标识移动应用目标)。
- 该协议本身不会执行任何语句操作;相反,它支持公开语句,使用方应用必须验证这些语句,然后决定是否执行相应操作以及如何执行操作。Android M 会以原生方式为您执行这些步骤;例如,如果网站将链接处理委托给特定应用,则 Android 会检查并验证该声明,验证目标应用,然后为应用提供处理给定链接的选项。
- 该协议不允许对两个第三方做出陈述:也就是说,网站 A 可以就网站 B 发表陈述,而网站 A 不能对网站 B 与网站 C 的关系做出陈述。但是,如果网站 B 信任网站 A,它可以查看网站 A 中是否有向网站 C 授予权限的声明,并决定实施该声明。
后续步骤
- 查看是否有适用于您的用例的明确文档。
- 了解如何创建对账单。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-06-26。
[null,null,["最后更新时间 (UTC):2024-06-26。"],[[["\u003cp\u003eDigital Asset Links enable apps and websites to make verifiable statements about their relationships with other apps and websites, such as link handling or credential sharing.\u003c/p\u003e\n"],["\u003cp\u003eThese statements are stored in a publicly accessible statement list, typically an "assetlinks.json" file hosted by the app or website making the statement.\u003c/p\u003e\n"],["\u003cp\u003eAndroid M and above automatically uses Digital Asset Links to verify website-to-app associations and direct links to the appropriate app if installed.\u003c/p\u003e\n"],["\u003cp\u003eThe protocol provides a foundation for trust and delegation between digital entities but relies on consumers to validate and act upon the statements.\u003c/p\u003e\n"]]],[],null,["Overview\n\nThe Digital Asset Links protocol and API enable an app or website to make public,\nverifiable *statements* about other apps or websites. For example, a website\ncan declare that it is associated with a specific Android app, or it can declare that\nit wants to share user credentials with another website.\n\nHere are some possible uses for Digital Asset Links:\n\n- Website A declares that links to its site should open in a designated app on mobile devices, if the app is installed.\n- Website A declares that it can share its Chrome user credentials with website B so that the user won't have to log in to website B if it is logged into website A.\n- App A declares that it can share device settings, such as location, with website B.\n\nKey terms\n\n- **Principal:** The principal is the app or website making the statement. In Digital Asset Links, the principal is always the app or website that hosts the statement list.\n- **Statement list** : Statements are contained in a *statement list* that contains one or more statements. A statement list is cleartext and publicly accessible, in a location that is controlled by the principal and difficult to spoof or tamper with. It can be a free-standing file, or a section of another, larger item. For example, on a website, it is an entire file; in an Android app, it is a section in the app manifest. Statements can be viewed and verified by anyone, using non-proprietary methods. [See the statement list documentation for more information](/digital-asset-links/v1/create-statement).\n- **Statement:** A statement is a tightly structured JSON construct that consists of a *relation* (what the statement says to do, for example: Enable sharing credentials) and a *target* (the website or app that the relation applies to). Therefore, each statement is like a sentence, where *principal* says *relation* about *target* . \n- **Statement consumer:** A statement consumer requests a statement list from a principal, checks for the presence of a statement against a given principal, and if it exists, can perform the action specified. [See the statement comsuming documentation for more information](/digital-asset-links/v1/consuming)*.*\n\nQuick usage example\n\nHere's a very simplified example of how the website www.example.com could\nuse Digital Asset Links to specify that any links to URLs in that site should\nopen in a designated app rather than the browser:\n\n1. The website www.example.com publishes a statement list at https://www.example.com/.well-known/assetlinks.json. This is the official name and location for a statement list on a site; statement lists in any other location, or with any other name, are not valid for this site. In our example, the statement list consists of one statement, granting its Android app the permission to open links on its site: \n\n ```\n [{\n \"relation\": [\"delegate_permission/common.handle_all_urls\"],\n \"target\" : { \"namespace\": \"android_app\", \"package_name\": \"com.example.app\",\n \"sha256_cert_fingerprints\": [\"hash_of_app_certificate\"] }\n }]\n ```\n A statement list supports an array of statements within the \\[ \\] marks, but our example file contains only one statement. `sha256_cert_fingerprints` is the SHA256 fingerprints of your app's signing certificate. Find more details in the [Android App Links documentation](https://developer.android.com/training/app-links/verify-android-applinks#web-assoc).\n2. The Android app listed in the statement above has an intent filter that specifies the scheme, host, and path pattern of URLs that it wants to handle: in this case, https://www.example.com. The intent filter includes a special attribute `android:autoVerify`, new to Android M, which indicates that Android should verify the statement on the website described in the intent filter when the app is installed.\n3. A user installs the app. Android sees the intent filter with the `autoVerify` attribute and checks for the presence of the statement list at the specified site; if present, Android checks whether that file includes a statement granting link handling to the app, and verifies the app against the statement by certificate hash. If everything checks out, Android will then forward any https://www.example.com intents to the example.com app.\n4. The user clicks a link to https://www.example.com/puppies on their device. This link could be anywhere: in a browser, in a Google Search Appliance suggestion, or anywhere else. Android forwards the intent to the example.com app.\n5. The example.com app receives the intent and chooses to handle it, opening the puppies page in the app. If for some reason the app had declined to handle the link, or if the app were not on the device, then the link would have been sent to the next default intent handler matching that intent pattern (often the browser).\n\nImportant considerations and limitations:\n\n- The protocol does not authenticate the principal making the statement, but the statement is located in a specific location strongly associated with the principal, and under control of the principal.\n- The protocol does not authenticate the statement target, but it provides a means for the caller to authenticate the target (for example, a statement identifies mobile app targets by certificate hash and package name).\n- The protocol does not natively perform any statement actions; rather, it enables the ability to expose statements, which a consuming application must validate and then decide whether and how to act upon. Android M natively performs these steps for you; for example, if a website delegates link handling to a specific app, Android checks and verifies the statement, verifies the target app, and then offers the app the option to handle the given link.\n- The protocol does not enable making statements about two third parties: that is, website A can make a statement about website B, but website A cannot make a statement about website B's relationship to website C. However, if website B trusts website A, it can check website A for a statement granting permission to website C, and decide to implement that.\n\nNext steps\n\n1. [See if there is explicit documentation for your use case.](/digital-asset-links/v1/using)\n2. [Learn about creating a statement.](/digital-asset-links/v1/create-statement)"]]