Skip to content

Commit ebea1ef

Browse files
authored
Custom fdl domain (#2121)
1 parent 48e5f7a commit ebea1ef

9 files changed

+78
-0
lines changed

Example/Auth/Tests/FIRGetOOBConfirmationCodeRequestTests.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@
126126
*/
127127
static NSString *const kCanHandleCodeInAppKey = @"canHandleCodeInApp";
128128

129+
/** @var kDynamicLinkDomainKey
130+
@brief The key for the "dynamic link domain" value in the request.
131+
*/
132+
static NSString *const kDynamicLinkDomainKey = @"dynamicLinkDomain";
133+
134+
/** @var kDynamicLinkDomain
135+
@brief Fake dynamic link domain for testing.
136+
*/
137+
static NSString *const kDynamicLinkDomain = @"test.page.link";
138+
129139
/** @class FIRGetOOBConfirmationCodeRequestTests
130140
@brief Tests for @c FIRGetOOBConfirmationCodeRequest.
131141
*/
@@ -194,6 +204,7 @@ - (void)testPasswordResetRequest {
194204
[NSNumber numberWithBool:YES]);
195205
XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kCanHandleCodeInAppKey],
196206
[NSNumber numberWithBool:YES]);
207+
XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kDynamicLinkDomainKey], kDynamicLinkDomain);
197208
}
198209

199210
/** @fn testSignInWithEmailLinkRequest
@@ -230,6 +241,7 @@ - (void)testSignInWithEmailLinkRequest {
230241
[NSNumber numberWithBool:YES]);
231242
XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kCanHandleCodeInAppKey],
232243
[NSNumber numberWithBool:YES]);
244+
XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kDynamicLinkDomainKey], kDynamicLinkDomain);
233245
}
234246

235247

@@ -268,6 +280,7 @@ - (void)testEmailVerificationRequest {
268280
[NSNumber numberWithBool:YES]);
269281
XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kCanHandleCodeInAppKey],
270282
[NSNumber numberWithBool:YES]);
283+
XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kDynamicLinkDomainKey], kDynamicLinkDomain);
271284
}
272285

273286
#pragma mark - Helpers
@@ -284,6 +297,7 @@ - (FIRActionCodeSettings *)fakeActionCodeSettings {
284297
minimumVersion:kAndroidMinimumVersion];
285298
actionCodeSettings.handleCodeInApp = YES;
286299
actionCodeSettings.URL = [NSURL URLWithString:kContinueURL];
300+
actionCodeSettings.dynamicLinkDomain = kDynamicLinkDomain;
287301
return actionCodeSettings;
288302
}
289303

Firebase/Auth/Source/FIRAuthErrorUtils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,13 @@ NS_ASSUME_NONNULL_BEGIN
501501
*/
502502
+ (NSError *)nullUserErrorWithMessage:(nullable NSString *)message;
503503

