|
@@ -82,195 +82,12 @@ static NSString *const kInvalidEmailSignInLinkExceptionMessage =
|
|
|
@"The link provided is not valid for email/link sign-in. Please check the link by calling "
|
|
@"The link provided is not valid for email/link sign-in. Please check the link by calling "
|
|
|
"isSignInWithEmailLink:link: on Auth before attempting to use it for email/link sign-in.";
|
|
"isSignInWithEmailLink:link: on Auth before attempting to use it for email/link sign-in.";
|
|
|
|
|
|
|
|
-/** @var kPasswordResetRequestType
|
|
|
|
|
- @brief The action code type value for resetting password in the check action code response.
|
|
|
|
|
- */
|
|
|
|
|
-static NSString *const kPasswordResetRequestType = @"PASSWORD_RESET";
|
|
|
|
|
-
|
|
|
|
|
-/** @var kVerifyEmailRequestType
|
|
|
|
|
- @brief The action code type value for verifying email in the check action code response.
|
|
|
|
|
- */
|
|
|
|
|
-static NSString *const kVerifyEmailRequestType = @"VERIFY_EMAIL";
|
|
|
|
|
-
|
|
|
|
|
-/** @var kRecoverEmailRequestType
|
|
|
|
|
- @brief The action code type value for recovering email in the check action code response.
|
|
|
|
|
- */
|
|
|
|
|
-static NSString *const kRecoverEmailRequestType = @"RECOVER_EMAIL";
|
|
|
|
|
-
|
|
|
|
|
-/** @var kEmailLinkSignInRequestType
|
|
|
|
|
- @brief The action code type value for an email sign-in link in the check action code response.
|
|
|
|
|
-*/
|
|
|
|
|
-static NSString *const kEmailLinkSignInRequestType = @"EMAIL_SIGNIN";
|
|
|
|
|
-
|
|
|
|
|
-/** @var kVerifyAndChangeEmailRequestType
|
|
|
|
|
- @brief The action code type value for verifying and changing email in the check action code
|
|
|
|
|
- response.
|
|
|
|
|
- */
|
|
|
|
|
-static NSString *const kVerifyAndChangeEmailRequestType = @"VERIFY_AND_CHANGE_EMAIL";
|
|
|
|
|
-
|
|
|
|
|
-/** @var kRevertSecondFactorAdditionRequestType
|
|
|
|
|
- @brief The action code type value for reverting second factor addition in the check action code
|
|
|
|
|
- response.
|
|
|
|
|
- */
|
|
|
|
|
-static NSString *const kRevertSecondFactorAdditionRequestType = @"REVERT_SECOND_FACTOR_ADDITION";
|
|
|
|
|
-
|
|
|
|
|
/** @var kMissingPasswordReason
|
|
/** @var kMissingPasswordReason
|
|
|
@brief The reason why the @c FIRAuthErrorCodeWeakPassword error is thrown.
|
|
@brief The reason why the @c FIRAuthErrorCodeWeakPassword error is thrown.
|
|
|
@remarks This error message will be localized in the future.
|
|
@remarks This error message will be localized in the future.
|
|
|
*/
|
|
*/
|
|
|
static NSString *const kMissingPasswordReason = @"Missing Password";
|
|
static NSString *const kMissingPasswordReason = @"Missing Password";
|
|
|
|
|
|
|
|
-#pragma mark - FIRActionCodeInfo
|
|
|
|
|
-
|
|
|
|
|
-@interface FIRActionCodeInfo ()
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- @brief The operation being performed.
|
|
|
|
|
- */
|
|
|
|
|
-@property(nonatomic, readwrite) FIRActionCodeOperation operation;
|
|
|
|
|
-
|
|
|
|
|
-/** @property email
|
|
|
|
|
- @brief The email address to which the code was sent. The new email address in the case of
|
|
|
|
|
- FIRActionCodeOperationRecoverEmail.
|
|
|
|
|
- */
|
|
|
|
|
-@property(nonatomic, nullable, readwrite, copy) NSString *email;
|
|
|
|
|
-
|
|
|
|
|
-/** @property previousEmail
|
|
|
|
|
- @brief The current email address in the case of FIRActionCodeOperationRecoverEmail.
|
|
|
|
|
- */
|
|
|
|
|
-@property(nonatomic, nullable, readwrite, copy) NSString *previousEmail;
|
|
|
|
|
-
|
|
|
|
|
-#if TARGET_OS_IOS
|
|
|
|
|
-/** @property multiFactorInfo
|
|
|
|
|
- @brief The MultiFactorInfo object of the second factor to be reverted in case of
|
|
|
|
|
- FIRActionCodeMultiFactorInfoKey.
|
|
|
|
|
- */
|
|
|
|
|
-@property(nonatomic, nullable, readwrite) FIRMultiFactorInfo *multiFactorInfo;
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
-@end
|
|
|
|
|
-
|
|
|
|
|
-@implementation FIRActionCodeInfo
|
|
|
|
|
-
|
|
|
|
|
-- (instancetype)initWithOperation:(FIRActionCodeOperation)operation
|
|
|
|
|
- email:(NSString *)email
|
|
|
|
|
- newEmail:(nullable NSString *)newEmail {
|
|
|
|
|
- self = [super init];
|
|
|
|
|
- if (self) {
|
|
|
|
|
- _operation = operation;
|
|
|
|
|
- if (newEmail) {
|
|
|
|
|
- _email = [newEmail copy];
|
|
|
|
|
- _previousEmail = [email copy];
|
|
|
|
|
- } else {
|
|
|
|
|
- _email = [email copy];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return self;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/** @fn actionCodeOperationForRequestType:
|
|
|
|
|
- @brief Returns the corresponding operation type per provided request type string.
|
|
|
|
|
- @param requestType Request type returned in in the server response.
|
|
|
|
|
- @return The corresponding FIRActionCodeOperation for the supplied request type.
|
|
|
|
|
- */
|
|
|
|
|
-+ (FIRActionCodeOperation)actionCodeOperationForRequestType:(NSString *)requestType {
|
|
|
|
|
- if ([requestType isEqualToString:kPasswordResetRequestType]) {
|
|
|
|
|
- return FIRActionCodeOperationPasswordReset;
|
|
|
|
|
- }
|
|
|
|
|
- if ([requestType isEqualToString:kVerifyEmailRequestType]) {
|
|
|
|
|
- return FIRActionCodeOperationVerifyEmail;
|
|
|
|
|
- }
|
|
|
|
|
- if ([requestType isEqualToString:kRecoverEmailRequestType]) {
|
|
|
|
|
- return FIRActionCodeOperationRecoverEmail;
|
|
|
|
|
- }
|
|
|
|
|
- if ([requestType isEqualToString:kEmailLinkSignInRequestType]) {
|
|
|
|
|
- return FIRActionCodeOperationEmailLink;
|
|
|
|
|
- }
|
|
|
|
|
- if ([requestType isEqualToString:kVerifyAndChangeEmailRequestType]) {
|
|
|
|
|
- return FIRActionCodeOperationVerifyAndChangeEmail;
|
|
|
|
|
- }
|
|
|
|
|
- if ([requestType isEqualToString:kRevertSecondFactorAdditionRequestType]) {
|
|
|
|
|
- return FIRActionCodeOperationRevertSecondFactorAddition;
|
|
|
|
|
- }
|
|
|
|
|
- return FIRActionCodeOperationUnknown;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-@end
|
|
|
|
|
-
|
|
|
|
|
-#pragma mark - FIRActionCodeURL
|
|
|
|
|
-
|
|
|
|
|
-@implementation FIRActionCodeURL
|
|
|
|
|
-
|
|
|
|
|
-/** @fn FIRAuthParseURL:NSString
|
|
|
|
|
- @brief Parses an incoming URL into all available query items.
|
|
|
|
|
- @param urlString The url to be parsed.
|
|
|
|
|
- @return A dictionary of available query items in the target URL.
|
|
|
|
|
- */
|
|
|
|
|
-+ (NSDictionary<NSString *, NSString *> *)parseURL:(NSString *)urlString {
|
|
|
|
|
- NSString *linkURL = [NSURLComponents componentsWithString:urlString].query;
|
|
|
|
|
- if (!linkURL) {
|
|
|
|
|
- return @{};
|
|
|
|
|
- }
|
|
|
|
|
- NSArray<NSString *> *URLComponents = [linkURL componentsSeparatedByString:@"&"];
|
|
|
|
|
- NSMutableDictionary<NSString *, NSString *> *queryItems =
|
|
|
|
|
- [[NSMutableDictionary alloc] initWithCapacity:URLComponents.count];
|
|
|
|
|
- for (NSString *component in URLComponents) {
|
|
|
|
|
- NSRange equalRange = [component rangeOfString:@"="];
|
|
|
|
|
- if (equalRange.location != NSNotFound) {
|
|
|
|
|
- NSString *queryItemKey =
|
|
|
|
|
- [[component substringToIndex:equalRange.location] stringByRemovingPercentEncoding];
|
|
|
|
|
- NSString *queryItemValue =
|
|
|
|
|
- [[component substringFromIndex:equalRange.location + 1] stringByRemovingPercentEncoding];
|
|
|
|
|
- if (queryItemKey && queryItemValue) {
|
|
|
|
|
- queryItems[queryItemKey] = queryItemValue;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return queryItems;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-+ (nullable instancetype)actionCodeURLWithLink:(NSString *)link {
|
|
|
|
|
- NSDictionary<NSString *, NSString *> *queryItems = [FIRActionCodeURL parseURL:link];
|
|
|
|
|
- if (!queryItems.count) {
|
|
|
|
|
- NSURLComponents *urlComponents = [NSURLComponents componentsWithString:link];
|
|
|
|
|
- queryItems = [FIRActionCodeURL parseURL:urlComponents.query];
|
|
|
|
|
- }
|
|
|
|
|
- if (!queryItems.count) {
|
|
|
|
|
- return nil;
|
|
|
|
|
- }
|
|
|
|
|
- NSString *APIKey = queryItems[@"apiKey"];
|
|
|
|
|
- NSString *actionCode = queryItems[@"oobCode"];
|
|
|
|
|
- NSString *continueURLString = queryItems[@"continueUrl"];
|
|
|
|
|
- NSString *languageCode = queryItems[@"languageCode"];
|
|
|
|
|
- NSString *mode = queryItems[@"mode"];
|
|
|
|
|
- NSString *tenantID = queryItems[@"tenantID"];
|
|
|
|
|
- return [[FIRActionCodeURL alloc] initWithAPIKey:APIKey
|
|
|
|
|
- actionCode:actionCode
|
|
|
|
|
- continueURLString:continueURLString
|
|
|
|
|
- languageCode:languageCode
|
|
|
|
|
- mode:mode
|
|
|
|
|
- tenantID:tenantID];
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-- (nullable instancetype)initWithAPIKey:(NSString *)APIKey
|
|
|
|
|
- actionCode:(NSString *)actionCode
|
|
|
|
|
- continueURLString:(NSString *)continueURLString
|
|
|
|
|
- languageCode:(NSString *)languageCode
|
|
|
|
|
- mode:(NSString *)mode
|
|
|
|
|
- tenantID:(NSString *)tenantID {
|
|
|
|
|
- self = [super init];
|
|
|
|
|
- if (self) {
|
|
|
|
|
- _APIKey = APIKey;
|
|
|
|
|
- _operation = [FIRActionCodeInfo actionCodeOperationForRequestType:mode];
|
|
|
|
|
- _code = actionCode;
|
|
|
|
|
- _continueURL = [NSURL URLWithString:continueURLString];
|
|
|
|
|
- _languageCode = languageCode;
|
|
|
|
|
- }
|
|
|
|
|
- return self;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-@end
|
|
|
|
|
-
|
|
|
|
|
#pragma mark - FIRAuth
|
|
#pragma mark - FIRAuth
|
|
|
|
|
|
|
|
#if TARGET_OS_IOS
|
|
#if TARGET_OS_IOS
|