FIRAppCheckDebugProvider.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. NS_ASSUME_NONNULL_BEGIN
  20. /// A Firebase App Check provider that can exchange a debug token registered
  21. /// in the Firebase console for a Firebase App Check token. The debug provider
  22. /// is designed to enable testing applications on a simulator or test
  23. /// environment.
  24. ///
  25. /// NOTE: Do not use the debug provider in applications used by real users.
  26. ///
  27. /// WARNING: Keep the Firebase App Check debug token secret. If you
  28. /// accidentally share one (e.g. commit to a public source repo), remove it in
  29. /// the Firebase console ASAP.
  30. ///
  31. /// To use `AppCheckDebugProvider` on a local simulator:
  32. /// 1. Configure `AppCheckDebugProviderFactory` before `FirebaseApp.configure()`:
  33. /// ```AppCheck.setAppCheckProviderFactory(AppCheckDebugProviderFactory())```
  34. /// 2. Enable debug logging by adding the `-FIRDebugEnabled` launch argument to
  35. /// the app target.
  36. /// 3. Launch the app. A local debug token will be logged when Firebase is
  37. /// configured. For example:
  38. /// "[Firebase/AppCheck][I-FAA001001] Firebase App Check Debug Token:
  39. /// '3BA09C8C-8A0D-4030-ACD5-B96D99DB73F9'".
  40. /// 4. Register the debug token in the Firebase console.
  41. ///
  42. /// Once the debug token is registered the debug provider will be able to provide a valid Firebase
  43. /// App Check token.
  44. ///
  45. /// To use `AppCheckDebugProvider` on a simulator on a build server:
  46. /// 1. Create a new Firebase App Check debug token in the Firebase console
  47. /// 2. Add the debug token to the secure storage of your build environment. E.g. see [Encrypted
  48. /// secrets](https://docs.github.com/en/actions/reference/encrypted-secrets) for GitHub Actions,
  49. /// etc.
  50. /// 3. Configure `AppCheckDebugProviderFactory` before `FirebaseApp.configure()`
  51. /// `AppCheck.setAppCheckProviderFactory(AppCheckDebugProviderFactory())`
  52. /// 4. Add an environment variable to the scheme with a name `FIRAAppCheckDebugToken` and value like
  53. /// `$(MY_APP_CHECK_DEBUG_TOKEN)`.
  54. /// 5. Configure the build script to pass the debug token as the environment variable, e.g.:
  55. /// `xcodebuild test -scheme InstallationsExample -workspace InstallationsExample.xcworkspace \
  56. /// MY_APP_CHECK_DEBUG_TOKEN=$(MY_SECRET_ON_CI)`
  57. ///
  58. NS_SWIFT_NAME(AppCheckDebugProvider)
  59. @interface FIRAppCheckDebugProvider : NSObject <FIRAppCheckProvider>
  60. - (instancetype)init NS_UNAVAILABLE;
  61. - (nullable instancetype)initWithApp:(FIRApp *)app;
  62. /** Return the locally generated token. */
  63. - (NSString *)localDebugToken;
  64. /** Returns the currently used App Check debug token. The priority:
  65. * - `FIRAAppCheckDebugToken` env variable value
  66. * - A previously generated token, stored locally on the device
  67. * - A newly generated random token. The generated token will be stored
  68. * locally for future use
  69. * @return The currently used App Check debug token.
  70. */
  71. - (NSString *)currentDebugToken;
  72. /* Jazzy doesn't generate documentation for protocol-inherited
  73. * methods, so this is copied over from the protocol declaration.
  74. */
  75. /// Returns a new Firebase App Check token.
  76. /// @param handler The completion handler. Make sure to call the handler with either a token
  77. /// or an error.
  78. - (void)getTokenWithCompletion:
  79. (void (^)(FIRAppCheckToken *_Nullable token, NSError *_Nullable error))handler
  80. NS_SWIFT_NAME(getToken(completion:));
  81. /// Returns a new Firebase App Check token.
  82. /// When implementing this method for your custom provider, the token returned should be suitable
  83. /// for consumption in a limited-use scenario. If you do not implement this method, the
  84. /// getTokenWithCompletion will be invoked instead whenever a limited-use token is requested.
  85. /// @param handler The completion handler. Make sure to call the handler with either a token
  86. /// or an error.
  87. - (void)getLimitedUseTokenWithCompletion:
  88. (void (^)(FIRAppCheckToken *_Nullable token, NSError *_Nullable error))handler
  89. NS_SWIFT_NAME(getLimitedUseToken(completion:));
  90. @end
  91. NS_ASSUME_NONNULL_END