@@ -131,8 +131,8 @@ - (MSIDRefreshToken *)getRefreshTokenWithAccount:(MSIDAccountIdentifier *)accoun
131131 context : (id <MSIDRequestContext>)context
132132 error : (NSError *__autoreleasing *)error
133133{
134- BOOL frtEnabled = [_accountCredentialCache checkFRTEnabled: configuration context: context error: error];
135- if (* error)
134+ BOOL frtEnabled = [_accountCredentialCache checkFRTEnabled: context error: error];
135+ if (error)
136136 {
137137 MSID_LOG_WITH_CTX (MSIDLogLevelError, context, @" Error checking FRT enabled status, not using new FRT." );
138138 }
@@ -152,10 +152,9 @@ - (MSIDRefreshToken *)getRefreshTokenWithAccount:(MSIDAccountIdentifier *)accoun
152152 // This will happen the first time the app starts using a single family refresh token.
153153 if (credentialType == MSIDFamilyRefreshTokenType)
154154 {
155- credentialType = MSIDRefreshTokenType;
156155 refreshToken = [self getRefreshableTokenWithAccount: accountIdentifier
157156 familyId: familyId
158- credentialType: credentialType
157+ credentialType: MSIDRefreshTokenType
159158 configuration: configuration
160159 context: context
161160 error: error];
@@ -811,6 +810,25 @@ - (BOOL)validateAndRemoveRefreshToken:(MSIDRefreshToken *)token
811810 context : (id <MSIDRequestContext>)context
812811 error : (NSError *__autoreleasing*)error
813812{
813+ BOOL frtEnabled = [_accountCredentialCache checkFRTEnabled: context error: error];
814+ if (error)
815+ {
816+ MSID_LOG_WITH_CTX (MSIDLogLevelError, context, @" Error checking FRT enabled status, not using new FRT." );
817+ }
818+
819+ MSIDCredentialType credentialType = frtEnabled ? MSIDFamilyRefreshTokenType : MSIDRefreshTokenType;
820+
821+ BOOL result = [self validateAndRemoveRefreshableToken: token
822+ credentialType: credentialType
823+ context: context
824+ error: error];
825+
826+ // If family refresh token is not enabled, return list of regular refresh tokens
827+ if (!frtEnabled)
828+ {
829+ return result;
830+ }
831+
814832 return [self validateAndRemoveRefreshableToken: token
815833 credentialType: MSIDRefreshTokenType
816834 context: context
@@ -832,7 +850,10 @@ - (BOOL)validateAndRemoveRefreshableToken:(MSIDRefreshToken *)token
832850 context : (id <MSIDRequestContext>)context
833851 error : (NSError *__autoreleasing*)error
834852{
835- if (credentialType != MSIDRefreshTokenType && credentialType != MSIDPrimaryRefreshTokenType) return NO ;
853+ if (credentialType != MSIDRefreshTokenType && credentialType != MSIDPrimaryRefreshTokenType && credentialType != MSIDFamilyRefreshTokenType)
854+ {
855+ return NO ;
856+ }
836857
837858 if (!token || [NSString msidIsStringNilOrBlank: token.refreshToken])
838859 {
@@ -975,7 +996,7 @@ - (BOOL)saveRefreshTokenWithConfiguration:(MSIDConfiguration *)configuration
975996 {
976997 // Check if FRT is enabled, this will update the configuration object, and then use it to decide if
977998 // we should save the token as FRT or legacy RT (with familyId, if it contains that value).
978- BOOL frtEnabled = [_accountCredentialCache checkFRTEnabled: configuration context: context error: error];
999+ BOOL frtEnabled = [_accountCredentialCache checkFRTEnabled: context error: error];
9791000 if (*error)
9801001 {
9811002 MSID_LOG_WITH_CTX (MSIDLogLevelError, context, @" Error checking FRT enabled status, not saving as new FRT." );
@@ -1042,7 +1063,7 @@ - (BOOL)removeToken:(MSIDBaseToken *)token
10421063 CONDITIONAL_START_CACHE_EVENT (event, MSID_TELEMETRY_EVENT_TOKEN_CACHE_DELETE, context);
10431064 BOOL result = [_accountCredentialCache removeCredential: token.tokenCacheItem context: context error: error];
10441065
1045- if (result && token.credentialType == MSIDRefreshTokenType)
1066+ if (result && ( token.credentialType == MSIDRefreshTokenType || token. credentialType == MSIDFamilyRefreshTokenType) )
10461067 {
10471068 [_accountCredentialCache saveWipeInfoWithContext: context error: nil ];
10481069 }
@@ -1107,7 +1128,7 @@ - (MSIDBaseToken *)getTokenWithEnvironment:(NSString *)environment
11071128 return resultTokens[0 ];
11081129 }
11091130
1110- if (cacheQuery.credentialType == MSIDRefreshTokenType)
1131+ if (cacheQuery.credentialType == MSIDRefreshTokenType || cacheQuery. credentialType == MSIDFamilyRefreshTokenType )
11111132 {
11121133 NSError *wipeError = nil ;
11131134 CONDITIONAL_STOP_FAILED_CACHE_EVENT (event, [_accountCredentialCache wipeInfoWithContext: context error: &wipeError], context);
@@ -1254,10 +1275,51 @@ - (BOOL)saveAccount:(MSIDAccount *)account
12541275 accountCredentialCache : (MSIDAccountCredentialCache *)accountCredentialCache
12551276 context : (id <MSIDRequestContext>)context
12561277 error : (NSError *__autoreleasing*)error
1278+ {
1279+ BOOL frtEnabled = [_accountCredentialCache checkFRTEnabled: context error: error];
1280+ if (*error)
1281+ {
1282+ MSID_LOG_WITH_CTX (MSIDLogLevelError, context, @" Error checking FRT enabled status, not using new FRT." );
1283+ }
1284+
1285+ MSIDCredentialType credentialType = frtEnabled ? MSIDFamilyRefreshTokenType : MSIDRefreshTokenType;
1286+
1287+ NSSet <NSString *> *firstSet = [self homeAccountIdsFromRTsWithAuthority: authority
1288+ clientId: clientId
1289+ familyId: familyId
1290+ credentialType: credentialType
1291+ accountCredentialCache: accountCredentialCache
1292+ context: context
1293+ error: error];
1294+
1295+ // If family refresh token is not enabled, return list of regular refresh tokens
1296+ if (!frtEnabled)
1297+ {
1298+ return firstSet;
1299+ }
1300+
1301+ NSSet <NSString *> *secondSet = [self homeAccountIdsFromRTsWithAuthority: authority
1302+ clientId: clientId
1303+ familyId: familyId
1304+ credentialType: MSIDRefreshTokenType
1305+ accountCredentialCache: accountCredentialCache
1306+ context: context
1307+ error: error];
1308+
1309+ return [firstSet setByAddingObjectsFromSet: secondSet];
1310+ }
1311+
1312+ - (NSSet <NSString *> *)homeAccountIdsFromRTsWithAuthority : (MSIDAuthority *)authority
1313+ clientId : (NSString *)clientId
1314+ familyId : (NSString *)familyId
1315+ credentialType : (MSIDCredentialType)credentialType
1316+ accountCredentialCache : (MSIDAccountCredentialCache *)accountCredentialCache
1317+ context : (id <MSIDRequestContext>)context
1318+ error : (NSError *__autoreleasing*)error
12571319{
12581320 // Retrieve refresh tokens in cache, and return account ids for those refresh tokens
12591321 MSIDDefaultCredentialCacheQuery *refreshTokenQuery = [MSIDDefaultCredentialCacheQuery new ];
1260- refreshTokenQuery.credentialType = MSIDRefreshTokenType ;
1322+ refreshTokenQuery.credentialType = credentialType ;
12611323 refreshTokenQuery.clientId = clientId;
12621324 refreshTokenQuery.familyId = familyId;
12631325 refreshTokenQuery.environmentAliases = [authority defaultCacheEnvironmentAliases ];
0 commit comments