Skip to content

Commit 8f8a5fd

Browse files
authored
Add support for deferred OAuth provisioning (#6121)
* Use GOOGLE_APP_ID instead of CLIENT_ID if CLIENT_ID is unavailable for generic IDP and phone auth flows. * Add a prefix to the custom URL scheme when using the Firebase app ID. * Add tests for FIROAuthProvider. * Add tests for FIRPhoneAuthProvider. * Change query param from firebaseAppId to appId. * Fix tests. * Address review comments. * Add changelog entry.
1 parent 9a24e53 commit 8f8a5fd

File tree

5 files changed

+426
-46
lines changed

5 files changed

+426
-46
lines changed

FirebaseAuth/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [changed] Added support for using GOOGLE_APP_ID in generic IDP and phone auth reCAPTCHA fallback flows. (#6121).
3+
14
# v6.7.1
25
- [fixed] Fixed a multithreaded memory access issue on iOS (#5979).
36

FirebaseAuth/Sources/AuthProvider/OAuth/FIROAuthProvider.m

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ typedef void (^FIRHeadfulLiteURLCallBack)(NSURL *_Nullable headfulLiteURL,
5252
*/
5353
static NSString *const kAuthTypeSignInWithRedirect = @"signInWithRedirect";
5454

55+
/** @var kCustomUrlSchemePrefix
56+
@brief The prefix to append to the Firebase app ID custom callback scheme..
57+
*/
58+
static NSString *const kCustomUrlSchemePrefix = @"app-";
59+
5560
@implementation FIROAuthProvider {
5661
/** @var _auth
5762
@brief The auth instance used for launching the URL presenter.
@@ -203,8 +208,15 @@ - (nullable instancetype)initWithProviderID:(NSString *)providerID auth:(FIRAuth
203208
if (self) {
204209
_auth = auth;
205210
_providerID = providerID;
206-
_callbackScheme = [[[_auth.app.options.clientID componentsSeparatedByString:@"."]
207-
reverseObjectEnumerator].allObjects componentsJoinedByString:@"."];
211+
if (_auth.app.options.clientID) {
212+
_callbackScheme = [[[_auth.app.options.clientID componentsSeparatedByString:@"."]
213+
reverseObjectEnumerator].allObjects componentsJoinedByString:@"."];
214+
} else {
215+
_callbackScheme = [kCustomUrlSchemePrefix
216+
stringByAppendingString:[_auth.app.options.googleAppID
217+
stringByReplacingOccurrencesOfString:@":"
218+
withString:@"-"]];
219+
}
208220
}
209221
return self;
210222
}
@@ -272,19 +284,24 @@ - (void)getHeadFulLiteURLWithEventID:(NSString *)eventID
272284
}
273285
__strong __typeof__(self) strongSelf = weakSelf;
274286
NSString *bundleID = [NSBundle mainBundle].bundleIdentifier;
275-
NSString *clienID = strongSelf->_auth.app.options.clientID;
287+
NSString *clientID = strongSelf->_auth.app.options.clientID;
288+
NSString *appID = strongSelf->_auth.app.options.googleAppID;
276289
NSString *apiKey =
277290
strongSelf->_auth.requestConfiguration.APIKey;
278291
NSMutableDictionary *urlArguments = [@{
279292
@"apiKey" : apiKey,
280-
@"authType" : @"signInWithRedirect",
293+
@"authType" : kAuthTypeSignInWithRedirect,
281294
@"ibi" : bundleID ?: @"",
282-
@"clientId" : clienID,
283295
@"sessionId" : [strongSelf hashforString:sessionID],
284296
@"v" : [FIRAuthBackend authUserAgent],
285297
@"eventId" : eventID,
286298
@"providerId" : strongSelf->_providerID,
287299
} mutableCopy];
300+
if (clientID) {
301+
urlArguments[@"clientId"] = clientID;
302+
} else {
303+
urlArguments[@"appId"] = appID;
304+
}
288305
if (strongSelf.scopes.count) {
289306
urlArguments[@"scopes"] =
290307
[strongSelf.scopes componentsJoinedByString:@","];

FirebaseAuth/Sources/AuthProvider/Phone/FIRPhoneAuthProvider.m

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ typedef void (^FIRFetchAuthDomainCallback)(NSString *_Nullable authDomain,
8383
*/
8484
static NSString *const kAuthTypeVerifyApp = @"verifyApp";
8585

86+
/** @var kCustomUrlSchemePrefix
87+
@brief The prefix to append to the Firebase app ID custom callback scheme..
88+
*/
89+
static NSString *const kCustomUrlSchemePrefix = @"app-";
90+
8691
/** @var kReCAPTCHAURLStringFormat
8792
@brief The format of the URL used to open the reCAPTCHA page during app verification.
8893
*/
@@ -111,8 +116,15 @@ - (nullable instancetype)initWithAuth:(FIRAuth *)auth {
111116
self = [super init];
112117
if (self) {
113118
_auth = auth;
114-
_callbackScheme = [[[_auth.app.options.clientID componentsSeparatedByString:@"."]
115-
reverseObjectEnumerator].allObjects componentsJoinedByString:@"."];
119+
if (_auth.app.options.clientID) {
120+
_callbackScheme = [[[_auth.app.options.clientID componentsSeparatedByString:@"."]
121+
reverseObjectEnumerator].allObjects componentsJoinedByString:@"."];
122+
} else {
123+
_callbackScheme = [kCustomUrlSchemePrefix
124+
stringByAppendingString:[_auth.app.options.googleAppID
125+
stringByReplacingOccurrencesOfString:@":"
126+
withString:@"-"]];
127+
}
116128
}
117129
return self;
118130
}
@@ -675,20 +687,28 @@ - (void)reCAPTCHAURLWithEventID:(NSString *)eventID completion:(FIRReCAPTCHAURLC
675687
}
676688
NSString *bundleID = [NSBundle mainBundle].bundleIdentifier;
677689
NSString *clientID = self->_auth.app.options.clientID;
690+
NSString *appID = self->_auth.app.options.googleAppID;
678691
NSString *apiKey = self->_auth.requestConfiguration.APIKey;
679692
NSMutableArray<NSURLQueryItem *> *queryItems = [@[
680693
[NSURLQueryItem queryItemWithName:@"apiKey" value:apiKey],
681694
[NSURLQueryItem queryItemWithName:@"authType"
682695
value:kAuthTypeVerifyApp],
683696
[NSURLQueryItem queryItemWithName:@"ibi"
684697
value:bundleID ?: @""],
685-
[NSURLQueryItem queryItemWithName:@"clientId"
686-
value:clientID],
687698
[NSURLQueryItem
688699
queryItemWithName:@"v"
689700
value:[FIRAuthBackend authUserAgent]],
690701
[NSURLQueryItem queryItemWithName:@"eventId" value:eventID]
691702
] mutableCopy];
703+
if (clientID) {
704+
[queryItems
705+
addObject:[NSURLQueryItem queryItemWithName:@"clientId"
706+
value:clientID]];
707+
} else {
708+
[queryItems
709+
addObject:[NSURLQueryItem queryItemWithName:@"appId"
710+
value:appID]];
711+
}
692712

693713
if (self->_auth.requestConfiguration.languageCode) {
694714
[queryItems

0 commit comments

Comments
 (0)