مثال: اعتبارنامه ها را در چندین وب سایت و چندین برنامه اندروید به اشتراک بگذارید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
برای راهاندازی اشتراکگذاری اعتبار در چندین وبسایت و چندین برنامه Android، باید:
- تعیین دامنه اصلی : یک URL را به عنوان نقطه مرجع اصلی برای پیوندها انتخاب کنید.
- فایلهای
assetlinks.json
را ایجاد کنید :- دامنه اصلی : یک فایل
assetlinks.json
در دامنه اصلی خود ایجاد کنید که تمام اعتبارنامه های اشتراک گذاری دامنه ها را فهرست می کند. - دامنههای دیگر : یک فایل
assetlinks.json
در هر یک از دامنههای دیگر ایجاد کنید، که هر کدام به دامنه اصلی پیوند داده میشوند.
- پیوند دارایی دیجیتال را در مانیفست هر برنامه پیکربندی کنید : هر برنامه را طوری تنظیم کنید که به فایل
assetlinks.json
در دامنه اصلی پیوند داده شود.
در مثال زیر، ما example.com را بهعنوان دامنه اصلی تعیین کردیم، و همه دامنههای فهرستشده دیگر اعتبارنامهها را با example.com و در سراسر خودشان به اشتراک میگذارند.
دو برنامه با نام بسته های زیر نیز اعتبارنامه ها را با همه وب سایت ها و بین آنها به اشتراک می گذارند:
-
com.example.android.myapplication
-
com.example.appname
قبل از راهاندازی اشتراکگذاری اعتبار، باید پیشنیازها را تکمیل کنید .
برای اعلام اشتراکگذاری اعتبار در این وبسایتها و برنامههای Android:
یک فایل assetlinks.json
با محتوای زیر ایجاد کنید:
[
{
"relation": ["delegate_permission/common.get_login_creds"],
"target": {
"namespace": "web",
"site": "https://example.com"
}
},
{
"relation": ["delegate_permission/common.get_login_creds"],
"target": {
"namespace": "web",
"site": "https://example.org"
}
},
{
"relation": ["delegate_permission/common.get_login_creds"],
"target": {
"namespace": "web",
"site": "https://example.net"
}
},
{
"relation": ["delegate_permission/common.get_login_creds"],
"target": {
"namespace": "web",
"site": "https://myownpersonaldomain.com"
}
},
{
"relation" : [
"delegate_permission/common.get_login_creds"
],
"target" : {
"namespace" : "android_app",
"package_name" : "com.example.android.myapplication",
"sha256_cert_fingerprints" : [ "AA:BB:CC:DD:EE:FF:11:22:33:44:55:66:77:88:99:00:AA:BB:CC:DD:EE:FF:11:22:33:44:55:66:77:88:99:00"
]
}
},
{
"relation" : [
"delegate_permission/common.get_login_creds"
],
"target" : {
"namespace" : "android_app",
"package_name" : "com.example.appname",
"sha256_cert_fingerprints" : [ "00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF"
]
}
}
]
فایل JSON پیوندهای دارایی دیجیتال را در مکان شناخته شده مربوطه در دامنه اصلی میزبانی کنید، در این مورد: https://example.com/.well-known/assetlinks.json
.
فایل assetlinks.json
دیگری با محتوای زیر ایجاد کنید:
[
{
"relation": ["delegate_permission/common.get_login_creds"],
"target": {
"namespace": "web",
"site": "example.com"
}
}
]
کپیهای میزبان این فایل JSON پیوندهای دارایی دیجیتال در مکان زیر در سایر دامنهها، در این مورد:
-
example.org/.well-known/assetlinks.json
-
example.net/.well-known/assetlinks.json
-
mypersonaldomain.com/.well-known/assetlinks.json
خط زیر را به هر دو فایل مانیفست برنامه های Android در <application>
اضافه کنید:
<meta-data android:name="asset_statements" android:resource="@string/asset_statements"/>
با اعلام ارتباط در برنامه Android، پیوند دارایی دیجیتال را در مانیفست پیکربندی کنید. یک شی اضافه کنید که فایلهای assetlinks.json
را برای بارگیری مشخص میکند. در این مورد:
<string name="asset_statements" translatable="false">
[{
\"include\": \"https://example.com/.well-known/assetlinks.json\"
}]
</string>
پس از انجام این مراحل، اشتراکگذاری اعتبار یکپارچه را در چندین وبسایت و برنامه اندروید با موفقیت راهاندازی کردهاید.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Example: Share credentials across multiple websites and multiple Android apps\n\nTo set up credential sharing across multiple websites and multiple Android apps\nyou must:\n\n- **Designate a primary domain**: Choose one URL as the primary reference point for links.\n- **Create `assetlinks.json` files** :\n - **Primary domain** : Create an `assetlinks.json` file on your primary domain that lists all domains sharing credentials.\n - **Other domains** : Create an `assetlinks.json` file on each of the other domains, each linking back to the primary domain.\n- **Configure digital asset linking in each App's manifest** : Set up each app to link back to the `assetlinks.json` file in the primary domain.\n\n| **Important:** While Google treats credential sharing relationships as transitive, individual [Digital Asset Links are\n| not](https://developers.google.com/digital-asset-links/reference/rpc/google.digitalassetlinks.v1).\n\nIn the following example, we designated\n[example.com](https://example.com/) as the primary domain, and all other\nlisted domains share credentials with\n[example.com](https://example.com/) and across themselves.\n\n- [example.com](https://example.com/) (primary domain)\n- [example.org](https://example.jp/)\n- [example.net](https://example.de/)\n- [myownpersonaldomain.com](http://myownpersonaldomain.com)\n\nThe two apps with the following package names also share credentials with all\nthe websites and between them:\n\n- `com.example.android.myapplication`\n- `com.example.appname`\n\nBefore setting up credential sharing you must [complete the prerequisites](/identity/credential-sharing/set-up#prerequisites).\n\nTo declare credential sharing across these websites and Android apps:\n\n1. Create an `assetlinks.json` file with the following content:\n\n [\n {\n \"relation\": [\"delegate_permission/common.get_login_creds\"],\n \"target\": {\n \"namespace\": \"web\",\n \"site\": \"https://example.com\"\n }\n },\n {\n \"relation\": [\"delegate_permission/common.get_login_creds\"],\n \"target\": {\n \"namespace\": \"web\",\n \"site\": \"https://example.org\"\n }\n },\n {\n \"relation\": [\"delegate_permission/common.get_login_creds\"],\n \"target\": {\n \"namespace\": \"web\",\n \"site\": \"https://example.net\"\n }\n },\n {\n \"relation\": [\"delegate_permission/common.get_login_creds\"],\n \"target\": {\n \"namespace\": \"web\",\n \"site\": \"https://myownpersonaldomain.com\"\n }\n },\n {\n \"relation\" : [\n \"delegate_permission/common.get_login_creds\"\n ],\n \"target\" : {\n \"namespace\" : \"android_app\",\n \"package_name\" : \"com.example.android.myapplication\",\n \"sha256_cert_fingerprints\" : [ \"AA:BB:CC:DD:EE:FF:11:22:33:44:55:66:77:88:99:00:AA:BB:CC:DD:EE:FF:11:22:33:44:55:66:77:88:99:00\"\n ]\n }\n },\n {\n \"relation\" : [\n \"delegate_permission/common.get_login_creds\"\n ],\n \"target\" : {\n \"namespace\" : \"android_app\",\n \"package_name\" : \"com.example.appname\",\n \"sha256_cert_fingerprints\" : [ \"00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF\"\n ]\n }\n }\n ]\n\n2. Host the Digital Asset Links JSON file in the corresponding well-known\n location on the primary domain, in this case:\n `https://example.com/.well-known/assetlinks.json`.\n\n3. Create another `assetlinks.json` file with the following content:\n\n [\n {\n \"relation\": [\"delegate_permission/common.get_login_creds\"],\n \"target\": {\n \"namespace\": \"web\",\n \"site\": \"example.com\"\n }\n }\n ]\n\n4. Host copies of this Digital Asset Links JSON file at the following location\n on the other domains, in this case:\n\n - `example.org/.well-known/assetlinks.json`\n - `example.net/.well-known/assetlinks.json`\n - `mypersonaldomain.com/.well-known/assetlinks.json`\n5. Add the following line to both Android Apps manifests files under\n `\u003capplication\u003e`:\n\n \u003cmeta-data android:name=\"asset_statements\" android:resource=\"@string/asset_statements\"/\u003e\n\n6. Configure digital asset linking in the manifest by declaring the association\n in the Android app. Add an object that specifies the `assetlinks.json` files\n to load. In this case:\n\n \u003cstring name=\"asset_statements\" translatable=\"false\"\u003e\n [{\n \\\"include\\\": \\\"https://example.com/.well-known/assetlinks.json\\\"\n }]\n \u003c/string\u003e\n\nAfter following these steps, you have successfully set up seamless credential\nsharing across multiple websites and Android apps."]]