FIRAppCheckDebugProvider.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 2020 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import "FIRAppCheckProvider.h"
  18. @class FIRApp;
  19. @protocol FIRAppCheckDebugProviderAPIServiceProtocol;
  20. NS_ASSUME_NONNULL_BEGIN
  21. /// A Firebase App Check provider that can exchange a debug token registered
  22. /// in the Firebase console for a Firebase App Check token. The debug provider
  23. /// is designed to enable testing applications on a simulator or test
  24. /// environment.
  25. ///
  26. /// NOTE: Do not use the debug provider in applications used by real users.
  27. ///
  28. /// WARNING: Keep the Firebase App Check debug token secret. If you
  29. /// accidentally share one (e.g. commit to a public source repo), remove it in
  30. /// the Firebase console ASAP.
  31. ///
  32. /// To use `AppCheckDebugProvider` on a local simulator:
  33. /// 1. Configure `AppCheckDebugProviderFactory` before `FirebaseApp.configure()`:
  34. /// ```AppCheck.setAppCheckProviderFactory(AppCheckDebugProviderFactory())```
  35. /// 2. Enable debug logging by adding the `-FIRDebugEnabled` launch argument to
  36. /// the app target.
  37. /// 3. Launch the app. A local debug token will be logged when Firebase is
  38. /// configured. For example:
  39. /// "[Firebase/AppCheck][I-FAA001001] Firebase App Check Debug Token:
  40. /// '3BA09C8C-8A0D-4030-ACD5-B96D99DB73F9'".
  41. /// 4. Register the debug token in the Firebase console.
  42. ///
  43. /// Once the debug token is registered the debug provider will be able to provide a valid Firebase
  44. /// App Check token.
  45. ///
  46. /// To use `AppCheckDebugProvider` on a simulator on a build server:
  47. /// 1. Create a new Firebase App Check debug token in the Firebase console
  48. /// 2. Add the debug token to the secure storage of your build environment. E.g. see [Encrypted
  49. /// secrets](https://docs.github.com/en/actions/reference/encrypted-secrets) for GitHub Actions,
  50. /// etc.
  51. /// 3. Configure `AppCheckDebugProviderFactory` before `FirebaseApp.configure()`
  52. /// `AppCheck.setAppCheckProviderFactory(AppCheckDebugProviderFactory())`
  53. /// 4. Add an environment variable to the scheme with a name `FIRAAppCheckDebugToken` and value like
  54. /// `$(MY_APP_CHECK_DEBUG_TOKEN)`.
  55. /// 5. Configure the build script to pass the debug token as the environment variable, e.g.:
  56. /// `xcodebuild test -scheme InstallationsExample -workspace InstallationsExample.xcworkspace \
  57. /// MY_APP_CHECK_DEBUG_TOKEN=$(MY_SECRET_ON_CI)`
  58. ///
  59. NS_SWIFT_NAME(AppCheckDebugProvider)
  60. @interface FIRAppCheckDebugProvider : NSObject <FIRAppCheckProvider>
  61. - (instancetype)init NS_UNAVAILABLE;
  62. - (nullable instancetype)initWithApp:(FIRApp *)app;
  63. /** Return the locally generated token. */
  64. - (NSString *)localDebugToken;
  65. /** Returns the currently used App Check debug token. The priority:
  66. * - `FIRAAppCheckDebugToken` env variable value
  67. * - A previously generated token, stored locally on the device
  68. * - A newly generated random token. The generated token will be stored
  69. * locally for future use
  70. * @return The currently used App Check debug token.
  71. */
  72. - (NSString *)currentDebugToken;
  73. @end
  74. NS_ASSUME_NONNULL_END