diff options
author | Zsika Phillip <protocol86@users.noreply.github.com> | 2017-09-27 00:16:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-27 00:16:33 -0700 |
commit | aebb293f3dcfaef012e847689d8b814477c0c301 (patch) | |
tree | d097bb35727b77c96901357af5c0bf7df3ec9570 /Firebase/Auth/Source/FIRUser.m | |
parent | 804ff523a20072fb958e9137c76b9c0e14dda870 (diff) |
Add operation phone auth (#309)
* Adds operation to verify PhoneNumber requests
* Improvements and unit tests
* Fixes typo
* Addresses comments
- Removes the FIRAuthOperation class.
- Defines the FIRAuthOperationType as an enum in a class of the same name.
- Passes the FIRAuthOperationType value down to the verifyPhoneNumber RPC where it is translated to a string.
* Fixes unit tests
* Actually fixes the unit tests.
Diffstat (limited to 'Firebase/Auth/Source/FIRUser.m')
-rw-r--r-- | Firebase/Auth/Source/FIRUser.m | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/Firebase/Auth/Source/FIRUser.m b/Firebase/Auth/Source/FIRUser.m index 049bb30..ef42a29 100644 --- a/Firebase/Auth/Source/FIRUser.m +++ b/Firebase/Auth/Source/FIRUser.m @@ -27,6 +27,7 @@ #import "FIRAuthErrorUtils.h" #import "FIRAuthGlobalWorkQueue.h" #import "FIRAuthSerialTaskQueue.h" +#import "FIRAuthOperationType.h" #import "FIRAuth_Internal.h" #import "FIRSecureTokenService.h" #import "FIRUserInfoImpl.h" @@ -615,27 +616,32 @@ static void callInMainThreadWithAuthDataResultAndError( } #if TARGET_OS_IOS -/** @fn internalUpdatePhoneNumberCredential:completion: +/** @fn internalUpdateOrLinkPhoneNumberCredential:completion: @brief Updates the phone number for the user. On success, the cached user profile data is updated. @param phoneAuthCredential The new phone number credential corresponding to the phone number to be added to the firebaes account, if a phone number is already linked to the account this new phone number will replace it. + @param isLinkOperation Boolean value indicating whether or not this is a link operation. @param completion Optionally; the block invoked when the user profile change has finished. Invoked asynchronously on the global work queue in the future. */ -- (void)internalUpdatePhoneNumberCredential:(FIRPhoneAuthCredential *)phoneAuthCredential - completion:(FIRUserProfileChangeCallback)completion { +- (void)internalUpdateOrLinkPhoneNumberCredential:(FIRPhoneAuthCredential *)phoneAuthCredential + isLinkOperation:(BOOL)isLinkOperation + completion:(FIRUserProfileChangeCallback)completion { [self internalGetTokenWithCallback:^(NSString *_Nullable accessToken, NSError *_Nullable error) { if (error) { completion(error); return; } + FIRAuthOperationType operation = + isLinkOperation ? FIRAuthOperationTypeLink : FIRAuthOperationTypeUpdate; FIRVerifyPhoneNumberRequest *request = [[FIRVerifyPhoneNumberRequest alloc] initWithVerificationID:phoneAuthCredential.verificationID verificationCode:phoneAuthCredential.verificationCode + operation:operation requestConfiguration:_auth.requestConfiguration]; request.accessToken = accessToken; [FIRAuthBackend verifyPhoneNumber:request @@ -661,8 +667,9 @@ static void callInMainThreadWithAuthDataResultAndError( - (void)updatePhoneNumberCredential:(FIRPhoneAuthCredential *)phoneAuthCredential completion:(nullable FIRUserProfileChangeCallback)completion { dispatch_async(FIRAuthGlobalWorkQueue(), ^{ - [self internalUpdatePhoneNumberCredential:phoneAuthCredential - completion:^(NSError *_Nullable error) { + [self internalUpdateOrLinkPhoneNumberCredential:phoneAuthCredential + isLinkOperation:NO + completion:^(NSError *_Nullable error) { callInMainThreadWithError(completion, error); }]; }); @@ -856,8 +863,9 @@ static void callInMainThreadWithAuthDataResultAndError( #if TARGET_OS_IOS if ([credential isKindOfClass:[FIRPhoneAuthCredential class]]) { FIRPhoneAuthCredential *phoneAuthCredential = (FIRPhoneAuthCredential *)credential; - [self internalUpdatePhoneNumberCredential:phoneAuthCredential - completion:^(NSError *_Nullable error) { + [self internalUpdateOrLinkPhoneNumberCredential:phoneAuthCredential + isLinkOperation:YES + completion:^(NSError *_Nullable error) { if (error){ callInMainThreadWithAuthDataResultAndError(completion, nil, error); } else { |