FIRPhoneAuthProvider.h 6.4 KB

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