Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Totp enrollment (#11114)
TOTP Enrollment Flow
  • Loading branch information
pragatimodi authored May 31, 2023
commit 978f6d73cde4fee5c8221863d7667f3d515ca504
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ - (void)verifyClientAndSendVerificationCodeToPhoneNumber:(NSString *)phoneNumber
} else {
if (callback) {
callback(
response.enrollmentResponse.sessionInfo,
response.phoneSessionInfo.sessionInfo,
nil);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import "FirebaseAuth/Sources/Backend/FIRAuthRPCRequest.h"
#import "FirebaseAuth/Sources/Backend/FIRIdentityToolkitRequest.h"
#import "FirebaseAuth/Sources/Backend/RPC/Proto/Phone/FIRAuthProtoFinalizeMFAPhoneRequestInfo.h"
#import "FirebaseAuth/Sources/Backend/RPC/Proto/TOTP/FIRAuthProtoFinalizeMFATOTPEnrollmentRequestInfo.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -25,13 +26,21 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, copy, readonly, nullable) NSString *IDToken;

@property(nonatomic, copy, readonly, nullable) NSString *displayName;

@property(nonatomic, copy, readonly, nullable)
FIRAuthProtoFinalizeMFAPhoneRequestInfo *verificationInfo;
FIRAuthProtoFinalizeMFAPhoneRequestInfo *phoneVerificationInfo;
@property(nonatomic, copy, readonly, nullable)
FIRAuthProtoFinalizeMFATOTPEnrollmentRequestInfo *TOTPVerificationInfo;

- (nullable instancetype)initWithIDToken:(NSString *)IDToken
displayName:(NSString *)displayName
phoneVerificationInfo:
(FIRAuthProtoFinalizeMFAPhoneRequestInfo *)phoneVerificationInfo
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration;

- (nullable instancetype)initWithIDToken:(NSString *)IDToken
displayName:(NSString *)displayName
verificationInfo:(FIRAuthProtoFinalizeMFAPhoneRequestInfo *)verificationInfo
TOTPVerificationInfo:
(FIRAuthProtoFinalizeMFATOTPEnrollmentRequestInfo *)TOTPVerificationInfo
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration;

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#import "FirebaseAuth/Sources/Backend/RPC/MultiFactor/Enroll/FIRFinalizeMFAEnrollmentRequest.h"

NS_ASSUME_NONNULL_BEGIN

static NSString *const kFinalizeMFAEnrollmentEndPoint = @"accounts/mfaEnrollment:finalize";

/** @var kTenantIDKey
Expand All @@ -27,7 +29,25 @@ @implementation FIRFinalizeMFAEnrollmentRequest

- (nullable instancetype)initWithIDToken:(NSString *)IDToken
displayName:(NSString *)displayName
verificationInfo:(FIRAuthProtoFinalizeMFAPhoneRequestInfo *)verificationInfo
phoneVerificationInfo:
(FIRAuthProtoFinalizeMFAPhoneRequestInfo *)phoneVerificationInfo
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
self = [super initWithEndpoint:kFinalizeMFAEnrollmentEndPoint
requestConfiguration:requestConfiguration
useIdentityPlatform:YES
useStaging:NO];
if (self) {
_IDToken = IDToken;
_displayName = displayName;
_phoneVerificationInfo = phoneVerificationInfo;
}
return self;
}

- (nullable instancetype)initWithIDToken:(NSString *)IDToken
displayName:(NSString *)displayName
TOTPVerificationInfo:
(FIRAuthProtoFinalizeMFATOTPEnrollmentRequestInfo *)TOTPVerificationInfo
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
self = [super initWithEndpoint:kFinalizeMFAEnrollmentEndPoint
requestConfiguration:requestConfiguration
Expand All @@ -36,7 +56,7 @@ - (nullable instancetype)initWithIDToken:(NSString *)IDToken
if (self) {
_IDToken = IDToken;
_displayName = displayName;
_verificationInfo = verificationInfo;
_TOTPVerificationInfo = TOTPVerificationInfo;
}
return self;
}
Expand All @@ -49,10 +69,10 @@ - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Null
if (_displayName) {
postBody[@"displayName"] = _displayName;
}
if (_verificationInfo) {
if ([_verificationInfo isKindOfClass:[FIRAuthProtoFinalizeMFAPhoneRequestInfo class]]) {
postBody[@"phoneVerificationInfo"] = [_verificationInfo dictionary];
}
if (_phoneVerificationInfo) {
postBody[@"phoneVerificationInfo"] = [_phoneVerificationInfo dictionary];
} else if (_TOTPVerificationInfo) {
postBody[@"totpVerificationInfo"] = [_TOTPVerificationInfo dictionary];
}
if (self.tenantID) {
postBody[kTenantIDKey] = self.tenantID;
Expand All @@ -61,3 +81,5 @@ - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Null
}

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#import "FirebaseAuth/Sources/Backend/FIRAuthRPCResponse.h"
#import "FirebaseAuth/Sources/Backend/RPC/Proto/Phone/FIRAuthProtoFinalizeMFAPhoneResponseInfo.h"
#import "FirebaseAuth/Sources/Backend/RPC/Proto/TOTP/FIRAuthProtoFinalizeMFATOTPEnrollmentResponseInfo.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -24,6 +25,10 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, copy, readonly, nullable) NSString *IDToken;

@property(nonatomic, copy, readonly, nullable) NSString *refreshToken;
@property(nonatomic, copy, readonly, nullable)
FIRAuthProtoFinalizeMFAPhoneResponseInfo *phoneAuthInfo;
@property(nonatomic, copy, readonly, nullable)
FIRAuthProtoFinalizeMFATOTPEnrollmentResponseInfo *TOTPAuthInfo;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@
*/

#import "FirebaseAuth/Sources/Backend/RPC/MultiFactor/Enroll/FIRFinalizeMFAEnrollmentResponse.h"

#import "FirebaseAuth/Sources/Backend/RPC/Proto/Phone/FIRAuthProtoFinalizeMFAPhoneResponseInfo.h"
#import "FirebaseAuth/Sources/Backend/RPC/Proto/TOTP/FIRAuthProtoFinalizeMFATOTPEnrollmentResponseInfo.h"

@implementation FIRFinalizeMFAEnrollmentResponse

- (BOOL)setWithDictionary:(nonnull NSDictionary *)dictionary
error:(NSError *__autoreleasing _Nullable *_Nullable)error {
_IDToken = [dictionary[@"idToken"] copy];
_refreshToken = [dictionary[@"refreshToken"] copy];
if (dictionary[@"phoneAuthInfo"] != nil) {
NSDictionary *data = dictionary[@"phoneAuthInfo"];
_phoneAuthInfo = [[FIRAuthProtoFinalizeMFAPhoneResponseInfo alloc] initWithDictionary:data];
} else if (dictionary[@"totpAuthInfo"] != nil) {
NSDictionary *data = dictionary[@"totpAuthInfo"];
_TOTPAuthInfo =
[[FIRAuthProtoFinalizeMFATOTPEnrollmentResponseInfo alloc] initWithDictionary:data];
}
return YES;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,25 @@
#import "FirebaseAuth/Sources/Backend/FIRAuthRPCRequest.h"
#import "FirebaseAuth/Sources/Backend/FIRIdentityToolkitRequest.h"
#import "FirebaseAuth/Sources/Backend/RPC/Proto/Phone/FIRAuthProtoStartMFAPhoneRequestInfo.h"
#import "FirebaseAuth/Sources/Backend/RPC/Proto/TOTP/FIRAuthProtoStartMFATOTPEnrollmentRequestInfo.h"

NS_ASSUME_NONNULL_BEGIN

@interface FIRStartMFAEnrollmentRequest : FIRIdentityToolkitRequest <FIRAuthRPCRequest>

@property(nonatomic, copy, readonly, nullable) NSString *IDToken;
@property(nonatomic, copy, readonly, nullable)
FIRAuthProtoStartMFAPhoneRequestInfo *phoneEnrollmentInfo;
@property(nonatomic, copy, readonly, nullable)
FIRAuthProtoStartMFATOTPEnrollmentRequestInfo *TOTPEnrollmentInfo;

@property(nonatomic, copy, readonly, nullable) FIRAuthProtoStartMFAPhoneRequestInfo *enrollmentInfo;
- (nullable instancetype)initWithIDToken:(NSString *)IDToken
enrollmentInfo:(FIRAuthProtoStartMFAPhoneRequestInfo *)phoneEnrollmentInfo
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration;

- (nullable instancetype)initWithIDToken:(NSString *)IDToken
enrollmentInfo:(FIRAuthProtoStartMFAPhoneRequestInfo *)enrollmentInfo
TOTPEnrollmentInfo:
(FIRAuthProtoStartMFATOTPEnrollmentRequestInfo *)TOTPEnrollmentInfo
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration;

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

#import "FirebaseAuth/Sources/Backend/RPC/MultiFactor/Enroll/FIRStartMFAEnrollmentRequest.h"

#import "FirebaseAuth/Sources/Backend/RPC/Proto/Phone/FIRAuthProtoStartMFAPhoneRequestInfo.h"
#import "FirebaseAuth/Sources/Backend/RPC/Proto/TOTP/FIRAuthProtoStartMFATOTPEnrollmentRequestInfo.h"

static NSString *const kStartMFAEnrollmentEndPoint = @"accounts/mfaEnrollment:start";

Expand All @@ -28,15 +28,30 @@
@implementation FIRStartMFAEnrollmentRequest

- (nullable instancetype)initWithIDToken:(NSString *)IDToken
enrollmentInfo:(FIRAuthProtoStartMFAPhoneRequestInfo *)enrollmentInfo
enrollmentInfo:(FIRAuthProtoStartMFAPhoneRequestInfo *)phoneEnrollmentInfo
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
self = [super initWithEndpoint:kStartMFAEnrollmentEndPoint
requestConfiguration:requestConfiguration
useIdentityPlatform:YES
useStaging:NO];
if (self) {
_IDToken = IDToken;
_phoneEnrollmentInfo = phoneEnrollmentInfo;
}
return self;
}

- (nullable instancetype)initWithIDToken:(NSString *)IDToken
TOTPEnrollmentInfo:
(FIRAuthProtoStartMFATOTPEnrollmentRequestInfo *)TOTPEnrollmentInfo
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
self = [super initWithEndpoint:kStartMFAEnrollmentEndPoint
requestConfiguration:requestConfiguration
useIdentityPlatform:YES
useStaging:NO];
if (self) {
_IDToken = IDToken;
_enrollmentInfo = enrollmentInfo;
_TOTPEnrollmentInfo = TOTPEnrollmentInfo;
}
return self;
}
Expand All @@ -46,10 +61,10 @@ - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Null
if (_IDToken) {
postBody[@"idToken"] = _IDToken;
}
if (_enrollmentInfo) {
if ([_enrollmentInfo isKindOfClass:[FIRAuthProtoStartMFAPhoneRequestInfo class]]) {
postBody[@"phoneEnrollmentInfo"] = [_enrollmentInfo dictionary];
}
if (_phoneEnrollmentInfo) {
postBody[@"phoneEnrollmentInfo"] = [_phoneEnrollmentInfo dictionary];
} else if (_TOTPEnrollmentInfo) {
postBody[@"totpEnrollmentInfo"] = [_TOTPEnrollmentInfo dictionary];
}
if (self.tenantID) {
postBody[kTenantIDKey] = self.tenantID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

#import "FirebaseAuth/Sources/Backend/FIRAuthRPCResponse.h"
#import "FirebaseAuth/Sources/Backend/RPC/Proto/Phone/FIRAuthProtoStartMFAPhoneResponseInfo.h"
#import "FirebaseAuth/Sources/Backend/RPC/Proto/TOTP/FIRAuthProtoStartMFATOTPEnrollmentResponseInfo.h"

NS_ASSUME_NONNULL_BEGIN

@interface FIRStartMFAEnrollmentResponse : NSObject <FIRAuthRPCResponse>

@property(nonatomic, copy, readonly, nullable)
FIRAuthProtoStartMFAPhoneResponseInfo *enrollmentResponse;
FIRAuthProtoStartMFAPhoneResponseInfo *phoneSessionInfo;
@property(nonatomic, copy, readonly, nullable)
FIRAuthProtoStartMFATOTPEnrollmentResponseInfo *TOTPSessionInfo;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@
#import "FirebaseAuth/Sources/Backend/RPC/MultiFactor/Enroll/FIRStartMFAEnrollmentResponse.h"

#import "FirebaseAuth/Sources/Backend/RPC/Proto/Phone/FIRAuthProtoStartMFAPhoneResponseInfo.h"
#import "FirebaseAuth/Sources/Backend/RPC/Proto/TOTP/FIRAuthProtoStartMFATOTPEnrollmentResponseInfo.h"

@implementation FIRStartMFAEnrollmentResponse

- (BOOL)setWithDictionary:(nonnull NSDictionary *)dictionary
error:(NSError *__autoreleasing _Nullable *_Nullable)error {
if (dictionary[@"phoneSessionInfo"] != nil) {
NSDictionary *data = dictionary[@"phoneSessionInfo"];
_enrollmentResponse = [[FIRAuthProtoStartMFAPhoneResponseInfo alloc] initWithDictionary:data];
_phoneSessionInfo = [[FIRAuthProtoStartMFAPhoneResponseInfo alloc] initWithDictionary:data];
} else if (dictionary[@"totpSessionInfo"] != nil) {
NSDictionary *data = dictionary[@"totpSessionInfo"];
_TOTPSessionInfo =
[[FIRAuthProtoStartMFATOTPEnrollmentResponseInfo alloc] initWithDictionary:data];
} else {
return NO;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface FIRAuthProtoMFAEnrollment : NSObject <FIRAuthProto>

@property(nonatomic, copy, readonly, nullable) NSString *phoneInfo;
@property(nonatomic, copy, readonly, nullable) NSObject *TOTPInfo;

@property(nonatomic, copy, readonly, nullable) NSString *MFAEnrollmentID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary {
if (self) {
if (dictionary[@"phoneInfo"]) {
_phoneInfo = dictionary[@"phoneInfo"];
} else if (dictionary[@"totpInfo"]) {
_TOTPInfo = dictionary[@"totpInfo"];
}
_MFAEnrollmentID = dictionary[@"mfaEnrollmentId"];
_displayName = dictionary[@"displayName"];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2023 Google LLC
*
* 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/LICENSE-2.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.
*/

#import "FirebaseAuth/Sources/Backend/RPC/Proto/FIRAuthProto.h"

NS_ASSUME_NONNULL_BEGIN

@interface FIRAuthProtoFinalizeMFATOTPEnrollmentRequestInfo : NSObject <FIRAuthProto>

@property(nonatomic, copy, readonly, nonnull) NSString *sessionInfo;
@property(nonatomic, copy, readonly, nonnull) NSString *verificationCode;

- (instancetype)initWithSessionInfo:(NSString *)sessionInfo
verificationCode:(NSString *)verificationCode;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2023 Google LLC
*
* 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/LICENSE-2.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.
*/

#import "FirebaseAuth/Sources/Backend/RPC/Proto/TOTP/FIRAuthProtoFinalizeMFATOTPEnrollmentRequestInfo.h"

NS_ASSUME_NONNULL_BEGIN

@implementation FIRAuthProtoFinalizeMFATOTPEnrollmentRequestInfo

- (instancetype)initWithSessionInfo:(NSString *)sessionInfo
verificationCode:(NSString *)verificationCode {
self = [super init];
if (self) {
_sessionInfo = sessionInfo;
_verificationCode = verificationCode;
}
return self;
}

- (NSDictionary *)dictionary {
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
if (_sessionInfo) {
dict[@"sessionInfo"] = _sessionInfo;
}
if (_verificationCode) {
dict[@"verificationCode"] = _verificationCode;
}
return [dict copy];
}

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2023 Google LLC
*
* 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/LICENSE-2.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.
*/

#import "FirebaseAuth/Sources/Backend/RPC/Proto/FIRAuthProto.h"

NS_ASSUME_NONNULL_BEGIN

@interface FIRAuthProtoFinalizeMFATOTPEnrollmentResponseInfo : NSObject <FIRAuthProto>

@end

NS_ASSUME_NONNULL_END
Loading