App Check mit dem Debugging-Anbieter in Web-Apps verwenden
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Wenn Sie Ihre App nach der Registrierung für App Check in einer Umgebung ausführen möchten, die normalerweise nicht als gültig eingestuft wird, z. B. lokal während der Entwicklung oder in einer Umgebung für kontinuierliche Integration (CI), können Sie einen Debug-Build Ihrer App erstellen, der anstelle eines echten Attestierungsanbieters den App Check-Debug-Anbieter verwendet.App Check
Debug-Anbieter auf localhost verwenden
So verwenden Sie den Debugging-Anbieter, während Sie Ihre App über localhost ausführen (z. B. während der Entwicklung):
Aktivieren Sie in Ihrem Debug-Build den Fehlerbehebungsmodus, indem Sie self.FIREBASE_APPCHECK_DEBUG_TOKEN auf true setzen, bevor Sie App Check initialisieren. Beispiel:
self.FIREBASE_APPCHECK_DEBUG_TOKEN=true;firebase.appCheck().activate(/* site key or provider */);
Rufen Sie Ihre Web-App lokal auf und öffnen Sie die Entwicklertools des Browsers. In der Debug-Konsole wird ein Debug-Token angezeigt:
AppCheck debug token: "123a4567-b89c-12d3-e456-789012345678". You will
need to safelist it in the Firebase console for it to work.
Wählen Sie im Bereich App Check der Firebase Console im Überlaufmenü Ihrer App die Option Debug-Tokens verwalten aus. Registrieren Sie dann das Debug-Token, das Sie im vorherigen Schritt protokolliert haben.
Nachdem Sie das Token registriert haben, wird es von den Firebase-Backend-Diensten als gültig akzeptiert.
Da mit diesem Token ohne gültiges Gerät auf Ihre Firebase-Ressourcen zugegriffen werden kann, ist es wichtig, dass Sie es vertraulich behandeln. Übertragen Sie es nicht in ein öffentliches Repository und widerrufen Sie es sofort in der Firebase-Konsole, wenn ein registriertes Token kompromittiert wird.
Dieses Token wird lokal in Ihrem Browser gespeichert und immer verwendet, wenn Sie Ihre App im selben Browser auf demselben Computer verwenden. Wenn Sie das Token in einem anderen Browser oder auf einem anderen Computer verwenden möchten, legen Sie self.FIREBASE_APPCHECK_DEBUG_TOKEN auf den Tokenstring anstelle von true fest.
Debug-Anbieter in einer CI-Umgebung verwenden
So verwenden Sie den Debug-Anbieter in einer Continuous Integration-Umgebung (CI):
Wählen Sie im Bereich App Check der Firebase Console im Überlaufmenü Ihrer App die Option Debug-Tokens verwalten aus. Erstellen Sie dann ein neues Debug-Token. Sie benötigen das Token im nächsten Schritt.
Da mit diesem Token ohne gültiges Gerät auf Ihre Firebase-Ressourcen zugegriffen werden kann, ist es wichtig, dass Sie es vertraulich behandeln. Übertragen Sie es nicht in ein öffentliches Repository und widerrufen Sie es sofort in der Firebase-Konsole, wenn ein registriertes Token kompromittiert wird.
Fügen Sie das gerade erstellte Debug-Token dem sicheren Schlüsselspeicher Ihres CI-Systems hinzu, z. B. den verschlüsselten Secrets von GitHub Actions oder den verschlüsselten Variablen von Travis CI.
Konfigurieren Sie Ihr CI-System bei Bedarf so, dass Ihr Debug-Token in der CI-Umgebung als Umgebungsvariable verfügbar ist. Geben Sie der Variablen einen Namen wie APP_CHECK_DEBUG_TOKEN_FROM_CI.
Aktivieren Sie in Ihrem Debug-Build den Debug-Modus, indem Sie self.FIREBASE_APPCHECK_DEBUG_TOKEN auf den Wert der Umgebungsvariable für das Debug-Token festlegen, bevor Sie App Check importieren. Beispiel:
[null,null,["Zuletzt aktualisiert: 2025-08-23 (UTC)."],[],[],null,["If, after you have registered your app for App Check, you want to run your\napp in an environment that App Check would normally not classify as valid,\nsuch as locally during development, or from a continuous integration (CI)\nenvironment, you can create a debug build of your app that uses the\nApp Check debug provider instead of a real attestation provider.\n| **Warning:** The debug provider allows access to your Firebase resources from unverified devices. **Don't** use the debug provider in production builds of your app, and **don't** share your debug builds with untrusted parties.\n\nUse the debug provider on localhost\n\nTo use the debug provider while running your app from `localhost` (during\ndevelopment, for example), do the following:\n| **Warning:** *Do not* try to enable `localhost` debugging by adding `localhost` to reCAPTCHA's allowed domains. Doing so would allow anyone to run your app from their local machines!\n\n1. In your debug build, enable debug mode by setting\n `self.FIREBASE_APPCHECK_DEBUG_TOKEN` to `true` before you initialize\n App Check. For example:\n\n Web \n\n self.FIREBASE_APPCHECK_DEBUG_TOKEN = true;\n initializeAppCheck(app, { /* App Check options */ });\n\n Web \n\n self.FIREBASE_APPCHECK_DEBUG_TOKEN = true;\n firebase.appCheck().activate(/* site key or provider */);\n\n | **Note:** In Firebase Web SDK versions before v9, `self.FIREBASE_APPCHECK_DEBUG_TOKEN` is read at import time, and not at initialization/activation time. This required it to be set in `index.html` before the code bundle is loaded. To avoid this restriction, upgrade to v9.\n2. Visit your web app locally and open the browser's developer tool. In the\n debug console, you'll see a debug token:\n\n ```\n AppCheck debug token: \"123a4567-b89c-12d3-e456-789012345678\". You will\n need to safelist it in the Firebase console for it to work.\n ```\n3. In the [**App Check**](//console.firebase.google.com/project/_/appcheck) section\n of the Firebase console, choose **Manage debug tokens** from your app's\n overflow menu. Then, register the debug token you logged in the previous\n step.\n\nAfter you register the token, Firebase backend services will accept it as valid.\n\nBecause this token allows access to your Firebase resources without a\nvalid device, it is crucial that you keep it private. Don't commit it to a\npublic repository, and if a registered token is ever compromised, revoke it\nimmediately in the Firebase console.\n\nThis token is stored locally in your browser and will be used whenever you use\nyour app in the same browser on the same machine. If you want to use the\ntoken in another browser or on another machine, set\n`self.FIREBASE_APPCHECK_DEBUG_TOKEN` to the token string instead of `true`.\n\nUse the debug provider in a CI environment\n\nTo use the debug provider in a continuous integration (CI) environment, do the following:\n\n1. In the [**App Check**](//console.firebase.google.com/project/_/appcheck) section\n of the Firebase console, choose **Manage debug tokens** from your app's\n overflow menu. Then, create a new debug token. You'll need the token in the\n next step.\n\n Because this token allows access to your Firebase resources without\n a valid device, it is crucial that you keep it private. Don't commit it to a\n public repository, and if a registered token is ever compromised, revoke it\n immediately in the Firebase console.\n\n2. Add the debug token you just created to your CI system's secure key store\n (for example, GitHub Actions' [encrypted secrets](https://docs.github.com/en/actions/reference/encrypted-secrets)\n or Travis CI's [encrypted variables](https://docs.travis-ci.com/user/environment-variables/#defining-encrypted-variables-in-travisyml)).\n\n3. If necessary, configure your CI system to make your debug token available\n within the CI environment as an environment variable. Name the variable\n something like `APP_CHECK_DEBUG_TOKEN_FROM_CI`.\n\n4. In your debug build, enable debug mode by setting\n `self.FIREBASE_APPCHECK_DEBUG_TOKEN` to the value of the debug token\n environment variable before you import App Check. For example:\n\n Web \n\n self.FIREBASE_APPCHECK_DEBUG_TOKEN = process.env.APP_CHECK_DEBUG_TOKEN_FROM_CI;\n initializeAppCheck(app, { /* App Check options */ });\n\n Web \n\n self.FIREBASE_APPCHECK_DEBUG_TOKEN = process.env.APP_CHECK_DEBUG_TOKEN_FROM_CI;\n firebase.appCheck().activate(/* site key or provider */);\n\nWhen your app runs in a CI environment, Firebase backend services will accept\nthe token it sends as valid."]]