開始使用
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
總覽
Digital Asset Links 通訊協定和 API 可讓應用程式或網站對其他應用程式或網站建立可驗證的公開聲明。舉例來說,網站可以宣告其與特定 Android 應用程式相關聯,也可以宣告要與其他網站共用使用者憑證。
以下列舉 Digital Asset Links 的幾種用途:
- 如果已安裝網站,網站 A 就會聲明,該網站連結應在行動裝置上透過指定應用程式開啟。
- 網站 A 宣告可與網站 B 共用 Chrome 使用者憑證,因此如果使用者已登入網站 A,就不必登入網站 B。
- 應用程式 A 宣告可以與網站 B 共用裝置設定 (例如位置)。
重要詞彙
- 主體:主體是指做出聲明的應用程式或網站。在 Digital Asset Links 中,主體一律為代管陳述清單的應用程式或網站。
- 陳述式清單:陳述式會出現在包含一或多個陳述式的陳述式清單中。陳述式清單屬於明文,可公開存取,位置在主體控管的位置,不容易遭人假冒或竄改。
可以是獨立檔案,也可以是另一個大型項目的區段。舉例來說,在網站上,這個檔案是完整的檔案,在 Android 應用程式中,則是應用程式資訊清單中的部分。任何人都能透過非專屬方式查看及驗證對帳單。詳情請參閱陳述式清單說明文件。
- 陳述: 陳述式是結構緊密的 JSON 結構,其中包含「關係」relation (聲明內容為「啟用共用憑證」的聲明) 和「目標」relation (與關聯相關的網站或應用程式)。因此,每個陳述就像一個句子,主體表示與相關相關目標。
- 陳述使用者:陳述式使用者向主體要求陳述式清單,檢查是否針對指定主體執行陳述式,如果存在,則可執行指定的動作。詳情請參閱聲明的陳述式說明文件.
快速使用範例
以下是一個簡單的範例,說明 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 應用程式連結說明文件。
- 上述陳述式中的 Android 應用程式擁有意圖篩選器,用於指定所處理網址的配置、主機和路徑模式:在本範例中為 https://www.example.com。意圖篩選器包含一個特殊屬性
android:autoVerify
,這是 Android M 的新屬性,代表 Android 應在應用程式安裝時於意圖篩選器中描述的網站上驗證聲明。
- 使用者安裝應用程式。Android 查看具有
autoVerify
屬性的意圖篩選器,並檢查指定網站是否存在陳述式清單。如果有,Android 會檢查該檔案是否包含授予應用程式連結處理的陳述式,並根據憑證雜湊來驗證應用程式。如果一切檢查完畢,Android 就會將所有 https://www.example.com 意圖轉送至 example.com 應用程式。
- 使用者在自己的裝置上點選 https://www.example.com/puppies 連結。這類連結沒有位置:瀏覽器、Google Search Appliance 建議頁面或其他位置。Android 會將意圖轉送至 example.com 應用程式。
- example.com 應用程式會收到意圖,並選擇處理該意圖,然後在應用程式中開啟小狗頁面。如果應用程式因故拒絕處理連結,或者應用程式不在裝置上,系統就會將連結傳送至符合該意圖模式 (通常是瀏覽器) 的下一個預設意圖處理常式。
重要注意事項和限制:
- 通訊協定不會驗證產生陳述式的主體,但該陳述式位於與主體密切相關的特定位置,且該陳述式是由主體控管。
- 通訊協定不會驗證陳述式目標,但可讓呼叫端驗證目標。舉例來說,陳述式可透過憑證雜湊和套件名稱來識別行動應用程式目標。
- 此通訊協定不會原生執行任何陳述式動作,而是能夠公開陳述式。使用此陳述式時,使用的應用程式必須驗證並決定是否採取行動。Android M 會以原生方式執行這些步驟;舉例來說,如果網站將連結處理作業委派給特定應用程式,Android 會檢查並驗證陳述式、驗證目標應用程式,然後為應用程式提供處理指定連結的選項。
- 這個通訊協定並不會啟用對兩方的陳述:網站 A 可以發表關於網站 B 的聲明,但網站 A 無法就網站 B 和網站 C 之間的關係發表聲明。不過,如果網站 B 信任網站 A,就能檢查網站 A 是否有授予網站 C 權限的聲明,並決定實作網站 C。
後續步驟
- 看看是否有適用於您的用途的明確說明文件。
- 瞭解如何建立對帳單。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-06-26 (世界標準時間)。
[null,null,["上次更新時間: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,["# Getting Started\n\nOverview\n--------\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\n### Key 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-------------------\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\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----------\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)"]]