Skip to content

Commit fb862ff

Browse files
committed
Sending authendication token for crashlytics and session
1 parent 2c76938 commit fb862ff

18 files changed

+112
-59
lines changed

Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
@property(nonatomic, readonly) NSOperationQueue *operationQueue;
2929
@property(nonatomic, readonly) FIRCLSFileManager *fileManager;
3030
@property(nonatomic, copy) NSString *fiid;
31+
@property(nonatomic, copy) NSString *authToken;
3132

3233
- (void)prepareAndSubmitReport:(FIRCLSInternalReport *)report
3334
dataCollectionToken:(FIRCLSDataCollectionToken *)dataCollectionToken

Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ - (void)prepareAndSubmitReport:(FIRCLSInternalReport *)report
9595
// urgent mode. Since urgent mode happens when the app is in a crash loop,
9696
// we can safely assume users aren't rotating their FIID, so this can be skipped.
9797
if (!urgent) {
98-
[self.installIDModel regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull newFIID) {
98+
[self.installIDModel regenerateInstallIDIfNeededWithBlock:^(
99+
NSString *_Nonnull newFIID, NSString *_Nonnull authToken) {
99100
self.fiid = [newFIID copy];
101+
self.authToken = [authToken copy];
100102
}];
101103
} else {
102104
FIRCLSWarningLog(
@@ -186,7 +188,8 @@ - (void)uploadPackagedReportAtPath:(NSString *)path
186188
FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:path
187189
googleAppId:self.googleAppID
188190
installIDModel:self.installIDModel
189-
fiid:self.fiid];
191+
fiid:self.fiid
192+
authToken:self.authToken];
190193

191194
GDTCOREvent *event = [self.googleTransport eventForTransport];
192195
event.dataObject = adapter;

Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN
4444
* - Concern 2: Whatever the FIID is, we should send it with the Crash report so we're in sync with
4545
* Sessions and other Firebase SDKs
4646
*/
47-
- (BOOL)regenerateInstallIDIfNeededWithBlock:(void (^)(NSString *fiid))block;
47+
- (BOOL)regenerateInstallIDIfNeededWithBlock:(void (^)(NSString *fiid, NSString *authToken))block;
4848

4949
@end
5050

Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.m

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,30 @@ - (NSString *)generateInstallationUUID {
9898

9999
#pragma mark Privacy Shield
100100

101-
- (BOOL)regenerateInstallIDIfNeededWithBlock:(void (^)(NSString *fiid))block {
101+
- (BOOL)regenerateInstallIDIfNeededWithBlock:(void (^)(NSString *fiid, NSString *authToken))block {
102102
BOOL __block didRotate = false;
103103

104104
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
105105

106-
// This runs Completion async, so wait a reasonable amount of time for it to finish.
106+
// Get a FID Authentication Token.
107107
[self.installations
108-
installationIDWithCompletion:^(NSString *_Nullable currentIID, NSError *_Nullable error) {
109-
// Provide the IID to the callback. For this case we don't care
110-
// if the FIID is null because it's the best we can do - we just want
111-
// to send up the same FIID that is sent by other SDKs (eg. the Sessions SDK).
112-
block(currentIID);
113-
114-
didRotate = [self rotateCrashlyticsInstallUUIDWithIID:currentIID error:error];
115-
116-
if (didRotate) {
117-
FIRCLSInfoLog(@"Rotated Crashlytics Install UUID because Firebase Install ID changed");
118-
}
119-
dispatch_semaphore_signal(semaphore);
108+
authTokenWithCompletion:^(FIRInstallationsAuthTokenResult *_Nullable tokenResult,
109+
NSError *_Nullable error) {
110+
// This runs Completion async, so wait a reasonable amount of time for it to finish.
111+
[self.installations installationIDWithCompletion:^(NSString *_Nullable currentIID,
112+
NSError *_Nullable error) {
113+
// Provide the IID to the callback. For this case we don't care
114+
// if the FIID is null because it's the best we can do - we just want
115+
// to send up the same FIID that is sent by other SDKs (eg. the Sessions SDK).
116+
block(currentIID, tokenResult.authToken);
117+
118+
didRotate = [self rotateCrashlyticsInstallUUIDWithIID:currentIID error:error];
119+
120+
if (didRotate) {
121+
FIRCLSInfoLog(@"Rotated Crashlytics Install UUID because Firebase Install ID changed");
122+
}
123+
dispatch_semaphore_signal(semaphore);
124+
}];
120125
}];
121126

122127
intptr_t result = dispatch_semaphore_wait(

Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
- (instancetype)initWithPath:(NSString *)folderPath
3636
googleAppId:(NSString *)googleAppID
3737
installIDModel:(FIRCLSInstallIdentifierModel *)installIDModel
38-
fiid:(NSString *)fiid;
38+
fiid:(NSString *)fiid
39+
authToken:(NSString *)authToken;
3940
@end

Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ @interface FIRCLSReportAdapter ()
3030

3131
@property(nonatomic, strong) FIRCLSInstallIdentifierModel *installIDModel;
3232
@property(nonatomic, copy) NSString *fiid;
33+
@property(nonatomic, copy) NSString *authToken;
3334

3435
@end
3536

@@ -38,13 +39,15 @@ @implementation FIRCLSReportAdapter
3839
- (instancetype)initWithPath:(NSString *)folderPath
3940
googleAppId:(NSString *)googleAppID
4041
installIDModel:(FIRCLSInstallIdentifierModel *)installIDModel
41-
fiid:(NSString *)fiid {
42+
fiid:(NSString *)fiid
43+
authToken:(NSString *)authToken {
4244
self = [super init];
4345
if (self) {
4446
_folderPath = folderPath;
4547
_googleAppID = googleAppID;
4648
_installIDModel = installIDModel;
4749
_fiid = [fiid copy];
50+
_authToken = [authToken copy];
4851

4952
[self loadMetaDataFile];
5053

@@ -156,6 +159,7 @@ - (google_crashlytics_Report)protoReport {
156159
report.installation_uuid = FIRCLSEncodeString(self.installIDModel.installID);
157160
report.firebase_installation_id = FIRCLSEncodeString(self.fiid);
158161
report.app_quality_session_id = FIRCLSEncodeString(self.identity.app_quality_session_id);
162+
report.firebase_authentication_token = FIRCLSEncodeString(self.authToken);
159163
report.build_version = FIRCLSEncodeString(self.application.build_version);
160164
report.display_version = FIRCLSEncodeString(self.application.display_version);
161165
report.apple_payload = [self protoFilesPayload];

Crashlytics/Protogen/nanopb/crashlytics.nanopb.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828

29-
const pb_field_t google_crashlytics_Report_fields[10] = {
29+
const pb_field_t google_crashlytics_Report_fields[11] = {
3030
PB_FIELD( 1, BYTES , SINGULAR, POINTER , FIRST, google_crashlytics_Report, sdk_version, sdk_version, 0),
3131
PB_FIELD( 3, BYTES , SINGULAR, POINTER , OTHER, google_crashlytics_Report, gmp_app_id, sdk_version, 0),
3232
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] = {
3636
PB_FIELD( 10, MESSAGE , SINGULAR, STATIC , OTHER, google_crashlytics_Report, apple_payload, display_version, &google_crashlytics_FilesPayload_fields),
3737
PB_FIELD( 16, BYTES , SINGULAR, POINTER , OTHER, google_crashlytics_Report, firebase_installation_id, apple_payload, 0),
3838
PB_FIELD( 17, BYTES , SINGULAR, POINTER , OTHER, google_crashlytics_Report, app_quality_session_id, firebase_installation_id, 0),
39+
PB_FIELD( 18, BYTES , SINGULAR, POINTER , OTHER, google_crashlytics_Report, firebase_authentication_token, app_quality_session_id, 0),
3940
PB_LAST_FIELD
4041
};
4142

Crashlytics/Protogen/nanopb/crashlytics.nanopb.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ typedef struct _google_crashlytics_Report {
6161
google_crashlytics_FilesPayload apple_payload;
6262
pb_bytes_array_t *firebase_installation_id;
6363
pb_bytes_array_t *app_quality_session_id;
64+
pb_bytes_array_t *firebase_authentication_token;
6465
/* @@protoc_insertion_point(struct:google_crashlytics_Report) */
6566
} google_crashlytics_Report;
6667

@@ -84,12 +85,13 @@ typedef struct _google_crashlytics_Report {
8485
#define google_crashlytics_Report_installation_uuid_tag 5
8586
#define google_crashlytics_Report_firebase_installation_id_tag 16
8687
#define google_crashlytics_Report_app_quality_session_id_tag 17
88+
#define google_crashlytics_Report_firebase_authentication_token 18
8789
#define google_crashlytics_Report_build_version_tag 6
8890
#define google_crashlytics_Report_display_version_tag 7
8991
#define google_crashlytics_Report_apple_payload_tag 10
9092

9193
/* Struct field encoding specification for nanopb */
92-
extern const pb_field_t google_crashlytics_Report_fields[10];
94+
extern const pb_field_t google_crashlytics_Report_fields[11];
9395
extern const pb_field_t google_crashlytics_FilesPayload_fields[2];
9496
extern const pb_field_t google_crashlytics_FilesPayload_File_fields[3];
9597

Crashlytics/UnitTests/FIRCLSContextManagerTests.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ - (void)test_notSettingSessionID_protoHasNilSessionID {
7575
FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:self.report.path
7676
googleAppId:@"TestGoogleAppID"
7777
installIDModel:self.installIDModel
78-
fiid:@"TestFIID"];
78+
fiid:@"TestFIID"
79+
authToken:@"TestAuthToken"];
7980

8081
XCTAssertEqualObjects(adapter.identity.app_quality_session_id, @"");
8182
}
@@ -92,7 +93,8 @@ - (void)test_settingSessionIDMultipleTimes_protoHasLastSessionID {
9293
FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:self.report.path
9394
googleAppId:@"TestGoogleAppID"
9495
installIDModel:self.installIDModel
95-
fiid:@"TestFIID"];
96+
fiid:@"TestFIID"
97+
authToken:@"TestAuthToken"];
9698
NSLog(@"reportPath: %@", self.report.path);
9799

98100
XCTAssertEqualObjects(adapter.identity.app_quality_session_id, TestContextSessionID2);
@@ -110,7 +112,8 @@ - (void)test_settingSessionIDOutOfOrder_protoHasLastSessionID {
110112
FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:self.report.path
111113
googleAppId:@"TestGoogleAppID"
112114
installIDModel:self.installIDModel
113-
fiid:@"TestFIID"];
115+
fiid:@"TestFIID"
116+
authToken:@"TestAuthToken"];
114117
NSLog(@"reportPath: %@", self.report.path);
115118

116119
XCTAssertEqualObjects(adapter.identity.app_quality_session_id, TestContextSessionID2);

Crashlytics/UnitTests/FIRCLSInstallIdentifierModelTests.m

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ - (void)testCreateUUIDAndRotate {
6666
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
6767
XCTAssertNotNil(model.installID);
6868

69-
BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){
70-
}];
69+
BOOL didRotate = [model
70+
regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){
71+
}];
7172
sleep(1);
7273

7374
XCTAssertFalse(didRotate);
@@ -85,8 +86,9 @@ - (void)testCreateUUIDAndErrorGettingInstanceID {
8586
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
8687
XCTAssertNotNil(model.installID);
8788

88-
BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){
89-
}];
89+
BOOL didRotate = [model
90+
regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){
91+
}];
9092

9193
XCTAssertFalse(didRotate);
9294
XCTAssertEqualObjects([_defaults objectForKey:FABInstallationUUIDKey], model.installID);
@@ -135,8 +137,9 @@ - (void)testIIDChanges {
135137
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
136138
XCTAssertNotNil(model.installID);
137139

138-
BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){
139-
}];
140+
BOOL didRotate = [model
141+
regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){
142+
}];
140143
XCTAssertTrue(didRotate);
141144

142145
// Test that the UUID changed.
@@ -158,8 +161,9 @@ - (void)testIIDDoesntChange {
158161
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
159162
XCTAssertNotNil(model.installID);
160163

161-
BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){
162-
}];
164+
BOOL didRotate = [model
165+
regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){
166+
}];
163167
XCTAssertFalse(didRotate);
164168

