You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.2 KiB

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