Skip to content

Commit 9585aa6

Browse files
authored
Adds ability to track Firebase Auth UI per request (firebase#251)
* Adds ability to track Firebase Auth UI per request Adds internal method to FIRAuth which will be accessed in Auth UI via an extension. Example request header header with Firebase Auth Core Marker: X-Client-Version: iOS/FirebaseSDK/0.1.1/FirebaseCore-iOS
1 parent 060bc53 commit 9585aa6

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

Firebase/Auth/Source/FIRAuth.m

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ @interface FIRAuth ()
202202
*/
203203
@property(nonatomic, copy, readonly) NSString *firebaseAppId;
204204

205+
/** @property additionalFrameworkMarker
206+
@brief Additional framework marker that will be added as part of the header of every request.
207+
*/
208+
@property(nonatomic, copy, nullable) NSString *additionalFrameworkMarker;
209+
205210
/** @fn initWithApp:
206211
@brief Creates a @c FIRAuth instance associated with the provided @c FIRApp instance.
207212
@param app The application to associate the auth instance with.
@@ -945,15 +950,29 @@ - (void)removeIDTokenDidChangeListener:(FIRIDTokenDidChangeListenerHandle)listen
945950
}
946951

947952
- (void)useAppLanguage {
948-
_requestConfiguration.languageCode = [NSBundle mainBundle].preferredLocalizations.firstObject;
953+
dispatch_sync(FIRAuthGlobalWorkQueue(), ^{
954+
_requestConfiguration.languageCode = [NSBundle mainBundle].preferredLocalizations.firstObject;
955+
});
949956
}
950957

951958
- (nullable NSString *)languageCode {
952959
return _requestConfiguration.languageCode;
953960
}
954961

955962
- (void)setLanguageCode:(nullable NSString *)languageCode {
956-
_requestConfiguration.languageCode = [languageCode copy];
963+
dispatch_sync(FIRAuthGlobalWorkQueue(), ^{
964+
_requestConfiguration.languageCode = [languageCode copy];
965+
});
966+
}
967+
968+
- (NSString *)additionalFrameworkMarker {
969+
return _requestConfiguration.additionalFrameworkMarker;
970+
}
971+
972+
- (void)setAdditionalFrameworkMarker:(NSString *)additionalFrameworkMarker {
973+
dispatch_sync(FIRAuthGlobalWorkQueue(), ^{
974+
_requestConfiguration.additionalFrameworkMarker = [additionalFrameworkMarker copy];
975+
});
957976
}
958977

959978
#if TARGET_OS_IOS

Firebase/Auth/Source/RPCs/FIRAuthBackend.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
*/
7777
static NSString *const kFirebaseLocalHeader = @"X-Firebase-Locale";
7878

79+
/** @var kFirebaseAuthCoreFrameworkMarker
80+
@brief The marker in the HTTP header that indicates the request comes from Firebase Auth Core.
81+
*/
82+
static NSString *const kFirebaseAuthCoreFrameworkMarker = @"FirebaseCore-iOS";
83+
7984
/** @var kJSONContentType
8085
@brief The value of the HTTP content-type header for JSON payloads.
8186
*/
@@ -499,8 +504,11 @@ - (void)asyncPostToURLWithRequestConfiguration:(FIRAuthRequestConfiguration *)re
499504
NSError *_Nullable))handler {
500505
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
501506
[request setValue:contentType forHTTPHeaderField:@"Content-Type"];
502-
NSString *clientVersion =
503-
[NSString stringWithFormat:@"iOS/FirebaseSDK/%s", FirebaseAuthVersionString];
507+
NSString *additionalFrameworkMarker = requestConfiguration.additionalFrameworkMarker ?:
508+
kFirebaseAuthCoreFrameworkMarker;
509+
NSString *clientVersion = [NSString stringWithFormat:@"iOS/FirebaseSDK/%s/%@",
510+
FirebaseAuthVersionString,
511+
additionalFrameworkMarker];
504512
[request setValue:clientVersion forHTTPHeaderField:kClientVersionHeader];
505513
NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
506514
[request setValue:bundleID forHTTPHeaderField:kIosBundleIdentifierHeader];

Firebase/Auth/Source/RPCs/FIRAuthRequestConfiguration.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ NS_ASSUME_NONNULL_BEGIN
3535
*/
3636
@property(nonatomic, copy, nullable) NSString *languageCode;
3737

38+
/** @property additionalFrameworkMarker
39+
@brief Additional framework marker that will be added as part of the header of every request.
40+
*/
41+
@property(nonatomic, copy, nullable) NSString *additionalFrameworkMarker;
42+
3843
- (nullable instancetype)init NS_UNAVAILABLE;
3944

4045
/** @fn initWithRequestClass:APIKey:authLanguage:

0 commit comments

Comments
 (0)