@@ -75,16 +75,9 @@ - (FIRUser *)getStoredUserForAccessGroup:(NSString *)accessGroup
75
75
shareAuthStateAcrossDevices : (BOOL )shareAuthStateAcrossDevices
76
76
projectIdentifier : (NSString *)projectIdentifier
77
77
error : (NSError *_Nullable *_Nullable)outError {
78
- NSMutableDictionary *query = [[NSMutableDictionary alloc ] init ];
79
- query[(__bridge id )kSecClass ] = (__bridge id )kSecClassGenericPassword ;
80
-
81
- query[(__bridge id )kSecAttrAccessGroup ] = accessGroup;
82
- query[(__bridge id )kSecAttrService ] = projectIdentifier;
83
- query[(__bridge id )kSecAttrAccount ] = kSharedKeychainAccountValue ;
84
- if (shareAuthStateAcrossDevices) {
85
- query[(__bridge id )kSecAttrSynchronizable ] = (__bridge id )kCFBooleanTrue ;
86
- }
87
-
78
+ NSMutableDictionary *query = [self keychainQueryForAccessGroup: accessGroup
79
+ shareAuthStateAcrossDevices: shareAuthStateAcrossDevices
80
+ projectIdentifier: projectIdentifier];
88
81
NSData *data = [self .keychainServices getItemWithQuery: query error: outError];
89
82
// If there's an outError parameter and it's populated, or there's no data, return.
90
83
if ((outError && *outError) || !data) {
@@ -113,22 +106,15 @@ - (BOOL)setStoredUser:(FIRUser *)user
113
106
shareAuthStateAcrossDevices : (BOOL )shareAuthStateAcrossDevices
114
107
projectIdentifier : (NSString *)projectIdentifier
115
108
error : (NSError *_Nullable *_Nullable)outError {
116
- NSMutableDictionary *query = [[NSMutableDictionary alloc ] init ];
117
- query[(__bridge id )kSecClass ] = (__bridge id )kSecClassGenericPassword ;
109
+ NSMutableDictionary *query = [self keychainQueryForAccessGroup: accessGroup
110
+ shareAuthStateAcrossDevices: shareAuthStateAcrossDevices
111
+ projectIdentifier: projectIdentifier];
118
112
if (shareAuthStateAcrossDevices) {
119
113
query[(__bridge id )kSecAttrAccessible ] = (__bridge id )kSecAttrAccessibleAfterFirstUnlock ;
120
114
} else {
121
115
query[(__bridge id )kSecAttrAccessible ] =
122
116
(__bridge id )kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly ;
123
117
}
124
-
125
- query[(__bridge id )kSecAttrAccessGroup ] = accessGroup;
126
- query[(__bridge id )kSecAttrService ] = projectIdentifier;
127
- query[(__bridge id )kSecAttrAccount ] = kSharedKeychainAccountValue ;
128
- if (shareAuthStateAcrossDevices) {
129
- query[(__bridge id )kSecAttrSynchronizable ] = (__bridge id )kCFBooleanTrue ;
130
- }
131
-
132
118
#if TARGET_OS_WATCH
133
119
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc ] initRequiringSecureCoding: false ];
134
120
#else
@@ -153,23 +139,44 @@ - (BOOL)removeStoredUserForAccessGroup:(NSString *)accessGroup
153
139
shareAuthStateAcrossDevices : (BOOL )shareAuthStateAcrossDevices
154
140
projectIdentifier : (NSString *)projectIdentifier
155
141
error : (NSError *_Nullable *_Nullable)outError {
156
- NSMutableDictionary *query = [[NSMutableDictionary alloc ] init ];
157
- query[(__bridge id )kSecClass ] = (__bridge id )kSecClassGenericPassword ;
142
+ NSMutableDictionary *query = [self keychainQueryForAccessGroup: accessGroup
143
+ shareAuthStateAcrossDevices: shareAuthStateAcrossDevices
144
+ projectIdentifier: projectIdentifier];
158
145
if (shareAuthStateAcrossDevices) {
159
146
query[(__bridge id )kSecAttrAccessible ] = (__bridge id )kSecAttrAccessibleAfterFirstUnlock ;
160
147
} else {
161
148
query[(__bridge id )kSecAttrAccessible ] =
162
149
(__bridge id )kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly ;
163
150
}
164
- if (shareAuthStateAcrossDevices) {
165
- query[(__bridge id )kSecAttrSynchronizable ] = (__bridge id )kCFBooleanTrue ;
166
- }
151
+ return [self .keychainServices removeItemWithQuery: query error: outError];
152
+ }
153
+
154
+ #pragma mark - Internal Methods
167
155
156
+ - (NSMutableDictionary *)keychainQueryForAccessGroup : (NSString *)accessGroup
157
+ shareAuthStateAcrossDevices : (BOOL )shareAuthStateAcrossDevices
158
+ projectIdentifier : (NSString *)projectIdentifier {
159
+ NSMutableDictionary *query = [[NSMutableDictionary alloc ] init ];
160
+ query[(__bridge id )kSecClass ] = (__bridge id )kSecClassGenericPassword ;
168
161
query[(__bridge id )kSecAttrAccessGroup ] = accessGroup;
169
162
query[(__bridge id )kSecAttrService ] = projectIdentifier;
170
163
query[(__bridge id )kSecAttrAccount ] = kSharedKeychainAccountValue ;
171
164
172
- return [self .keychainServices removeItemWithQuery: query error: outError];
165
+ if (@available (iOS 13.0 , macOS 10.15 , macCatalyst 13.0 , tvOS 13.0 , watchOS 6.0 , *)) {
166
+ /*
167
+ "The data protection key affects operations only in macOS.
168
+ Other platforms automatically behave as if the key is set to true,
169
+ and ignore the key in the query dictionary. You can safely use the key on all platforms."
170
+ [kSecUseDataProtectionKeychain](https://developer.apple.com/documentation/security/ksecusedataprotectionkeychain)
171
+ */
172
+ query[(__bridge id )kSecUseDataProtectionKeychain ] = (__bridge id )kCFBooleanTrue ;
173
+ }
174
+
175
+ if (shareAuthStateAcrossDevices) {
176
+ query[(__bridge id )kSecAttrSynchronizable ] = (__bridge id )kCFBooleanTrue ;
177
+ }
178
+
179
+ return query;
173
180
}
174
181
175
182
@end
0 commit comments