FIRPhoneAuthProvider.h 4.3 KB

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