Android'de Uygulama Kontrolü ile özel arka uç kaynaklarını koruma
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Uygulamanız için Google dışı özel arka uç kaynaklarını (ör. kendi kendine barındırılan arka ucunuz) korumak üzere App Check kullanabilirsiniz. Bunun için aşağıdakilerin ikisini de yapmanız gerekir:
- Uygulama istemcinizi, arka uçunuza gönderilen her istekle birlikte App Check jetonu gönderecek şekilde değiştirin. Bu işlem, bu sayfada açıklanmıştır.
- Arka ucunuzu, Özel bir arka uçtan gelen App Check jetonlarını doğrulama bölümünde açıklandığı gibi, her istekte geçerli bir App Check jetonu gerektirecek şekilde değiştirin.
Başlamadan önce
Varsayılan Play Integrity sağlayıcısını veya özel bir sağlayıcıyı kullanarak uygulamanıza App Check ekleyin.
Arka uç istekleriyle App Check jetonları gönderme
Arka uç isteklerinizin geçerli, süresi dolmamış bir App Check jetonu içerdiğinden emin olmak için her isteği getAppCheckToken()
çağrısına sarmalayın. App Check kitaplığı gerekirse jetonu yeniler ve jetona yöntemin başarı dinleyicisinden erişebilirsiniz.
Geçerli bir jetonunuz olduğunda, istekle birlikte arka ucunuza gönderin. Bunu nasıl yapacağınız size bağlıdır ancak URL'lerin bir parçası olarak App Check jetonları göndermeyin. Bu, sorgu parametreleri de dahil olmak üzere jetonların yanlışlıkla sızdırılmasına ve saldırıya uğramasına neden olur. Jetonu özel bir HTTP üstbilgisinde göndermeniz önerilir.
Örneğin, Retrofit kullanıyorsanız:
Kotlin
class ApiWithAppCheckExample {
interface YourExampleBackendService {
@GET("yourExampleEndpoint")
fun exampleData(
@Header("X-Firebase-AppCheck") appCheckToken: String,
): Call<List<String>>
}
var yourExampleBackendService: YourExampleBackendService = Retrofit.Builder()
.baseUrl("https://yourbackend.example.com/")
.build()
.create(YourExampleBackendService::class.java)
fun callApiExample() {
Firebase.appCheck.getAppCheckToken(false).addOnSuccessListener { appCheckToken ->
val token = appCheckToken.token
val apiCall = yourExampleBackendService.exampleData(token)
// ...
}
}
}
Java
public class ApiWithAppCheckExample {
private interface YourExampleBackendService {
@GET("yourExampleEndpoint")
Call<List<String>> exampleData(
@Header("X-Firebase-AppCheck") String appCheckToken);
}
YourExampleBackendService yourExampleBackendService = new Retrofit.Builder()
.baseUrl("https://yourbackend.example.com/")
.build()
.create(YourExampleBackendService.class);
public void callApiExample() {
FirebaseAppCheck.getInstance()
.getAppCheckToken(false)
.addOnSuccessListener(new OnSuccessListener<AppCheckToken>() {
@Override
public void onSuccess(@NonNull AppCheckToken appCheckToken) {
String token = appCheckToken.getToken();
Call<List<String>> apiCall =
yourExampleBackendService.exampleData(token);
// ...
}
});
}
}
Tekrar koruması (beta)
Yeniden oynatma korumasını etkinleştirdiğiniz bir uç noktaya istekte bulunurken isteği getAppCheckToken()
yerine getLimitedUseAppCheckToken()
çağrısıyla sarmalayın:
Kotlin
Firebase.appCheck.limitedUseAppCheckToken.addOnSuccessListener {
// ...
}
Java
FirebaseAppCheck.getInstance()
.getLimitedUseAppCheckToken().addOnSuccessListener(
new OnSuccessListener<AppCheckToken>() {
@Override
public void onSuccess(AppCheckToken appCheckToken) {
String token = appCheckToken.getToken();
// ...
}
}
);
Aksi belirtilmediği sürece bu sayfanın içeriği Creative Commons Atıf 4.0 Lisansı altında ve kod örnekleri Apache 2.0 Lisansı altında lisanslanmıştır. Ayrıntılı bilgi için Google Developers Site Politikaları'na göz atın. Java, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-08-23 UTC.
[null,null,["Son güncelleme tarihi: 2025-08-23 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```"]]