Benutzerdefinierte Back-End-Ressourcen mit App Check in C++-Projekten schützen
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Mit App Check können Sie benutzerdefinierte Backend-Ressourcen für Ihre App schützen, die nicht von Google stammen, z. B. Ihr eigenes selbst gehostetes Backend. Dazu müssen Sie Folgendes tun:
Ändern Sie Ihren App-Client so, dass er mit jeder Anfrage an Ihr Backend ein App Check-Token sendet, wie auf dieser Seite beschrieben.
Damit Ihre Backend-Anfragen ein gültiges, nicht abgelaufenes App Check-Token enthalten, rufen Sie vor jeder Anfrage AppCheck::GetAppCheckToken() auf. Die App Check-Bibliothek aktualisiert das Token bei Bedarf.
Sobald Sie ein gültiges Token haben, senden Sie es zusammen mit der Anfrage an Ihr Backend. Wie Sie das genau umsetzen, liegt bei Ihnen. Senden Sie App Check-Tokens jedoch nicht als Teil von URLs, auch nicht in Abfrageparametern, da sie dadurch anfällig für unbeabsichtigtes Weitergeben und Abfangen werden. Die empfohlene Methode ist, das Token in einem benutzerdefinierten HTTP-Header zu senden.
Beispiel:
voidCallApiExample(){firebase_app_check::AppCheck*app_check=firebase::app_check::AppCheck::GetInstance();Future<std::string>app_check_future=app_check->GetAppCheckToken(false);app_check_future.OnCompletion([&](constFuture<std::string>&future_token){if(future_token.result()){// Got a valid App Check token. Include it in your own http calls.}}}
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-23 (UTC)."],[],[],null,["\u003cbr /\u003e\n\nYou 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 the [default providers](/docs/app-check/cpp/default-providers).\n\nSend App Check tokens with backend requests\n\nTo ensure your backend requests include a valid, unexpired, App Check token,\nprecede each request with a call to `AppCheck::GetAppCheckToken()`. The App\nCheck library will refresh the token if necessary.\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: \n\n void CallApiExample() {\n firebase_app_check::AppCheck* app_check = firebase::app_check::AppCheck::GetInstance();\n Future\u003cstd::string\u003e app_check_future = app_check-\u003eGetAppCheckToken(false);\n app_check_future.OnCompletion([&](const Future\u003cstd::string\u003e& future_token) {\n if (future_token.result()) {\n // Got a valid App Check token. Include it in your own http calls.\n }\n }\n }"]]