FIRPhoneAuthProvider.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 FIRAuth;
  18. @class FIRMultiFactorSession;
  19. @class FIRPhoneAuthCredential;
  20. @class FIRPhoneMultiFactorInfo;
  21. @protocol FIRAuthUIDelegate;
  22. NS_ASSUME_NONNULL_BEGIN
  23. /** @var FIRPhoneAuthProviderID
  24. @brief A string constant identifying the phone identity provider.
  25. This constant is available on iOS only.
  26. */
  27. extern NSString *const FIRPhoneAuthProviderID NS_SWIFT_NAME(PhoneAuthProviderID)
  28. API_UNAVAILABLE(macos, tvos, watchos);
  29. /** @var FIRPhoneAuthProviderID
  30. @brief A string constant identifying the phone sign-in method.
  31. This constant is available on iOS only.
  32. */
  33. extern NSString *const _Nonnull FIRPhoneAuthSignInMethod NS_SWIFT_NAME(PhoneAuthSignInMethod)
  34. API_UNAVAILABLE(macos, tvos, watchos);
  35. /** @typedef FIRVerificationResultCallback
  36. @brief The type of block invoked when a request to send a verification code has finished.
  37. This type is available on iOS only.
  38. @param verificationID On success, the verification ID provided, nil otherwise.
  39. @param error On error, the error that occurred, nil otherwise.
  40. */
  41. typedef void (^FIRVerificationResultCallback)(NSString *_Nullable verificationID,
  42. NSError *_Nullable error)
  43. NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.")
  44. API_UNAVAILABLE(macos, tvos, watchos);
  45. /** @class FIRPhoneAuthProvider
  46. @brief A concrete implementation of `AuthProvider` for phone auth providers.
  47. This class is available on iOS only.
  48. */
  49. NS_SWIFT_NAME(PhoneAuthProvider) API_UNAVAILABLE(macos, tvos, watchos)
  50. @interface FIRPhoneAuthProvider : NSObject
  51. /** @fn provider
  52. @brief Returns an instance of `PhoneAuthProvider` for the default `Auth` object.
  53. */
  54. + (instancetype)provider NS_SWIFT_NAME(provider());
  55. /** @fn providerWithAuth:
  56. @brief Returns an instance of `PhoneAuthProvider` for the provided `Auth` object.
  57. @param auth The auth object to associate with the phone auth provider instance.
  58. */
  59. + (instancetype)providerWithAuth:(FIRAuth *)auth NS_SWIFT_NAME(provider(auth:));
  60. /** @fn verifyPhoneNumber:UIDelegate:completion:
  61. @brief Starts the phone number authentication flow by sending a verification code to the
  62. specified phone number.
  63. @param phoneNumber The phone number to be verified.
  64. @param UIDelegate An object used to present the SFSafariViewController. The object is retained
  65. by this method until the completion block is executed.
  66. @param completion The callback to be invoked when the verification flow is finished.
  67. @remarks Possible error codes:
  68. + `AuthErrorCodeCaptchaCheckFailed` - Indicates that the reCAPTCHA token obtained by
  69. the Firebase Auth is invalid or has expired.
  70. + `AuthErrorCodeQuotaExceeded` - Indicates that the phone verification quota for this
  71. project has been exceeded.
  72. + `AuthErrorCodeInvalidPhoneNumber` - Indicates that the phone number provided is
  73. invalid.
  74. + `AuthErrorCodeMissingPhoneNumber` - Indicates that a phone number was not provided.
  75. */
  76. - (void)verifyPhoneNumber:(NSString *)phoneNumber
  77. UIDelegate:(nullable id<FIRAuthUIDelegate>)UIDelegate
  78. completion:(nullable void (^)(NSString *_Nullable verificationID,
  79. NSError *_Nullable error))completion;
  80. /** @fn verifyPhoneNumber:UIDelegate:multiFactorSession:completion:
  81. @brief Verify ownership of the second factor phone number by the current user.
  82. @param phoneNumber The phone number to be verified.
  83. @param UIDelegate An object used to present the SFSafariViewController. The object is retained
  84. by this method until the completion block is executed.
  85. @param session A session to identify the MFA flow. For enrollment, this identifies the user
  86. trying to enroll. For sign-in, this identifies that the user already passed the first
  87. factor challenge.
  88. @param completion The callback to be invoked when the verification flow is finished.
  89. */
  90. - (void)verifyPhoneNumber:(NSString *)phoneNumber
  91. UIDelegate:(nullable id<FIRAuthUIDelegate>)UIDelegate
  92. multiFactorSession:(nullable FIRMultiFactorSession *)session
  93. completion:(nullable void (^)(NSString *_Nullable verificationID,
  94. NSError *_Nullable error))completion;
  95. /** @fn verifyPhoneNumberWithMultiFactorInfo:UIDelegate:multiFactorSession:completion:
  96. @brief Verify ownership of the second factor phone number by the current user.
  97. @param phoneMultiFactorInfo The phone multi factor whose number need to be verified.
  98. @param UIDelegate An object used to present the SFSafariViewController. The object is retained
  99. by this method until the completion block is executed.
  100. @param session A session to identify the MFA flow. For enrollment, this identifies the user
  101. trying to enroll. For sign-in, this identifies that the user already passed the first
  102. factor challenge.
  103. @param completion The callback to be invoked when the verification flow is finished.
  104. */
  105. - (void)verifyPhoneNumberWithMultiFactorInfo:(FIRPhoneMultiFactorInfo *)phoneMultiFactorInfo
  106. UIDelegate:(nullable id<FIRAuthUIDelegate>)UIDelegate
  107. multiFactorSession:(nullable FIRMultiFactorSession *)session
  108. completion:
  109. (nullable void (^)(NSString *_Nullable verificationID,
  110. NSError *_Nullable error))completion;
  111. /** @fn credentialWithVerificationID:verificationCode:
  112. @brief Creates an `AuthCredential` for the phone number provider identified by the
  113. verification ID and verification code.
  114. @param verificationID The verification ID obtained from invoking
  115. verifyPhoneNumber:completion:
  116. @param verificationCode The verification code obtained from the user.
  117. @return The corresponding phone auth credential for the verification ID and verification code
  118. provided.
  119. */
  120. - (FIRPhoneAuthCredential *)credentialWithVerificationID:(NSString *)verificationID
  121. verificationCode:(NSString *)verificationCode;
  122. /** @fn init
  123. @brief Please use the `provider()` or `provider(auth:)` methods to obtain an instance of
  124. `PhoneAuthProvider`.
  125. */
  126. - (instancetype)init NS_UNAVAILABLE;
  127. @end
  128. NS_ASSUME_NONNULL_END