GIDAppCheck.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright 2023 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 <TargetConditionals.h>
  17. #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  18. #import <Foundation/Foundation.h>
  19. NS_ASSUME_NONNULL_BEGIN
  20. @protocol GACAppCheckProvider;
  21. @class GACAppCheckToken;
  22. extern NSString *const kGIDAppCheckPreparedKey;
  23. NS_CLASS_AVAILABLE_IOS(14)
  24. @interface GIDAppCheck : NSObject
  25. - (instancetype)init NS_UNAVAILABLE;
  26. /// Creates the instance of this App Check wrapper class using `GACAppCheckDebugProvider`.
  27. ///
  28. /// @param APIKey The API Key to use when creating the debug App Check provider.
  29. ///
  30. /// The instance is created using `+[NSUserDefaults standardUserDefaults]`.
  31. + (instancetype)appCheckUsingDebugProviderWithAPIKey:(NSString *)APIKey;
  32. /// Creates the instance of this App Check wrapper class using `GACAppAttestProvider`.
  33. ///
  34. /// The instance is created using `+[NSUserDefaults standardUserDefaults]`.
  35. + (instancetype)appCheckUsingAppAttestProvider;
  36. /// Creates the instance of this App Check wrapper class.
  37. ///
  38. /// @param appCheckProvider The instance performing the Firebase App Check token requests. If `nil`,
  39. /// then a default implementation will be used.
  40. /// @param userDefaults The instance of `NSUserDefaults` that `GIDAppCheck` will use to store its
  41. /// preparation status. If nil, `GIDAppCheck` will use `-[NSUserDefaults standardUserDefaults]`.
  42. - (instancetype)initWithAppCheckProvider:(id<GACAppCheckProvider>)appCheckProvider
  43. userDefaults:(NSUserDefaults *)userDefaults NS_DESIGNATED_INITIALIZER;
  44. /// Prewarms the library for App Check by asking Firebase App Check to generate the App Attest key
  45. /// id and perform the initial attestation process (if needed).
  46. ///
  47. /// @param completion A `nullable` callback with a `nullable` `NSError` if preparation fails.
  48. - (void)prepareForAppCheckWithCompletion:(nullable void (^)(NSError * _Nullable error))completion;
  49. /// Fetches the limited use Firebase token.
  50. ///
  51. /// @param completion A `nullable` callback with the `FIRAppCheckToken`, or an `NSError` otherwise.
  52. - (void)getLimitedUseTokenWithCompletion:
  53. (nullable void (^)(GACAppCheckToken *token, NSError * _Nullable error))completion;
  54. /// Whether or not the App Attest key ID created and the attestation object has been fetched.
  55. - (BOOL)isPrepared;
  56. @end
  57. NS_ASSUME_NONNULL_END
  58. #endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST