Protect custom backend resources with App Check on Android
Stay organized with collections
Save and categorize content based on your preferences.
You can use App Check to protect non-Google custom backend resources for
your app, like your own self-hosted backend. To do so, you'll need to do both of
the following:
Modify your app client to send an App Check token along with each request
to your backend, as described on this page.
To ensure your backend requests include a valid, unexpired, App Check token,
wrap each request in a call to getAppCheckToken(). The App Check library
will refresh the token if necessary, and you can access the token in the
method's success listener.
Once you have a valid token, send it along with the request to your backend. The
specifics of how you accomplish this are up to you, but don't send
App Check tokens as part of URLs, including in query parameters, as this
makes them vulnerable to accidental leakage and interception. The recommended
approach is to send the token in a custom HTTP header.
When making a request to an endpoint for which you've enabled
replay protection,
wrap the request in a call to getLimitedUseAppCheckToken() instead of
getAppCheckToken():
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-22 UTC."],[],[],null,["You can use App Check to protect non-Google custom backend resources for\nyour app, like your own self-hosted backend. To do so, you'll need to do both of\nthe following:\n\n- Modify your app client to send an App Check token along with each request to your backend, as described on this page.\n- Modify your backend to require a valid App Check token with every request, as described in [Verify App Check tokens from a custom backend](/docs/app-check/custom-resource-backend).\n\nBefore you begin\n\nAdd App Check to your app, using either the default\n[Play Integrity provider](/docs/app-check/android/play-integrity-provider), or a\n[custom provider](/docs/app-check/android/custom-provider).\n\nSend App Check tokens with backend requests\n\nTo ensure your backend requests include a valid, unexpired, App Check token,\nwrap each request in a call to `getAppCheckToken()`. The App Check library\nwill refresh the token if necessary, and you can access the token in the\nmethod's success listener.\n\nOnce you have a valid token, send it along with the request to your backend. The\nspecifics of how you accomplish this are up to you, but *don't send\nApp Check tokens as part of URLs*, including in query parameters, as this\nmakes them vulnerable to accidental leakage and interception. The recommended\napproach is to send the token in a custom HTTP header.\n\nFor example, if you use Retrofit: \n\nKotlin \n\n```kotlin\nclass ApiWithAppCheckExample {\n interface YourExampleBackendService {\n @GET(\"yourExampleEndpoint\")\n fun exampleData(\n @Header(\"X-Firebase-AppCheck\") appCheckToken: String,\n ): Call\u003cList\u003cString\u003e\u003e\n }\n\n var yourExampleBackendService: YourExampleBackendService = Retrofit.Builder()\n .baseUrl(\"https://yourbackend.example.com/\")\n .build()\n .create(YourExampleBackendService::class.java)\n\n fun callApiExample() {\n Firebase.appCheck.getAppCheckToken(false).addOnSuccessListener { appCheckToken -\u003e\n val token = appCheckToken.token\n val apiCall = yourExampleBackendService.exampleData(token)\n // ...\n }\n }\n}https://github.com/firebase/snippets-android/blob/391c1646eacf44d2aab3f76bcfa60dfc6c14acf1/appcheck/app/src/main/java/com/google/firebase/example/appcheck/kotlin/ApiWithAppCheckExample.kt#L11-L31\n```\n\nJava \n\n```java\npublic class ApiWithAppCheckExample {\n private interface YourExampleBackendService {\n @GET(\"yourExampleEndpoint\")\n Call\u003cList\u003cString\u003e\u003e exampleData(\n @Header(\"X-Firebase-AppCheck\") String appCheckToken);\n }\n\n YourExampleBackendService yourExampleBackendService = new Retrofit.Builder()\n .baseUrl(\"https://yourbackend.example.com/\")\n .build()\n .create(YourExampleBackendService.class);\n\n public void callApiExample() {\n FirebaseAppCheck.getInstance()\n .getAppCheckToken(false)\n .addOnSuccessListener(new OnSuccessListener\u003cAppCheckToken\u003e() {\n @Override\n public void onSuccess(@NonNull AppCheckToken appCheckToken) {\n String token = appCheckToken.getToken();\n Call\u003cList\u003cString\u003e\u003e apiCall =\n yourExampleBackendService.exampleData(token);\n // ...\n }\n });\n }\n}https://github.com/firebase/snippets-android/blob/391c1646eacf44d2aab3f76bcfa60dfc6c14acf1/appcheck/app/src/main/java/com/google/firebase/example/appcheck/ApiWithAppCheckExample.java#L18-L43\n```\n\nReplay protection (beta)\n\nWhen making a request to an endpoint for which you've enabled\n[replay protection](/docs/app-check/custom-resource-backend#replay-protection),\nwrap the request in a call to `getLimitedUseAppCheckToken()` instead of\n`getAppCheckToken()`: \n\nKotlin \n\n```kotlin\nFirebase.appCheck.limitedUseAppCheckToken.addOnSuccessListener {\n // ...\n}https://github.com/firebase/snippets-android/blob/391c1646eacf44d2aab3f76bcfa60dfc6c14acf1/appcheck/app/src/main/java/com/google/firebase/example/appcheck/kotlin/ApiWithAppCheckExample.kt#L37-L39\n```\n\nJava \n\n```java\nFirebaseAppCheck.getInstance()\n .getLimitedUseAppCheckToken().addOnSuccessListener(\n new OnSuccessListener\u003cAppCheckToken\u003e() {\n @Override\n public void onSuccess(AppCheckToken appCheckToken) {\n String token = appCheckToken.getToken();\n // ...\n }\n }\n );https://github.com/firebase/snippets-android/blob/391c1646eacf44d2aab3f76bcfa60dfc6c14acf1/appcheck/app/src/main/java/com/google/firebase/example/appcheck/ApiWithAppCheckExample.java#L49-L58\n```"]]