|
44 | 44 |
|
45 | 45 | NSTimeInterval const kFIRInstallationsTokenExpirationThreshold = 60 * 60; // 1 hour.
|
46 | 46 |
|
| 47 | +static NSString *const kKeychainService = @"com.firebase.FIRInstallations.installations"; |
| 48 | + |
47 | 49 | @interface FIRInstallationsIDController ()
|
48 | 50 | @property(nonatomic, readonly) NSString *appID;
|
49 | 51 | @property(nonatomic, readonly) NSString *appName;
|
@@ -71,9 +73,9 @@ - (instancetype)initWithGoogleAppID:(NSString *)appID
|
71 | 73 | APIKey:(NSString *)APIKey
|
72 | 74 | projectID:(NSString *)projectID
|
73 | 75 | GCMSenderID:(NSString *)GCMSenderID
|
74 |
| - accessGroup:(NSString *)accessGroup { |
75 |
| - GULKeychainStorage *secureStorage = |
76 |
| - [[GULKeychainStorage alloc] initWithService:@"com.firebase.FIRInstallations.installations"]; |
| 76 | + accessGroup:(nullable NSString *)accessGroup { |
| 77 | + NSString *serviceName = [FIRInstallationsIDController keychainServiceWithAppID:appID]; |
| 78 | + GULKeychainStorage *secureStorage = [[GULKeychainStorage alloc] initWithService:serviceName]; |
77 | 79 | FIRInstallationsStore *installationsStore =
|
78 | 80 | [[FIRInstallationsStore alloc] initWithSecureStorage:secureStorage accessGroup:accessGroup];
|
79 | 81 |
|
@@ -456,4 +458,23 @@ - (BOOL)isDefaultApp {
|
456 | 458 | return [self.appName isEqualToString:kFIRDefaultAppName];
|
457 | 459 | }
|
458 | 460 |
|
| 461 | +#pragma mark - Keychain |
| 462 | + |
| 463 | ++ (NSString *)keychainServiceWithAppID:(NSString *)appID { |
| 464 | +#if TARGET_OS_MACCATALYST || TARGET_OS_OSX |
| 465 | + // We need to keep service name unique per application on macOS. |
| 466 | + // Applications on macOS may request access to Keychain items stored by other applications. It |
| 467 | + // means that when the app looks up for a relevant Keychain item in the service scope it will |
| 468 | + // request user password to grant access to the Keychain if there are other Keychain items from |
| 469 | + // other applications stored under the same Keychain Service. |
| 470 | + return [kKeychainService stringByAppendingFormat:@".%@", appID]; |
| 471 | +#else |
| 472 | + // Use a constant Keychain service for non-macOS because: |
| 473 | + // 1. Keychain items cannot be shared between apps until configured specifically so the service |
| 474 | + // name collisions are not a concern |
| 475 | + // 2. We don't want to change the service name to avoid doing a migration. |
| 476 | + return kKeychainService; |
| 477 | +#endif |
| 478 | +} |
| 479 | + |
459 | 480 | @end
|
0 commit comments