Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
App Check memiliki dukungan bawaan untuk beberapa penyedia: DeviceCheck dan App Attest di platform Apple, Play Integrity di Android, dan reCAPTCHA Enterprise di aplikasi web (ringkasan). Penyedia tersebut sudah dikenal dengan baik dan akan memenuhi kebutuhan sebagian besar developer. Namun, Anda juga dapat menerapkan penyedia App Check kustom Anda sendiri. Menggunakan penyedia kustom diperlukan jika:
Anda ingin menggunakan penyedia selain penyedia bawaan.
Anda ingin menggunakan penyedia bawaan dengan cara yang tidak didukung.
Anda ingin memverifikasi perangkat menggunakan platform selain Apple, Android, dan web. Misalnya, Anda dapat membuat penyedia App Check untuk OS desktop atau perangkat Internet of Things.
Anda ingin menerapkan teknik verifikasi Anda sendiri pada platform apa pun.
Ringkasan
Untuk menerapkan penyedia App Check kustom, Anda memerlukan lingkungan backend aman yang dapat menjalankan Firebase Admin SDK Node.js.
Lingkungan tersebut bisa berupa Cloud Functions, platform container seperti Cloud Run, atau server Anda sendiri.
Dari lingkungan ini, Anda akan memberikan layanan yang dapat diakses jaringan yang menerima bukti keaslian dari klien aplikasi Anda. Jika bukti autentikasi lulus penilaian keaslian, layanan akan menampilkan token App Check. Indikator spesifik yang Anda gunakan sebagai bukti keaslian akan bergantung pada penyedia pihak ketiga yang Anda gunakan atau indikator yang Anda tetapkan sendiri, jika menerapkan logika kustom.
Umumnya, layanan ini dapat Anda ekspos sebagai endpoint REST atau gRPC, sesuai pilihan Anda.
Buat endpoint yang dapat diakses jaringan yang dapat menerima data keaslian dari klien Anda. Misalnya, menggunakan Cloud Functions:
// Create endpoint at https://example-app.cloudfunctions.net/fetchAppCheckTokenexports.fetchAppCheckToken=functions.https.onRequest((request,response)=>{// ...});
Tambahkan ke logika endpoint yang menilai data keaslian. Ini adalah logika inti dari penyedia App Check kustom, yang harus Anda tulis sendiri.
Jika Anda telah memastikan bahwa klien tersebut asli, gunakan Admin SDK untuk membuat token App Check dan menampilkan token tersebut beserta masa berlakunya kepada klien:
constadmin=require('firebase-admin');admin.initializeApp();// ...admin.appCheck().createToken(appId).then(function(appCheckToken){// Token expires in an hour.constexpiresAt=Math.floor(Date.now()/1000)+60*60;// Return appCheckToken and expiresAt to the client.}).catch(function(err){console.error('Unable to create App Check token.');console.error(err);});
Jika Anda tidak dapat memverifikasi keaslian klien, tampilkan error (misalnya, tampilkan error HTTP 403).
Opsional: Tetapkan time to live (TTL) untuk token App Check yang dikeluarkan oleh penyedia kustom Anda dengan meneruskan objek AppCheckTokenOptions ke createToken(). Anda dapat menetapkan TTL ke semua nilai dalam rentang 30 menit hingga 7 hari. Saat menetapkan nilai ini, perhatikan pertimbangan berikut:
Keamanan: TTL yang lebih singkat memberikan keamanan yang lebih kuat karena mengurangi periode penyalahgunaan oleh penyerang atas token yang bocor atau diintersepsi.
Performa: TTL yang lebih singkat membuat aplikasi Anda akan lebih sering melakukan pengesahan. Karena proses pengesahan aplikasi meningkatkan latensi ke permintaan jaringan setiap kali dilakukan, TTL yang singkat dapat memengaruhi performa aplikasi Anda.
TTL default selama 1 jam termasuk wajar untuk sebagian besar aplikasi.
Langkah berikutnya
Setelah Anda menerapkan logika sisi server penyedia kustom, pelajari cara menggunakannya dari klien Apple, Android, dan web.
[null,null,["Terakhir diperbarui pada 2025-08-23 UTC."],[],[],null,["App Check has built-in support for several providers: DeviceCheck and App\nAttest on Apple platforms, Play Integrity on Android, and reCAPTCHA Enterprise\nin web apps ([overview](/docs/app-check)). These are well-understood providers\nthat should meet the needs of most developers. You can, however, also implement\nyour own custom App Check providers. Using a custom provider is necessary\nwhen:\n\n- You want to use a provider other than the built-in ones.\n\n- You want to use the built-in providers in unsupported ways.\n\n- You want to verify devices using platforms other than Apple, Android, and the\n web. For example, you could create App Check providers for desktop OSes or\n Internet-of-Things devices.\n\n- You want to implement your own verification techniques on any platform.\n\nOverview\n\nTo implement a custom App Check provider, you need a secure backend\nenvironment that can run the Node.js [Firebase Admin SDK](/docs/admin/setup).\nThis can be Cloud Functions, a container platform such as\n[Cloud Run](https://cloud.google.com/run), or your own server.\n\nFrom this environment, you will provide a network-accessible service that\nreceives proof of authenticity from your app clients, and---if the proof of\nauthenticity passes your authenticity assessment---returns an App Check\ntoken. The specific indicators you use as proof of authenticity will depend on\neither the third-party provider you're using, or the indicators of your own\ninvention, if you're implementing custom logic.\n\nUsually, you expose this service as a REST or gRPC endpoint, but this detail is\nup to you.\n\nCreate the token acquisition endpoint\n\n1. [Install and initialize the Admin SDK](/docs/admin/setup).\n\n2. Create a network-accessible endpoint that can receive authenticity data from\n your clients. For example, using Cloud Functions:\n\n // Create endpoint at https://example-app.cloudfunctions.net/fetchAppCheckToken\n exports.fetchAppCheckToken = functions.https.onRequest((request, response) =\u003e {\n // ...\n });\n\n3. Add to the endpoint logic that assesses the authenticity data. This is the\n core logic of your custom App Check provider, which you will need to\n write yourself.\n\n4. If you determine the client to be authentic, use the Admin SDK to mint\n an App Check token and return it and its expiration time to the client:\n\n const admin = require('firebase-admin');\n admin.initializeApp();\n\n // ...\n\n admin.appCheck().createToken(appId)\n .then(function (appCheckToken) {\n // Token expires in an hour.\n const expiresAt = Math.floor(Date.now() / 1000) + 60 * 60;\n\n // Return appCheckToken and expiresAt to the client.\n })\n .catch(function (err) {\n console.error('Unable to create App Check token.');\n console.error(err);\n });\n\n | **Note:** If you encounter a token signing error while creating a new token, make sure your service account has the required permissions. See the [Admin SDK troubleshooting guide](/docs/auth/admin/create-custom-tokens#troubleshooting).\n\n If you can't verify the client's authenticity, return an error (for example,\n return an HTTP 403 error).\n5. **Optional** : Set the time-to-live (TTL) for App Check tokens issued by\n your custom provider by passing an `AppCheckTokenOptions` object to\n `createToken()`. You can set the TTL to any value between 30 minutes and 7\n days. When setting this value, be aware of the following tradeoffs:\n\n - Security: Shorter TTLs provide stronger security, because it reduces the window in which a leaked or intercepted token can be abused by an attacker.\n - Performance: Shorter TTLs mean your app will perform attestation more frequently. Because the app attestation process adds latency to network requests every time it's performed, a short TTL can impact the performance of your app.\n\n The default TTL of 1 hour is reasonable for most apps.\n\nNext steps\n\nNow that you've implemented your custom provider's server-side logic, learn how\nto use it from your [Apple](/docs/app-check/ios/custom-provider),\n[Android](/docs/app-check/android/custom-provider), and [web](/docs/app-check/web/custom-provider) clients."]]