React Native 与 firebase AppCheck 在 ios 上的发布版本中使用 ExchangeDebugToken url

问题描述 投票:0回答:1

技术堆栈

react native
@react-native-firebase

运行发布构建

在 xcode 上,我使用

Build Configuration
Release
在物理设备上运行应用程序。

应用程序启动时控制台中显示错误

[javascript] [Error: [appCheck/token-error] The operation couldn’t be completed. The server responded with an error: 
 - URL: https://firebaseappcheck.googleapis.com/v1/projects/##########/apps/##########:exchangeDebugToken 
 - HTTP status code: 403 
 - Response body: {
  "error": {
    "code": 403,
    "message": "App attestation failed.",
    "status": "PERMISSION_DENIED"
  }
}
]

看上面的url中有

exchangeDebugToken

Javascript初始化

async function initAppCheck() {
  const appcheck = firebase.appCheck();
  const rnfbProvider = appcheck
    .newReactNativeFirebaseAppCheckProvider();
  await rnfbProvider.configure({
    android: {
      provider: __DEV__ ? 'debug' : 'playIntegrity',
      debugToken: 'fba7bbac-8440-4965-b5f2-8c020bd042c3',
    },
    apple: {
      provider: 'appAttestWithDeviceCheckFallback',
    },
    web: {
      provider: 'reCaptchaV3',
      siteKey: 'unknown',
    },
  });

  await appcheck.initializeAppCheck({
    provider: rnfbProvider,
    isTokenAutoRefreshEnabled: true,
  });
  const token = await appcheck.getToken(true);
}
登录时,

__DEV__
false

Pod 文件:

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, min_ios_version_supported
prepare_react_native_project!
flipper_config = FlipperConfiguration.disabled 
# flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled
linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'BusinessClientApp' do
  config = use_native_modules!
  use_frameworks! :linkage => :static
  
  # pod 'Firebase', :modular_headers => true
  # pod 'FirebaseCore', :modular_headers => true
  # pod 'GoogleUtilities', :modular_headers => true
  # pod 'FirebaseCoreExtension', :modular_headers => true
  # pod 'FirebaseAppCheckInterop', :modular_headers => true
  # pod 'FirebaseAuthInterop', :modular_headers => true
  # pod 'FirebaseMessagingInterop', :modular_headers => true
  # pod 'GTMSessionFetcher', :modular_headers => true
  # pod 'FirebaseStorageInternal', :modular_headers => true
  # pod 'FirebaseCoreExtension', :modular_headers => true
  
  # Flags change depending on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    # Hermes is now enabled by default. Disable by setting this flag to false.
    # Upcoming versions of React Native may rely on get_default_flags(), but
    # we make it explicit here to aid in the React Native upgrade process.
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    :flipper_configuration => flipper_config,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'BusinessClientAppTests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    react_native_post_install(
      installer,
      # Set `mac_catalyst_enabled` to `true` in order to apply patches
      # necessary for Mac Catalyst builds
      :mac_catalyst_enabled => false
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

应用程序委托.mm

#import "AppDelegate.h"
#import "RNFBAppCheckModule.h" // https://rnfirebase.io/app-check/usage
#import <Firebase.h>

#import <React/RCTBundleURLProvider.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // Firebase config
  [RNFBAppCheckModule sharedInstance]; // ⬅️ ADD THIS LINE BEFORE [FIRApp configure] https://rnfirebase.io/app-check/usage

  [FIRApp configure];
  
   self.moduleName = @"BusinessClientApp";
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}


/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
///
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
/// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`.
- (BOOL)concurrentRootEnabled
{
  return true;
}

@end

在模拟器上运行此命令也会出现相同的错误,但它会打开一个验证码页面,从而可以成功登录。但在物理设备上,验证码不会打开,并且会引发身份验证/错误。

ios firebase react-native react-native-firebase firebase-app-check
1个回答
-1
投票

这个运气好吗?我有同样的问题..不知道哪里出了问题..

© www.soinside.com 2019 - 2024. All rights reserved.