165169
// Test that the UUID changed.
@@ -180,8 +184,9 @@ - (void)testUUIDSetButNeverIIDNilIID {
180184
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
181185
XCTAssertNotNil(model.installID);
182186

183-
BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){
184-
}];
187+
BOOL didRotate = [model
188+
regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){
189+
}];
185190
XCTAssertFalse(didRotate);
186191

187192
// Test that the UUID did not change. The FIID can be nil if
@@ -202,8 +207,9 @@ - (void)testUUIDSetButNeverIIDWithIID {
202207
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
203208
XCTAssertNotNil(model.installID);
204209

205-
BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){
206-
}];
210+
BOOL didRotate = [model
211+
regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){
212+
}];
207213
XCTAssertFalse(didRotate);
208214

209215
// Test that the UUID did not change. The FIID can be nil if
@@ -226,8 +232,9 @@ - (void)testADIDWasSetButNeverIID {
226232
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
227233
XCTAssertNotNil(model.installID);
228234

229-
BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){
230-
}];
235+
BOOL didRotate = [model
236+
regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){
237+
}];
231238
XCTAssertFalse(didRotate);
232239

233240
// Test that the UUID didn't change.
@@ -248,8 +255,9 @@ - (void)testADIDWasSetAndIIDBecomesSet {
248255
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
249256
XCTAssertNotNil(model.installID);
250257

251-
BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){
252-
}];
258+
BOOL didRotate = [model
259+
regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){
260+
}];
253261
XCTAssertFalse(didRotate);
254262

255263
// Test that the UUID didn't change.
@@ -272,8 +280,9 @@ - (void)testADIDAndIIDWereSet {
272280
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
273281
XCTAssertNotNil(model.installID);
274282

275-
BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){
276-
}];
283+
BOOL didRotate = [model
284+
regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){
285+
}];
277286
XCTAssertFalse(didRotate);
278287

279288
// Test that the UUID didn't change.
@@ -297,8 +306,9 @@ - (void)testADIDAndIIDWereSet2 {
297306
[[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
298307
XCTAssertNotNil(model.installID);
299308

300-
BOOL didRotate = [model regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid){
301-
}];
309+
BOOL didRotate = [model
310+
regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull fiid, NSString *_Nonnull authToken){
311+
}];
302312
XCTAssertTrue(didRotate);
303313

304314
// Test that the UUID change.

0 commit comments

Comments
 (0)