Files
firebase-ios-sdk/FirebaseAuth/Sources/MultiFactor/FIRMultiFactorResolver.m
T

101 lines
4.7 KiB
Objective-C
Raw Normal View History

2020-03-10 13:30:20 -07:00
/*
* Copyright 2019 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2020-07-09 13:31:53 -07:00
#import <TargetConditionals.h>
2020-03-10 13:30:20 -07:00
#if TARGET_OS_IOS
2020-07-27 15:21:19 -07:00
#import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRAdditionalUserInfo.h"
#import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRMultiFactorResolver.h"
2020-03-10 13:30:20 -07:00
2020-04-10 11:54:51 -07:00
#import "FirebaseAuth/Sources/Auth/FIRAuthDataResult_Internal.h"
#import "FirebaseAuth/Sources/Auth/FIRAuth_Internal.h"
#import "FirebaseAuth/Sources/Backend/FIRAuthBackend+MultiFactor.h"
#import "FirebaseAuth/Sources/Backend/RPC/MultiFactor/SignIn/FIRFinalizeMFASignInRequest.h"
#import "FirebaseAuth/Sources/Backend/RPC/Proto/Phone/FIRAuthProtoFinalizeMFAPhoneRequestInfo.h"
#import "FirebaseAuth/Sources/MultiFactor/FIRMultiFactorResolver+Internal.h"
#import "FirebaseAuth/Sources/MultiFactor/FIRMultiFactorSession+Internal.h"
2020-03-10 13:30:20 -07:00
#if TARGET_OS_IOS
2020-07-27 15:21:19 -07:00
#import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRPhoneMultiFactorAssertion.h"
2020-04-10 11:54:51 -07:00
#import "FirebaseAuth/Sources/AuthProvider/Phone/FIRPhoneAuthCredential_Internal.h"
#import "FirebaseAuth/Sources/MultiFactor/Phone/FIRPhoneMultiFactorAssertion+Internal.h"
2020-03-10 13:30:20 -07:00
#endif
NS_ASSUME_NONNULL_BEGIN
@implementation FIRMultiFactorResolver
2020-03-11 10:15:27 -07:00
- (instancetype)initWithMFAPendingCredential:(NSString *_Nullable)MFAPendingCredential
2020-03-10 13:30:20 -07:00
hints:(NSArray<FIRMultiFactorInfo *> *)hints {
self = [super init];
if (self) {
2020-03-11 10:15:27 -07:00
_MFAPendingCredential = MFAPendingCredential;
2020-03-10 13:30:20 -07:00
_hints = hints;
_auth = [FIRAuth auth];
_session = [[FIRMultiFactorSession alloc] init];
2020-03-11 10:15:27 -07:00
_session.MFAPendingCredential = MFAPendingCredential;
2020-03-10 13:30:20 -07:00
}
return self;
}
- (void)resolveSignInWithAssertion:(nonnull FIRMultiFactorAssertion *)assertion
completion:(nullable FIRAuthDataResultCallback)completion {
#if TARGET_OS_IOS
FIRPhoneMultiFactorAssertion *phoneAssertion = (FIRPhoneMultiFactorAssertion *)assertion;
2020-03-11 10:15:27 -07:00
FIRAuthProtoFinalizeMFAPhoneRequestInfo *finalizeMFAPhoneRequestInfo =
[[FIRAuthProtoFinalizeMFAPhoneRequestInfo alloc]
2020-03-17 10:22:29 -07:00
initWithSessionInfo:phoneAssertion.authCredential.verificationID
verificationCode:phoneAssertion.authCredential.verificationCode];
FIRFinalizeMFASignInRequest *request = [[FIRFinalizeMFASignInRequest alloc]
initWithMFAPendingCredential:self.MFAPendingCredential
verificationInfo:finalizeMFAPhoneRequestInfo
requestConfiguration:self.auth.requestConfiguration];
2020-03-17 10:22:29 -07:00
[FIRAuthBackend
finalizeMultiFactorSignIn:request
callback:^(FIRFinalizeMFASignInResponse *_Nullable response,
NSError *_Nullable error) {
if (error) {
if (completion) {
completion(nil, error);
}
} else {
[FIRAuth.auth
completeSignInWithAccessToken:response.IDToken
accessTokenExpirationDate:nil
refreshToken:response.refreshToken
anonymous:NO
callback:^(FIRUser *_Nullable user,
NSError *_Nullable error) {
FIRAuthDataResult *result =
[[FIRAuthDataResult alloc]
initWithUser:user
additionalUserInfo:nil];
FIRAuthDataResultCallback decoratedCallback =
[FIRAuth.auth
signInFlowAuthDataResultCallbackByDecoratingCallback:
completion];
decoratedCallback(result, error);
}];
}
}];
2020-03-10 13:30:20 -07:00
#endif
}
@end
NS_ASSUME_NONNULL_END
#endif