504+
/** @fn invalidDynamicLinkDomainErrorWithMessage:
505+
@brief Constructs an @c NSError with the code and message provided.
506+
@param message Error message from the backend, if any.
507+
@return The nullable NSError instance associated with the given error message, if one is found.
508+
*/
509+
+ (NSError *)invalidDynamicLinkDomainErrorWithMessage:(nullable NSString *)message;
510+
504511
/** @fn keychainErrorWithFunction:status:
505512
@brief Constructs an @c NSError with the @c FIRAuthErrorCodeKeychainError code.
506513
@param keychainFunction The keychain function which was invoked and yielded an unexpected

Firebase/Auth/Source/FIRAuthErrorUtils.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,13 @@
407407
static NSString *const kFIRAuthErrorMessageNullUser = @"A null user object was provided as the "
408408
"argument for an operation which requires a non-null user object.";
409409

410+
/** @var kFIRAuthErrorMessageInvalidDynamicLinkDomain
411+
@brief Message for @c kFIRAuthErrorMessageInvalidDynamicLinkDomain error code.
412+
*/
413+
static NSString *const kFIRAuthErrorMessageInvalidDynamicLinkDomain = @"The "
414+
"Firebase Dynamic Link domain used is either not configured or is unauthorized "
415+
"for the current project.";
416+
410417
/** @var kFIRAuthErrorMessageInternalError
411418
@brief Message for @c FIRAuthErrorCodeInternalError error code.
412419
*/
@@ -535,6 +542,8 @@
535542
return kFIRAuthErrorMessageWebRequestFailed;
536543
case FIRAuthErrorCodeNullUser:
537544
return kFIRAuthErrorMessageNullUser;
545+
case FIRAuthErrorCodeInvalidDynamicLinkDomain:
546+
return kFIRAuthErrorMessageInvalidDynamicLinkDomain;
538547
case FIRAuthErrorCodeWebInternalError:
539548
return kFIRAuthErrorMessageWebInternalError;
540549
case FIRAuthErrorCodeMalformedJWT:
@@ -658,6 +667,8 @@
658667
return @"ERROR_WEB_NETWORK_REQUEST_FAILED";
659668
case FIRAuthErrorCodeNullUser:
660669
return @"ERROR_NULL_USER";
670+
case FIRAuthErrorCodeInvalidDynamicLinkDomain:
671+
return @"ERROR_INVALID_DYNAMIC_LINK_DOMAIN";
661672
case FIRAuthErrorCodeWebInternalError:
662673
return @"ERROR_WEB_INTERNAL_ERROR";
663674
case FIRAuthErrorCodeMalformedJWT:
@@ -1019,6 +1030,10 @@ + (NSError *)nullUserErrorWithMessage:(nullable NSString *)message {
10191030
return [self errorWithCode:FIRAuthInternalErrorCodeNullUser message:message];
10201031
}
10211032

