Files
Andrew Heard c06a1d7199 feat(appcheck): read CLI debug token on Simulator (#17017)
Co-authored-by: Nick Cooke <36927374+ncooke3@users.noreply.github.com>

In a Simulator, AppCheckDebugProvider now uses the debug token that
`firebase appcheck:debugtokens:create` saves to
~/.config/configstore/firebase-appcheck.json on the host, so apps
launched from Xcode work without manually registering a token. The
token is looked up by each app's Google App ID through
SIMULATOR_HOST_HOME. The lookup is compiled out on devices, macOS and
Mac Catalyst. No public API changes.

Debug tokens are now resolved in this order:
1. AppCheckDebugToken or FIRAAppCheckDebugToken environment variable
2. Token from the CLI config store (Simulator only)
3. Token stored in UserDefaults
4. Newly generated UUID

The config store comes before the stored token so a newly provisioned
token takes effect without reinstalling the app.

Logging:
- I-FAA004003: debug token loaded from the config store.
- I-FAA004004: exchanging the config store token failed; suggests
  re-running the CLI with --force and relaunching.
- I-FAA004002: exchanging an environment variable token failed; now
  names the variables instead of showing an unrelated local token.
- I-FAA004005: the config store exists but can't be read or parsed.
A missing file, or a path where it can't exist (e.g., ~/.config is a
regular file), is silent. Exchange-failure warnings are skipped when
the server is unreachable, and no message includes the token.
2026-11-06 19:23:51 -05:00

60 lines
2.4 KiB
Objective-C

/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <Foundation/Foundation.h>
#if __has_include(<AppCheckCore/AppCheckCore-Swift.h>)
#import <AppCheckCore/AppCheckCore-Swift.h>
#elif __has_include("AppCheckCore-Swift.h")
#import "AppCheckCore-Swift.h"
#else
@import AppCheckCore;
#endif
#import "FirebaseCore/Extension/FirebaseCoreInternal.h"
extern FIRLoggerService kFIRLoggerAppCheck;
// FIRAppCheck.m
FOUNDATION_EXPORT NSString *const kFIRLoggerAppCheckMessageCodeProviderFactoryIsMissing;
FOUNDATION_EXPORT NSString *const kFIRLoggerAppCheckMessageCodeProviderIsMissing;
// FIRAppCheckDebugProvider.m
FOUNDATION_EXPORT NSString *const kFIRLoggerAppCheckMessageDebugProviderIncompleteFIROptions;
FOUNDATION_EXPORT NSString *const kFIRLoggerAppCheckMessageCodeDebugTokenExchangeFailed;
FOUNDATION_EXPORT NSString *const kFIRLoggerAppCheckMessageCodeDebugTokenFromConfigStore;
FOUNDATION_EXPORT NSString *const kFIRLoggerAppCheckMessageCodeConfigStoreDebugTokenExchangeFailed;
FOUNDATION_EXPORT NSString *const kFIRLoggerAppCheckMessageCodeDebugToken;
// FIRAppCheckDebugTokenConfigStore.m
FOUNDATION_EXPORT NSString *const kFIRLoggerAppCheckMessageCodeDebugTokenConfigStoreUnreadable;
// FIRDeviceCheckProvider.m
FOUNDATION_EXPORT NSString *const kFIRLoggerAppCheckMessageDeviceCheckProviderIncompleteFIROptions;
// FIRRecaptchaProvider.m
FOUNDATION_EXPORT NSString *const kFIRLoggerAppCheckMessageRecaptchaProviderIncompleteFIROptions;
FOUNDATION_EXPORT NSString *const kFIRLoggerAppCheckMessageRecaptchaProviderMissingSiteKey;
FOUNDATION_EXPORT NSString *const
kFIRLoggerAppCheckMessageRecaptchaProviderMissingRecaptchaEnterpriseSDK;
// FIRDefaultProviderFactory.m
FOUNDATION_EXPORT NSString *const kFIRLoggerAppCheckMessageCodeDeviceCheckProviderUnavailable;
void FIRAppCheckDebugLog(NSString *messageCode, NSString *message, ...);
GACAppCheckLogLevel FIRGetGACAppCheckLogLevel(void);