Repository navigation
feat(app_check): support CLI-provisioned debug tokens on Apple and Web - #18947
AustinBenoit wants to merge 3 commits into
Conversation
- Apple (iOS/macOS): temporarily set `AppCheckDebugToken` instead of `FIRAAppCheckDebugToken` when Dart supplies a non-empty `debugToken` and restore it via `defer`; under `#if DEBUG` log `currentDebugToken()` rather than `localDebugToken()` when no Dart token is supplied so CLI-provisioned Simulator tokens are preserved. - Web: extract `configureWebDebugTokenGlobal` to preserve an existing non-empty `globalThis.FIREBASE_APPCHECK_DEBUG_TOKEN` string when `WebDebugProvider.debugToken` is null or empty, and add Chrome tests.
There was a problem hiding this comment.
Code Review
This pull request updates the Firebase App Check debug token handling for iOS and Web platforms. On iOS, it updates the environment variable key to AppCheckDebugToken, manages its state using a defer block to restore any prior token, and limits debug token printing to debug builds. On Web, it introduces a helper function configureWebDebugTokenGlobal to manage the global FIREBASE_APPCHECK_DEBUG_TOKEN variable and adds corresponding unit tests. The review feedback suggests improving the Swift implementation by using optional chaining to avoid variable shadowing and simplify compatibility, and simplifying the Dart code by removing a redundant isDefinedAndNotNull check.
| if debugToken?.isEmpty ?? true, let debugProvider { | ||
| print("Firebase App Check Debug Token: \(debugProvider.currentDebugToken())") | ||
| } |
There was a problem hiding this comment.
Using optional chaining with debugProvider?.currentDebugToken() is cleaner, avoids shadowing the debugProvider variable, and is fully backward-compatible with older Swift versions (avoiding Swift 5.7's implicit optional binding shorthand).
| if debugToken?.isEmpty ?? true, let debugProvider { | |
| print("Firebase App Check Debug Token: \(debugProvider.currentDebugToken())") | |
| } | |
| if debugToken?.isEmpty ?? true, let token = debugProvider?.currentDebugToken() { | |
| print("Firebase App Check Debug Token: \(token)") | |
| } |
| if (existing != null && | ||
| existing.isDefinedAndNotNull && | ||
| existing.isA<JSString>() && | ||
| (existing as JSString).toDart.isNotEmpty) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
The check existing.isDefinedAndNotNull is redundant because existing != null already ensures that the value is neither Dart null nor JS null/undefined (since getProperty returns Dart null for JS null or undefined). We can simplify this condition.
if (existing != null &&
existing.isA<JSString>() &&
(existing as JSString).toDart.isNotEmpty) {
return;
}| delegateProvider = debugProvider | ||
| #if DEBUG | ||
| if debugToken?.isEmpty ?? true, let debugProvider { | ||
| print("Firebase App Check Debug Token: \(debugProvider.currentDebugToken())") |
There was a problem hiding this comment.
Is this going to print the CLI debugToken? Is this behavior by design?
There was a problem hiding this comment.
Removed in 0363091. The plugin no longer prints the debug token: the native SDK already logs a locally generated token with the instructions for registering it, and it does not log a token provisioned by the Firebase CLI, so printing it here was not intended.
SelaseKay
left a comment
There was a problem hiding this comment.
Hi @AustinBenoit, thanks for the PR.
The web change looks good.
On Apple, the CLI token is read from ~/.config/configstore/firebase-appcheck.json by firebase/firebase-ios-sdk#17017. That commit is on main and is not in the SDKs this repo pin (Swift Package Manager 13.1.1). AppCheckDebugProvider in those versions still uses the environment variable or a generated UserDefaults token, so merging this as it stands leaves the Simulator on the old flow. The same upstream change also compiles that file lookup out on macOS.
I'd wait for a release that contains that commit.
The plugin printed the debug token itself when Dart supplied none. The native SDK already logs a locally generated token with instructions for registering it, and deliberately does not log a token provisioned by the Firebase CLI, so the plugin's print would have exposed that one.
|
@SelaseKay firebase-ios-sdk 13.2.0 was released today and includes firebase/firebase-ios-sdk#17017, the CLI debug token lookup on Simulator. |
Description
Enables
firebase_app_checkon Apple (iOS/macOS) and Web to preserve and use CLI-provisioned App Check debug tokens without manual copy-pasting or overriding injected tokens:packages/firebase_app_check/firebase_app_checkSwift plugin):debugTokenvalues toAppCheckDebugToken(set only when non-empty) and restores any prior value viadeferafterAppCheckDebugProvider(app: app)initializes.packages/firebase_app_check/firebase_app_check_web):@visibleForTesting configureWebDebugTokenGlobal(String? debugToken)and uses it ingetAppCheckInstanceforWebDebugProvider.debugTokenis provided, setsFIREBASE_APPCHECK_DEBUG_TOKENto that token. Otherwise, preserves an existing non-empty string already set onglobalContext.FIREBASE_APPCHECK_DEBUG_TOKENinstead of overwriting it withtrue, falling back totrueonly when unset, empty, or non-string.test/firebase_app_check_web_test.dartcovering pre-set token preservation, explicit override, andtruefallback.Testing
dart format --output=none --set-exit-if-changed(firebase_app_check_web)dart analyze --fatal-infos(firebase_app_check_web: no issues)flutter test --platform chrome packages/firebase_app_check/firebase_app_check_web/test/firebase_app_check_web_test.dart(10/10 passed)FirebaseAppCheckPlugin.swift, symlinked to macOS) rely on GitHub Actions macOS/iOS CI for Xcode compilation and testing.Related Issues
Related upstream seamless debug token work:
firebase/firebase-tools#11418,firebase/firebase-ios-sdk#17017.Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]).This will ensure a smooth and quick review process. Updating the
pubspec.yamland changelogs is not required.///).melos run analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?
Prepared with AI coding agents (Google-internal, built on Jetski) and opened by @AustinBenoit.