1033+
+ (NSError *)invalidDynamicLinkDomainErrorWithMessage:(nullable NSString *)message {
1034+
return [self errorWithCode:FIRAuthInternalErrorCodeInvalidDynamicLinkDomain message:message];
1035+
}
1036+
10221037
+ (NSError *)keychainErrorWithFunction:(NSString *)keychainFunction status:(OSStatus)status {
10231038
NSString *failureReason = [NSString stringWithFormat:@"%@ (%li)", keychainFunction, (long)status];
10241039
return [self errorWithCode:FIRAuthInternalErrorCodeKeychainError userInfo:@{

Firebase/Auth/Source/FIRAuthInternalErrors.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@ typedef NS_ENUM(NSInteger, FIRAuthInternalErrorCode) {
376376
FIRAuthInternalErrorCodeNullUser =
377377
FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeNullUser,
378378

379+
/** Indicates that the Firebase Dynamic Link domain used is either not configured or is unauthorized
380+
for the current project.
381+
*/
382+
FIRAuthInternalErrorCodeInvalidDynamicLinkDomain =
383+
FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidDynamicLinkDomain,
384+
379385
FIRAuthInternalErrorCodeMalformedJWT =
380386
FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeMalformedJWT,
381387

Firebase/Auth/Source/Public/FIRActionCodeSettings.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
*/
6060
@property(nonatomic, assign, readonly) BOOL androidInstallIfNotAvailable;
6161

62+
/** @property dynamicLinkDomain
63+
@brief The Firebase Dynamic Link domain used for out of band code flow.
64+
*/
65+
@property (copy, nonatomic, nullable) NSString *dynamicLinkDomain;
66+
6267
/** @fn setIOSBundleID
6368
@brief Sets the iOS bundle Id.
6469
@param iOSBundleID The iOS bundle ID.

Firebase/Auth/Source/Public/FIRAuthErrors.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ typedef NS_ENUM(NSInteger, FIRAuthErrorCode) {
304304
*/
305305
FIRAuthErrorCodeNullUser = 17067,
306306

307+
/** Indicates that the Firebase Dynamic Link domain used is either not configured or is unauthorized
308+
for the current project.
309+
*/
310+
FIRAuthErrorCodeInvalidDynamicLinkDomain = 17074,
311+
307312
/** Indicates an error occurred while attempting to access the keychain.
308313
*/
309314
FIRAuthErrorCodeKeychainError = 17995,

Firebase/Auth/Source/RPCs/FIRAuthBackend.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,12 @@
284284
*/
285285
static NSString *const kUnauthorizedDomainErrorMessage = @"UNAUTHORIZED_DOMAIN";
286286

287+
/** @var kInvalidDynamicLinkDomainErrorMessage
288+
@brief This is the error message the server will respond with if the dynamic link domain provided
289+
in the request is invalid.
290+
*/
291+
static NSString *const kInvalidDynamicLinkDomainErrorMessage = @"INVALID_DYNAMIC_LINK_DOMAIN";
292+
287293
/** @var kInvalidContinueURIErrorMessage
288294
@brief This is the error message the server will respond with if the continue URL provided in
289295
the request is invalid.
@@ -1044,6 +1050,10 @@ + (nullable NSError *)clientErrorWithServerErrorMessage:(NSString *)serverErrorM
10441050
return [FIRAuthErrorUtils invalidContinueURIErrorWithMessage:serverDetailErrorMessage];
10451051
}
10461052

1053+
if ([shortErrorMessage isEqualToString:kInvalidDynamicLinkDomainErrorMessage]) {
1054+
return [FIRAuthErrorUtils invalidDynamicLinkDomainErrorWithMessage:serverDetailErrorMessage];
1055+
}
1056+
10471057
if ([shortErrorMessage isEqualToString:kMissingContinueURIErrorMessage]) {
10481058
return [FIRAuthErrorUtils missingContinueURIErrorWithMessage:serverDetailErrorMessage];
10491059
}

Firebase/Auth/Source/RPCs/FIRGetOOBConfirmationCodeRequest.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ typedef NS_ENUM(NSInteger, FIRGetOOBConfirmationCodeRequestType) {
9696
*/
9797
@property(assign, nonatomic) BOOL handleCodeInApp;
9898

99+
/** @property dynamicLinkDomain
100+
@brief The Firebase Dynamic Link domain used for out of band code flow.
101+
*/
102+
@property (copy, nonatomic, nullable) NSString *dynamicLinkDomain;
103+
104+
99105
/** @fn passwordResetRequestWithEmail:actionCodeSettings:requestConfiguration:
100106
@brief Creates a password reset request.
101107
@param email The user's email address.

Firebase/Auth/Source/RPCs/FIRGetOOBConfirmationCodeRequest.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@
7474
*/
7575
static NSString *const kCanHandleCodeInAppKey = @"canHandleCodeInApp";
7676

77+
/** @var kDynamicLinkDomainKey
78+
@brief The key for the "dynamic link domain" value in the request.
79+
*/
80+
static NSString *const kDynamicLinkDomainKey = @"dynamicLinkDomain";
81+
7782
/** @var kPasswordResetRequestTypeValue
7883
@brief The value for the "PASSWORD_RESET" request type.
7984
*/
@@ -177,6 +182,7 @@ - (nullable instancetype)initWithRequestType:(FIRGetOOBConfirmationCodeRequestTy
177182
_androidMinimumVersion = actionCodeSettings.androidMinimumVersion;
178183
_androidInstallApp = actionCodeSettings.androidInstallIfNotAvailable;
179184
_handleCodeInApp = actionCodeSettings.handleCodeInApp;
185+
_dynamicLinkDomain = actionCodeSettings.dynamicLinkDomain;
180186
}
181187
return self;
182188
}
@@ -228,6 +234,10 @@ - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)
228234
body[kCanHandleCodeInAppKey] = @YES;
229235
}
230236

237+
if (_dynamicLinkDomain) {
238+
body[kDynamicLinkDomainKey] = _dynamicLinkDomain;
239+
}
240+
231241
return body;
232242
}
233243

0 commit comments

Comments
 (0)