From fb862ff6252b9d429849fa672df64e7e35153cf8 Mon Sep 17 00:00:00 2001 From: Themis wang Date: Mon, 12 Feb 2024 13:38:15 -0500 Subject: [PATCH] Sending authendication token for crashlytics and session --- .../Controllers/FIRCLSReportUploader.h | 1 + .../Controllers/FIRCLSReportUploader.m | 7 ++- .../Models/FIRCLSInstallIdentifierModel.h | 2 +- .../Models/FIRCLSInstallIdentifierModel.m | 33 ++++++------ .../Models/Record/FIRCLSReportAdapter.h | 3 +- .../Models/Record/FIRCLSReportAdapter.m | 6 ++- .../Protogen/nanopb/crashlytics.nanopb.c | 3 +- .../Protogen/nanopb/crashlytics.nanopb.h | 4 +- .../UnitTests/FIRCLSContextManagerTests.m | 9 ++-- .../FIRCLSInstallIdentifierModelTests.m | 50 +++++++++++-------- .../UnitTests/FIRCLSReportAdapterTests.m | 4 +- .../UnitTests/Mocks/FIRMockInstallations.m | 8 +++ .../Installations+InstallationsProtocol.swift | 19 ++++--- .../Sources/SessionCoordinator.swift | 6 ++- .../Sources/SessionStartEvent.swift | 6 +++ .../Settings/SettingsDownloadClient.swift | 4 +- .../Protogen/nanopb/sessions.nanopb.h | 1 + .../Mocks/MockInstallationsProtocol.swift | 5 +- 18 files changed, 112 insertions(+), 59 deletions(-) diff --git a/Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.h b/Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.h index 6f134b55296..3723a50e464 100644 --- a/Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.h +++ b/Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.h @@ -28,6 +28,7 @@ @property(nonatomic, readonly) NSOperationQueue *operationQueue; @property(nonatomic, readonly) FIRCLSFileManager *fileManager; @property(nonatomic, copy) NSString *fiid; +@property(nonatomic, copy) NSString *authToken; - (void)prepareAndSubmitReport:(FIRCLSInternalReport *)report dataCollectionToken:(FIRCLSDataCollectionToken *)dataCollectionToken diff --git a/Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.m b/Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.m index caf1bae252d..0de639c6e86 100644 --- a/Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.m +++ b/Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.m @@ -95,8 +95,10 @@ - (void)prepareAndSubmitReport:(FIRCLSInternalReport *)report // urgent mode. Since urgent mode happens when the app is in a crash loop, // we can safely assume users aren't rotating their FIID, so this can be skipped. if (!urgent) { - [self.installIDModel regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull newFIID) { + [self.installIDModel regenerateInstallIDIfNeededWithBlock:^( + NSString *_Nonnull newFIID, NSString *_Nonnull authToken) { self.fiid = [newFIID copy]; + self.authToken = [authToken copy]; }]; } else { FIRCLSWarningLog( @@ -186,7 +188,8 @@ - (void)uploadPackagedReportAtPath:(NSString *)path FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:path googleAppId:self.googleAppID installIDModel:self.installIDModel - fiid:self.fiid]; + fiid:self.fiid + authToken:self.authToken]; GDTCOREvent *event = [self.googleTransport eventForTransport]; event.dataObject = adapter; diff --git a/Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.h b/Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.h index fd33a4b6959..4e0f4832162 100644 --- a/Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.h +++ b/Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.h @@ -44,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN * - Concern 2: Whatever the FIID is, we should send it with the Crash report so we're in sync with * Sessions and other Firebase SDKs */ -- (BOOL)regenerateInstallIDIfNeededWithBlock:(void (^)(NSString *fiid))block; +- (BOOL)regenerateInstallIDIfNeededWithBlock:(void (^)(NSString *fiid, NSString *authToken))block; @end diff --git a/Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.m b/Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.m index 9cc936bb50e..4949353cc2a 100644 --- a/Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.m +++ b/Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.m @@ -98,25 +98,30 @@ - (NSString *)generateInstallationUUID { #pragma mark Privacy Shield -- (BOOL)regenerateInstallIDIfNeededWithBlock:(void (^)(NSString *fiid))block { +- (BOOL)regenerateInstallIDIfNeededWithBlock:(void (^)(NSString *fiid, NSString *authToken))block { BOOL __block didRotate = false; dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); - // This runs Completion async, so wait a reasonable amount of time for it to finish. + // Get a FID Authentication Token. [self.installations - installationIDWithCompletion:^(NSString *_Nullable currentIID, NSError *_Nullable error) { - // Provide the IID to the callback. For this case we don't care - // if the FIID is null because it's the best we can do - we just want - // to send up the same FIID that is sent by other SDKs (eg. the Sessions SDK). - block(currentIID); - - didRotate = [self rotateCrashlyticsInstallUUIDWithIID:currentIID error:error]; - - if (didRotate) { - FIRCLSInfoLog(@"Rotated Crashlytics Install UUID because Firebase Install ID changed"); - } - dispatch_semaphore_signal(semaphore); + authTokenWithCompletion:^(FIRInstallationsAuthTokenResult *_Nullable tokenResult, + NSError *_Nullable error) { + // This runs Completion async, so wait a reasonable amount of time for it to finish. + [self.installations installationIDWithCompletion:^(NSString *_Nullable currentIID, + NSError *_Nullable error) { + // Provide the IID to the callback. For this case we don't care + // if the FIID is null because it's the best we can do - we just want + // to send up the same FIID that is sent by other SDKs (eg. the Sessions SDK). + block(currentIID, tokenResult.authToken); + + didRotate = [self rotateCrashlyticsInstallUUIDWithIID:currentIID error:error]; + + if (didRotate) { + FIRCLSInfoLog(@"Rotated Crashlytics Install UUID because Firebase Install ID changed"); + } + dispatch_semaphore_signal(semaphore); + }]; }]; intptr_t result = dispatch_semaphore_wait( diff --git a/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.h b/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.h index 24afcdeff91..4db047cf58f 100644 --- a/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.h +++ b/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.h @@ -35,5 +35,6 @@ - (instancetype)initWithPath:(NSString *)folderPath googleAppId:(NSString *)googleAppID installIDModel:(FIRCLSInstallIdentifierModel *)installIDModel - fiid:(NSString *)fiid; + fiid:(NSString *)fiid + authToken:(NSString *)authToken; @end diff --git a/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m b/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m index 3d52bbeb844..2cbcdb9ef23 100644 --- a/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m +++ b/Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m @@ -30,6 +30,7 @@ @interface FIRCLSReportAdapter () @property(nonatomic, strong) FIRCLSInstallIdentifierModel *installIDModel; @property(nonatomic, copy) NSString *fiid; +@property(nonatomic, copy) NSString *authToken; @end @@ -38,13 +39,15 @@ @implementation FIRCLSReportAdapter - (instancetype)initWithPath:(NSString *)folderPath googleAppId:(NSString *)googleAppID installIDModel:(FIRCLSInstallIdentifierModel *)installIDModel - fiid:(NSString *)fiid { + fiid:(NSString *)fiid + authToken:(NSString *)authToken { self = [super init]; if (self) { _folderPath = folderPath; _googleAppID = googleAppID; _installIDModel = installIDModel; _fiid = [fiid copy]; + _authToken = [authToken copy]; [self loadMetaDataFile]; @@ -156,6 +159,7 @@ - (google_crashlytics_Report)protoReport { report.installation_uuid = FIRCLSEncodeString(self.installIDModel.installID); report.firebase_installation_id = FIRCLSEncodeString(self.fiid); report.app_quality_session_id = FIRCLSEncodeString(self.identity.app_quality_session_id); + report.firebase_authentication_token = FIRCLSEncodeString(self.authToken); report.build_version = FIRCLSEncodeString(self.application.build_version); report.display_version = FIRCLSEncodeString(self.application.display_version); report.apple_payload = [self protoFilesPayload]; diff --git a/Crashlytics/Protogen/nanopb/crashlytics.nanopb.c b/Crashlytics/Protogen/nanopb/crashlytics.nanopb.c index cd9c87d50bd..3f3ef20ce17 100644 --- a/Crashlytics/Protogen/nanopb/crashlytics.nanopb.c +++ b/Crashlytics/Protogen/nanopb/crashlytics.nanopb.c @@ -26,7 +26,7 @@ -const pb_field_t google_crashlytics_Report_fields[10] = { +const pb_field_t google_crashlytics_Report_fields[11] = { PB_FIELD( 1, BYTES , SINGULAR, POINTER , FIRST, google_crashlytics_Report, sdk_version, sdk_version, 0), PB_FIELD( 3, BYTES , SINGULAR, POINTER , OTHER, google_crashlytics_Report, gmp_app_id, sdk_version, 0), PB_FIELD( 4, UENUM , SINGULAR, STATIC , OTHER, google_crashlytics_Report, platform, gmp_app_id, 0), @@ -36,6 +36,7 @@ const pb_field_t google_crashlytics_Report_fields[10] = { PB_FIELD( 10, MESSAGE , SINGULAR, STATIC , OTHER, google_crashlytics_Report, apple_payload, display_version, &google_crashlytics_FilesPayload_fields), PB_FIELD( 16, BYTES , SINGULAR, POINTER , OTHER, google_crashlytics_Report, firebase_installation_id, apple_payload, 0), PB_FIELD( 17, BYTES , SINGULAR, POINTER , OTHER, google_crashlytics_Report, app_quality_session_id, firebase_installation_id, 0), + PB_FIELD( 18, BYTES , SINGULAR, POINTER , OTHER, google_crashlytics_Report, firebase_authentication_token, app_quality_session_id, 0), PB_LAST_FIELD }; diff --git a/Crashlytics/Protogen/nanopb/crashlytics.nanopb.h b/Crashlytics/Protogen/nanopb/crashlytics.nanopb.h index ed9838ad47d..c8f62abf14d 100644 --- a/Crashlytics/Protogen/nanopb/crashlytics.nanopb.h +++ b/Crashlytics/Protogen/nanopb/crashlytics.nanopb.h @@ -61,6 +61,7 @@ typedef struct _google_crashlytics_Report { google_crashlytics_FilesPayload apple_payload; pb_bytes_array_t *firebase_installation_id; pb_bytes_array_t *app_quality_session_id; + pb_bytes_array_t *firebase_authentication_token; /* @@protoc_insertion_point(struct:google_crashlytics_Report) */ } google_crashlytics_Report; @@ -84,12 +85,13 @@ typedef struct _google_crashlytics_Report { #define google_crashlytics_Report_installation_uuid_tag 5 #define google_crashlytics_Report_firebase_installation_id_tag 16 #define google_crashlytics_Report_app_quality_session_id_tag 17 +#define google_crashlytics_Report_firebase_authentication_token 18 #define google_crashlytics_Report_build_version_tag 6 #define google_crashlytics_Report_display_version_tag 7 #define google_crashlytics_Report_apple_payload_tag 10 /* Struct field encoding specification for nanopb */ -extern const pb_field_t google_crashlytics_Report_fields[10]; +extern const pb_field_t google_crashlytics_Report_fields[11]; extern const pb_field_t google_crashlytics_FilesPayload_fields[2]; extern const pb_field_t google_crashlytics_FilesPayload_File_fields[3]; diff --git a/Crashlytics/UnitTests/FIRCLSContextManagerTests.m b/Crashlytics/UnitTests/FIRCLSContextManagerTests.m index 249b85f4991..887eb442bf0 100644 --- a/Crashlytics/UnitTests/FIRCLSContextManagerTests.m +++ b/Crashlytics/UnitTests/FIRCLSContextManagerTests.m @@ -75,7 +75,8 @@ - (void)test_notSettingSessionID_protoHasNilSessionID { FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:self.report.path googleAppId:@"TestGoogleAppID" installIDModel:self.installIDModel - fiid:@"TestFIID"]; + fiid:@"TestFIID" + authToken:@"TestAuthToken"]; XCTAssertEqualObjects(adapter.identity.app_quality_session_id, @""); } @@ -92,7 +93,8 @@ - (void)test_settingSessionIDMultipleTimes_protoHasLastSessionID { FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:self.report.path googleAppId:@"TestGoogleAppID" installIDModel:self.installIDModel - fiid:@"TestFIID"]; + fiid:@"TestFIID" + authToken:@"TestAuthToken"]; NSLog(@"reportPath: %@", self.report.path); XCTAssertEqualObjects(adapter.identity.app_quality_session_id, TestContextSessionID2); @@ -110,7 +112,8 @@ - (void)test_settingSessionIDOutOfOrder_protoHasLastSessionID { FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:self.report.path googleAppId:@"TestGoogleAppID" installIDModel:self.installIDModel - fiid:@"TestFIID"]; + fiid:@"TestFIID" + authToken:@"TestAuthToken"]; NSLog(@"reportPath: %@", self.report.path); XCTAssertEqualObjects(adapter.identity.app_quality_session_id, TestContextSessionID2); diff --git a/Crashlytics/UnitTests/FIRCLSInstallIdentifierModelTests.m b/Crashlytics/UnitTests/FIRCLSInstallIdentifierModelTests.m index b95b65b3ff6..da0f231572e 100644 --- a/Crashlytics/UnitTests/FIRCLSInstallIdentifierModelTests.m +++ b/Crashlytics/UnitTests/FIRCLSInstallIdentifierModelTests.m @@ -66,8 +66,9 @@ - (void)testCreateUUIDAndRotate { [[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid]; XCTAssertNotNil(model.installID); - BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){ - }]; + BOOL didRotate = [model + regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){ + }]; sleep(1); XCTAssertFalse(didRotate); @@ -85,8 +86,9 @@ - (void)testCreateUUIDAndErrorGettingInstanceID { [[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid]; XCTAssertNotNil(model.installID); - BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){ - }]; + BOOL didRotate = [model + regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){ + }]; XCTAssertFalse(didRotate); XCTAssertEqualObjects([_defaults objectForKey:FABInstallationUUIDKey], model.installID); @@ -135,8 +137,9 @@ - (void)testIIDChanges { [[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid]; XCTAssertNotNil(model.installID); - BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){ - }]; + BOOL didRotate = [model + regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){ + }]; XCTAssertTrue(didRotate); // Test that the UUID changed. @@ -158,8 +161,9 @@ - (void)testIIDDoesntChange { [[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid]; XCTAssertNotNil(model.installID); - BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){ - }]; + BOOL didRotate = [model + regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){ + }]; XCTAssertFalse(didRotate); // Test that the UUID changed. @@ -180,8 +184,9 @@ - (void)testUUIDSetButNeverIIDNilIID { [[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid]; XCTAssertNotNil(model.installID); - BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){ - }]; + BOOL didRotate = [model + regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){ + }]; XCTAssertFalse(didRotate); // Test that the UUID did not change. The FIID can be nil if @@ -202,8 +207,9 @@ - (void)testUUIDSetButNeverIIDWithIID { [[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid]; XCTAssertNotNil(model.installID); - BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){ - }]; + BOOL didRotate = [model + regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){ + }]; XCTAssertFalse(didRotate); // Test that the UUID did not change. The FIID can be nil if @@ -226,8 +232,9 @@ - (void)testADIDWasSetButNeverIID { [[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid]; XCTAssertNotNil(model.installID); - BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){ - }]; + BOOL didRotate = [model + regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){ + }]; XCTAssertFalse(didRotate); // Test that the UUID didn't change. @@ -248,8 +255,9 @@ - (void)testADIDWasSetAndIIDBecomesSet { [[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid]; XCTAssertNotNil(model.installID); - BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){ - }]; + BOOL didRotate = [model + regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){ + }]; XCTAssertFalse(didRotate); // Test that the UUID didn't change. @@ -272,8 +280,9 @@ - (void)testADIDAndIIDWereSet { [[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid]; XCTAssertNotNil(model.installID); - BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){ - }]; + BOOL didRotate = [model + regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){ + }]; XCTAssertFalse(didRotate); // Test that the UUID didn't change. @@ -297,8 +306,9 @@ - (void)testADIDAndIIDWereSet2 { [[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid]; XCTAssertNotNil(model.installID); - BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){ - }]; + BOOL didRotate = [model + regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){ + }]; XCTAssertTrue(didRotate); // Test that the UUID change. diff --git a/Crashlytics/UnitTests/FIRCLSReportAdapterTests.m b/Crashlytics/UnitTests/FIRCLSReportAdapterTests.m index 1298298ac9c..ae53871f043 100644 --- a/Crashlytics/UnitTests/FIRCLSReportAdapterTests.m +++ b/Crashlytics/UnitTests/FIRCLSReportAdapterTests.m @@ -32,6 +32,7 @@ @interface FIRCLSReportAdapterTests : XCTestCase @end static NSString *const TestFIID = @"TEST_FIID"; +static NSString *const TestAuthToken = @"TEST_AUTH_TOKEN"; @implementation FIRCLSReportAdapterTests @@ -46,7 +47,8 @@ - (FIRCLSReportAdapter *)constructAdapterWithPath:(NSString *)path return [[FIRCLSReportAdapter alloc] initWithPath:path googleAppId:googleAppID installIDModel:installIDModel - fiid:TestFIID]; + fiid:TestFIID + authToken:TestAuthToken]; } /// Attempt sending a proto report to the reporting endpoint diff --git a/Crashlytics/UnitTests/Mocks/FIRMockInstallations.m b/Crashlytics/UnitTests/Mocks/FIRMockInstallations.m index 25dda90e724..ad9efd86bc2 100644 --- a/Crashlytics/UnitTests/Mocks/FIRMockInstallations.m +++ b/Crashlytics/UnitTests/Mocks/FIRMockInstallations.m @@ -21,10 +21,18 @@ @interface FIRMockInstallationsImpl : NSObject @property(nonatomic, copy) NSString *installationID; @property(nonatomic, strong) NSError *error; +// the init function is not public for the token result, use as a placeholder to mock the token +// completion block +@property(nonatomic, strong) FIRInstallationsAuthTokenResult *tokenResult; + @end @implementation FIRMockInstallationsImpl +- (void)authTokenWithCompletion:(FIRInstallationsTokenHandler)completion { + completion(self.tokenResult, self.error); +} + - (void)installationIDWithCompletion:(FIRInstallationsIDHandler)completion { completion(self.installationID, self.error); } diff --git a/FirebaseSessions/Sources/Installations+InstallationsProtocol.swift b/FirebaseSessions/Sources/Installations+InstallationsProtocol.swift index 47d7a4f1ed5..52a18a1c626 100644 --- a/FirebaseSessions/Sources/Installations+InstallationsProtocol.swift +++ b/FirebaseSessions/Sources/Installations+InstallationsProtocol.swift @@ -16,18 +16,21 @@ import Foundation @_implementationOnly import FirebaseInstallations - +/// Return a tuple: (installationID, authenticationToken) for success result protocol InstallationsProtocol { - func installationID(completion: @escaping (Result) -> Void) + func installationID(completion: @escaping (Result<(String, String), Error>) -> Void) } extension Installations: InstallationsProtocol { - func installationID(completion: @escaping (Result) -> Void) { - installationID { (installationID: String?, error: Error?) in - if let installationID = installationID { - completion(.success(installationID)) - } else if let error = error { - completion(.failure(error)) + func installationID(completion: @escaping (Result<(String, String), Error>) -> Void) { + authToken { [weak self] (authTokenResult: InstallationsAuthTokenResult?, error: Error?) in + + self?.installationID { (installationID: String?, error: Error?) in + if let installationID = installationID { + completion(.success((installationID, authTokenResult?.authToken ?? ""))) + } else if let error = error { + completion(.failure(error)) + } } } } diff --git a/FirebaseSessions/Sources/SessionCoordinator.swift b/FirebaseSessions/Sources/SessionCoordinator.swift index 801eafb9e51..3d4cec1b072 100644 --- a/FirebaseSessions/Sources/SessionCoordinator.swift +++ b/FirebaseSessions/Sources/SessionCoordinator.swift @@ -67,11 +67,13 @@ class SessionCoordinator: SessionCoordinatorProtocol { -> Void) { installations.installationID { result in switch result { - case let .success(fiid): - event.setInstallationID(installationId: fiid) + case let .success(installationsInfo): + event.setInstallationID(installationId: installationsInfo.0) + event.setAuthenticationToken(authenticationToken: installationsInfo.1) callback(.success(())) case let .failure(error): event.setInstallationID(installationId: "") + event.setAuthenticationToken(authenticationToken: "") callback(.failure(FirebaseSessionsError.SessionInstallationsError(error))) } } diff --git a/FirebaseSessions/Sources/SessionStartEvent.swift b/FirebaseSessions/Sources/SessionStartEvent.swift index c107849a662..7943650ecca 100644 --- a/FirebaseSessions/Sources/SessionStartEvent.swift +++ b/FirebaseSessions/Sources/SessionStartEvent.swift @@ -104,6 +104,12 @@ class SessionStartEvent: NSObject, GDTCOREventDataObject { nanopb_free(oldID) } + func setAuthenticationToken(authenticationToken: String) { + let oldToken = proto.session_data.firebase_authentication_token + proto.session_data.firebase_authentication_token = makeProtoString(authenticationToken) + nanopb_free(oldToken) + } + func setSamplingRate(samplingRate: Double) { proto.session_data.data_collection_status.session_sampling_rate = samplingRate } diff --git a/FirebaseSessions/Sources/Settings/SettingsDownloadClient.swift b/FirebaseSessions/Sources/Settings/SettingsDownloadClient.swift index c944291857a..aaea90941dc 100644 --- a/FirebaseSessions/Sources/Settings/SettingsDownloadClient.swift +++ b/FirebaseSessions/Sources/Settings/SettingsDownloadClient.swift @@ -53,8 +53,8 @@ class SettingsDownloader: SettingsDownloadClient { installations.installationID { result in switch result { - case let .success(fiid): - let request = self.buildRequest(url: validURL, fiid: fiid) + case let .success(installationsInfo): + let request = self.buildRequest(url: validURL, fiid: installationsInfo.0) let task = URLSession.shared.dataTask(with: request) { data, response, error in if let data = data { if let dict = try? JSONSerialization.jsonObject(with: data) as? [String: Any] { diff --git a/FirebaseSessions/SourcesObjC/Protogen/nanopb/sessions.nanopb.h b/FirebaseSessions/SourcesObjC/Protogen/nanopb/sessions.nanopb.h index c8cfeb8edb3..c45f8df021b 100644 --- a/FirebaseSessions/SourcesObjC/Protogen/nanopb/sessions.nanopb.h +++ b/FirebaseSessions/SourcesObjC/Protogen/nanopb/sessions.nanopb.h @@ -157,6 +157,7 @@ typedef struct _firebase_appquality_sessions_AppleApplicationInfo { typedef struct _firebase_appquality_sessions_SessionInfo { pb_bytes_array_t *session_id; pb_bytes_array_t *firebase_installation_id; + pb_bytes_array_t *firebase_authentication_token; int64_t event_timestamp_us; firebase_appquality_sessions_DataCollectionStatus data_collection_status; pb_bytes_array_t *first_session_id; diff --git a/FirebaseSessions/Tests/Unit/Mocks/MockInstallationsProtocol.swift b/FirebaseSessions/Tests/Unit/Mocks/MockInstallationsProtocol.swift index 0abfdaf2446..8f3420f2a44 100644 --- a/FirebaseSessions/Tests/Unit/Mocks/MockInstallationsProtocol.swift +++ b/FirebaseSessions/Tests/Unit/Mocks/MockInstallationsProtocol.swift @@ -19,9 +19,10 @@ class MockInstallationsProtocol: InstallationsProtocol { static let testInstallationId = "testInstallationId" - var result: Result = .success(testInstallationId) + static let testAuthToken = "testAuthToken" + var result: Result<(String, String), Error> = .success((testInstallationId, testAuthToken)) - func installationID(completion: @escaping (Result) -> Void) { + func installationID(completion: @escaping (Result<(String, String), Error>) -> Void) { completion(result) } }