Proteggere le risorse di backend personalizzate con App Check nei progetti C++
Mantieni tutto organizzato con le raccolte Salva e classifica i contenuti in base alle tue preferenze.
Puoi utilizzare App Check per proteggere le risorse di backend personalizzate non Google per la tua app, ad esempio il tuo backend auto-hosted. A questo scopo, dovrai svolgere entrambe le seguenti operazioni:
Modifica il client dell'app in modo da inviare un token App Check insieme a ogni richiesta al tuo backend, come descritto in questa pagina.
Inviare token App Check con le richieste di backend
Per assicurarti che le richieste di backend includano un token App Check valido e non scaduto, precede ogni richiesta con una chiamata a AppCheck::GetAppCheckToken(). La libreria Appcheck aggiornerà il token, se necessario.
Una volta ottenuto un token valido, invialo insieme alla richiesta al tuo backend. Le specifiche su come eseguire questa operazione dipendono da te, ma non inviare i token di App Check all'interno degli URL, inclusi nei parametri di query, in quanto ciò li rende vulnerabili a fughe e intercettazioni accidentali. L'approccio consigliato è inviare il token in un'intestazione HTTP personalizzata.
Ad esempio:
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.}}}
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-06-17 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 }"]]