FIRAuthAppCredentialManager.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2017 Google
  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. #include <TargetConditionals.h>
  17. #if !TARGET_OS_OSX
  18. #import <Foundation/Foundation.h>
  19. #import "FirebaseAuth/Sources/Storage/FIRAuthKeychainServices.h"
  20. #import "FirebaseAuth/Sources/SystemService/FIRAuthAppCredential.h"
  21. NS_ASSUME_NONNULL_BEGIN
  22. /** @typedef FIRAuthAppCredentialCallback
  23. @brief The type of block to receive an app crdential.
  24. @param credential The best available app credential at the time.
  25. */
  26. typedef void (^FIRAuthAppCredentialCallback)(FIRAuthAppCredential *credential);
  27. /** @class FIRAuthAppCredentialManager
  28. @brief A class to manage app credentials backed by iOS Keychain.
  29. */
  30. @interface FIRAuthAppCredentialManager : NSObject
  31. /** @property credential
  32. @brief The full credential (which has a secret) to be used by the app, if one is available.
  33. */
  34. @property(nonatomic, strong, readonly, nullable) FIRAuthAppCredential *credential;
  35. /** @property maximumNumberOfPendingReceipts
  36. @brief The maximum (but not necessarily the minimum) number of pending receipts to be kept.
  37. @remarks Only tests should access this property.
  38. */
  39. @property(nonatomic, assign, readonly) NSUInteger maximumNumberOfPendingReceipts;
  40. /** @fn init
  41. @brief Call @c initWithKeychain: to initialize an instance of this class.
  42. */
  43. - (instancetype)init NS_UNAVAILABLE;
  44. /** @fn initWithKeychain:
  45. @brief Initializes the instance.
  46. @param keychain The iOS Keychain storage to back up the app credential with.
  47. @return The initialized instance.
  48. */
  49. - (instancetype)initWithKeychain:(FIRAuthKeychainServices *)keychain NS_DESIGNATED_INITIALIZER;
  50. /** @fn didStartVerificationWithReceipt:timeout:callback:
  51. @brief Notifies that the app verification process has started.
  52. @param receipt The receipt for verification.
  53. @param timeout The timeout value for how long the callback is waited to be called.
  54. @param callback The block to be called in future either when the verification finishes, or
  55. when timeout occurs, whichever happens earlier.
  56. */
  57. - (void)didStartVerificationWithReceipt:(NSString *)receipt
  58. timeout:(NSTimeInterval)timeout
  59. callback:(FIRAuthAppCredentialCallback)callback;
  60. /** @fn canFinishVerificationWithReceipt:
  61. @brief Attempts to finish verification.
  62. @param receipt The receipt to match the original receipt obtained when verification started.
  63. @param secret The secret to complete the verification.
  64. @return Whether or not the receipt matches a pending verification, and finishes verification
  65. if it does.
  66. */
  67. - (BOOL)canFinishVerificationWithReceipt:(NSString *)receipt secret:(NSString *)secret;
  68. /** @fn clearCredential
  69. @brief Clears the saved credential, to be used in the case that it is rejected by the server.
  70. */
  71. - (void)clearCredential;
  72. @end
  73. NS_ASSUME_NONNULL_END
  74. #endif