FIRAppCheck.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. @class FIRApp;
  18. @class FIRAppCheckToken;
  19. @protocol FIRAppCheckProviderFactory;
  20. NS_ASSUME_NONNULL_BEGIN
  21. /// A notification with the specified name is sent to the default notification center
  22. /// (`NotificationCenter.default`) each time a Firebase app check token is refreshed.
  23. /// The user info dictionary contains `kFIRAppCheckTokenNotificationKey` and
  24. /// `kFIRAppCheckAppNameNotificationKey` keys.
  25. FOUNDATION_EXPORT const NSNotificationName
  26. FIRAppCheckAppCheckTokenDidChangeNotification NS_SWIFT_NAME(AppCheckTokenDidChange);
  27. /// `userInfo` key for the `FirebaseApp.name` in `AppCheckTokenDidChangeNotification`.
  28. FOUNDATION_EXPORT NSString *const kFIRAppCheckTokenNotificationKey NS_SWIFT_NAME(AppCheckTokenNotificationKey);
  29. /// `userInfo` key for the `AppCheckToken` in `AppCheckTokenDidChangeNotification`.
  30. FOUNDATION_EXPORT NSString *const kFIRAppCheckAppNameNotificationKey NS_SWIFT_NAME(AppCheckAppNameNotificationKey);
  31. /// A class used to manage app check tokens for a given Firebase app.
  32. NS_SWIFT_NAME(AppCheck)
  33. @interface FIRAppCheck : NSObject
  34. - (instancetype)init NS_UNAVAILABLE;
  35. /// Returns a default instance of `AppCheck`.
  36. /// @return An instance of `AppCheck` for `FirebaseApp.defaultApp()`.
  37. /// @throw Throws an exception if the default app is not configured yet or required `FirebaseApp`
  38. /// options are missing.
  39. + (instancetype)appCheck NS_SWIFT_NAME(appCheck());
  40. /// Returns an instance of `AppCheck` for an application.
  41. /// @param firebaseApp A configured `FirebaseApp` instance if exists.
  42. /// @return An instance of `AppCheck` corresponding to the passed application.
  43. /// @throw Throws an exception if required `FirebaseApp` options are missing.
  44. + (nullable instancetype)appCheckWithApp:(FIRApp *)firebaseApp NS_SWIFT_NAME(appCheck(app:));
  45. /// Requests Firebase app check token. This method should *only* be used if you need to authorize
  46. /// requests to a non-Firebase backend. Requests to Firebase backend are authorized automatically if
  47. /// configured.
  48. ///
  49. /// If your non-Firebase backend exposes sensitive or expensive endpoints that have low traffic
  50. /// volume, consider protecting it with [Replay
  51. /// Protection](https://firebase.google.com/docs/app-check/custom-resource-backend#replay-protection).
  52. /// In this case, use the ``limitedUseToken(completion:)`` instead to obtain a limited-use token.
  53. /// @param forcingRefresh If `YES`, a new Firebase app check token is requested and the token
  54. /// cache is ignored. If `NO`, the cached token is used if it exists and has not expired yet. In
  55. /// most cases, `NO` should be used. `YES` should only be used if the server explicitly returns an
  56. /// error, indicating a revoked token.
  57. /// @param handler The completion handler. Includes the app check token if the request succeeds,
  58. /// or an error if the request fails.
  59. - (void)tokenForcingRefresh:(BOOL)forcingRefresh
  60. completion:
  61. (void (^)(FIRAppCheckToken *_Nullable token, NSError *_Nullable error))handler
  62. NS_SWIFT_NAME(token(forcingRefresh:completion:));
  63. /// Requests a limited-use Firebase App Check token. This method should be used only if you need to
  64. /// authorize requests to a non-Firebase backend.
  65. ///
  66. /// Returns limited-use tokens that are intended for use with your non-Firebase backend endpoints
  67. /// that are protected with [Replay
  68. /// Protection](https://firebase.google.com/docs/app-check/custom-resource-backend#replay-protection).
  69. /// This method does not affect the token generation behavior of the
  70. /// ``tokenForcingRefresh()`` method.
  71. - (void)limitedUseTokenWithCompletion:(void (^)(FIRAppCheckToken *_Nullable token,
  72. NSError *_Nullable error))handler;
  73. /// Sets the `AppCheckProviderFactory` to use to generate
  74. /// `AppCheckDebugProvider` objects.
  75. ///
  76. /// An instance of `DeviceCheckProviderFactory` is used by default, but you can
  77. /// also use a custom `AppCheckProviderFactory` implementation or an
  78. /// instance of `AppCheckDebugProviderFactory` to test your app on a simulator
  79. /// on a local machine or a build server.
  80. ///
  81. /// NOTE: Make sure to call this method before `FirebaseApp.configure()`. If
  82. /// this method is called after configuring Firebase, the changes will not take
  83. /// effect.
  84. + (void)setAppCheckProviderFactory:(nullable id<FIRAppCheckProviderFactory>)factory;
  85. /// If this flag is disabled then Firebase app check will not periodically auto-refresh the app
  86. /// check token. The default value of the flag is equal to
  87. /// `FirebaseApp.dataCollectionDefaultEnabled`. To disable the flag by default set
  88. /// `FirebaseAppCheckTokenAutoRefreshEnabled` flag in the app Info.plist to `NO`. Once the flag is
  89. /// set explicitly, the value will be persisted and used as a default value on next app launches.
  90. @property(nonatomic, assign) BOOL isTokenAutoRefreshEnabled;
  91. @end
  92. NS_ASSUME_NONNULL_END