Skip to content

Commit 2e732d1

Browse files
committed
Store flag to disable FRT in requestContext instead of msidConfiguration.
1 parent 3aa7008 commit 2e732d1

13 files changed

+125
-72
lines changed

IdentityCore/src/MSIDBasicContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
3232
@property (nonatomic, nullable) NSString *logComponent;
3333
@property (nonatomic, nullable) NSString *telemetryRequestId;
3434
@property (nonatomic, nullable) NSDictionary *appRequestMetadata;
35+
@property (nonatomic, readwrite) BOOL disableFRT;
3536

3637
@end
3738

IdentityCore/src/MSIDRequestContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,11 @@
2929
- (NSString *)logComponent;
3030
- (NSString *)telemetryRequestId;
3131
- (NSDictionary *)appRequestMetadata;
32+
/**
33+
Temporal property to disable Family Refresh Token. This will be removed in future, added to allow 1P apps to disablle this feature themselves.
34+
Enabled by default, also configured to be enabled/disabled remotely by Microsoft.
35+
*/
36+
//- (BOOL)disableFRT;
37+
@property (nonatomic, readwrite) BOOL disableFRT;
3238

3339
@end

IdentityCore/src/cache/accessor/MSIDAccountCredentialCache.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@
197197
/*
198198
Check if support FRT has been enabled
199199
*/
200-
- (BOOL)checkFRTEnabled:(nonnull MSIDConfiguration *)configuration
201-
context:(nullable id<MSIDRequestContext>)context
200+
- (BOOL)checkFRTEnabled:(nullable id<MSIDRequestContext>)context
202201
error:(NSError * _Nullable __autoreleasing * _Nullable)error;
203202

204203
/*

IdentityCore/src/cache/accessor/MSIDAccountCredentialCache.m

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ - (BOOL)removeCredential:(nonnull MSIDCredentialCacheItem *)credential
385385

386386
BOOL result = [_dataSource removeTokensWithKey:key context:context error:error];
387387

388-
if (result && credential.credentialType == MSIDRefreshTokenType)
388+
if (result && (credential.credentialType == MSIDRefreshTokenType || credential.credentialType == MSIDFamilyRefreshTokenType))
389389
{
390390
[_dataSource saveWipeInfoWithContext:context error:nil];
391391
}
@@ -559,12 +559,11 @@ - (BOOL)removeAppMetadata:(nonnull MSIDAppMetadataCacheItem *)appMetadata
559559
return cacheItems;
560560
}
561561

562-
- (BOOL)checkFRTEnabled:(nonnull MSIDConfiguration *)configuration
563-
context:(nullable id<MSIDRequestContext>)context
562+
- (BOOL)checkFRTEnabled:(nullable id<MSIDRequestContext>)context
564563
error:(NSError * _Nullable __autoreleasing * _Nullable)error
565564
{
566565

567-
if (configuration.disableFRT)
566+
if (context.disableFRT)
568567
{
569568
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, context, @"FRT disabled by MSAL client app, returning NO");
570569
return NO;
@@ -579,7 +578,7 @@ - (BOOL)checkFRTEnabled:(nonnull MSIDConfiguration *)configuration
579578
if (readError)
580579
{
581580
MSID_LOG_WITH_CTX(MSIDLogLevelError, context, @"Failed to retrieve FRT cache entry, error: %@", readError);
582-
configuration.disableFRT = YES;
581+
context.disableFRT = YES;
583582
if (error)
584583
{
585584
*error = readError;
@@ -590,15 +589,15 @@ - (BOOL)checkFRTEnabled:(nonnull MSIDConfiguration *)configuration
590589
if (![jsonObjects count])
591590
{
592591
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, context, @"No FRT cache entry found, returning NO");
593-
configuration.disableFRT = YES;
592+
context.disableFRT = YES;
594593
return NO;
595594
}
596595

597596
NSDictionary *dict = [jsonObjects[0] jsonDictionary];
598597
if (!dict)
599598
{
600599
MSID_LOG_WITH_CTX(MSIDLogLevelError, context, @"Failed to deserialize FRT cache entry, returning NO");
601-
configuration.disableFRT = YES;
600+
context.disableFRT = YES;
602601
return NO;
603602
}
604603

@@ -609,7 +608,7 @@ - (BOOL)checkFRTEnabled:(nonnull MSIDConfiguration *)configuration
609608
}
610609

611610
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, context, @"FRT is disabled by the following apps: %@", dict[MSID_USE_SINGLE_FRT_APPS_DISABLED_KEY]);
612-
configuration.disableFRT = YES;
611+
context.disableFRT = YES;
613612
return NO;
614613
}
615614

IdentityCore/src/cache/accessor/MSIDDefaultTokenCacheAccessor.m

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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];

IdentityCore/src/configuration/MSIDConfiguration.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ extern NSString * const MSID_SCOPE_JSON_KEY;
3232
extern NSString * const MSID_TOKEN_TYPE_JSON_KEY;
3333
extern NSString * const MSID_NESTED_AUTH_BROKER_CLIENT_ID_JSON_KEY;
3434
extern NSString * const MSID_NESTED_AUTH_BROKER_REDIRECT_URI_JSON_KEY;
35-
extern NSString * const MSID_FRT_DISABLED_JSON_KEY;
3635

3736
@interface MSIDConfiguration : NSObject <NSCopying, MSIDJsonSerializable>
3837

@@ -47,9 +46,6 @@ extern NSString * const MSID_FRT_DISABLED_JSON_KEY;
4746
@property (atomic, readwrite) NSString *nestedAuthBrokerClientId;
4847
@property (atomic, readwrite) NSString *nestedAuthBrokerRedirectUri;
4948

50-
// Family refresh token enabled/disabled
51-
@property (atomic, readwrite) BOOL disableFRT;
52-
5349
@property (atomic, readwrite) NSString *applicationIdentifier;
5450

5551
@property (atomic, readonly) NSString *resource;

IdentityCore/src/configuration/MSIDConfiguration.m

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
NSString *const MSID_TOKEN_TYPE_JSON_KEY = @"token_type";
3737
NSString *const MSID_NESTED_AUTH_BROKER_CLIENT_ID_JSON_KEY = @"brk_client_id";
3838
NSString *const MSID_NESTED_AUTH_BROKER_REDIRECT_URI_JSON_KEY = @"brk_redirect_uri";
39-
NSString *const MSID_FRT_DISABLED_JSON_KEY = @"frt_disabled";
4039

4140
@interface MSIDConfiguration()
4241

@@ -61,7 +60,6 @@ - (instancetype)copyWithZone:(NSZone*)zone
6160
configuration.authScheme = [_authScheme copyWithZone:zone];
6261
configuration.nestedAuthBrokerClientId = [_nestedAuthBrokerClientId copyWithZone:zone];
6362
configuration.nestedAuthBrokerRedirectUri = [_nestedAuthBrokerRedirectUri copyWithZone:zone];
64-
configuration.disableFRT = _disableFRT;
6563
return configuration;
6664
}
6765

@@ -188,12 +186,6 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(NSError *__au
188186
MSIDAuthenticationScheme *authScheme = (MSIDAuthenticationScheme *)[MSIDJsonSerializableFactory createFromJSONDictionary:json classTypeJSONKey:MSID_TOKEN_TYPE_JSON_KEY assertKindOfClass:MSIDAuthenticationScheme.class error:nil];
189187
if (authScheme) config.authScheme = authScheme;
190188

191-
// If json contains an entry for frt_disabled, set it. Otherwise it will default to NO
192-
if (json[MSID_FRT_DISABLED_JSON_KEY])
193-
{
194-
config.disableFRT = [json msidBoolObjectForKey:MSID_FRT_DISABLED_JSON_KEY];
195-
}
196-
197189
return config;
198190
}
199191

@@ -227,7 +219,6 @@ - (NSDictionary *)jsonDictionary
227219
// Nested auth protocol
228220
json[MSID_NESTED_AUTH_BROKER_REDIRECT_URI_JSON_KEY] = self.nestedAuthBrokerRedirectUri;
229221
json[MSID_NESTED_AUTH_BROKER_CLIENT_ID_JSON_KEY] = self.nestedAuthBrokerClientId;
230-
json[MSID_FRT_DISABLED_JSON_KEY] = [@(self.disableFRT) stringValue];
231222

232223
NSDictionary *authSchemeJson = [self.authScheme jsonDictionary];
233224
if (!authSchemeJson)

IdentityCore/src/parameters/MSIDRequestParameters.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@
6060
@property (nonatomic) BOOL skipValidateResultAccount;
6161
@property (nonatomic) BOOL forceRefresh;
6262
@property (nonatomic) BOOL bypassRedirectURIValidation;
63-
/**
64-
Temporal property to disable Family Refresh Token. This will be removed in future, added to allow 1P apps to disablle this feature themselves.
65-
Enabled by default, also configured to be enabled/disabled remotely by Microsoft.
66-
*/
67-
@property (nonatomic) BOOL disableFRT;
6863

6964
// Telemetry metadata
7065
@property (nonatomic) NSString *platformSequence;
@@ -96,6 +91,11 @@
9691
@property (nonatomic) NSString *telemetryRequestId;
9792
@property (nonatomic) NSDictionary *appRequestMetadata;
9893
@property (nonatomic) NSString *telemetryApiId;
94+
/**
95+
Temporal property to disable Family Refresh Token. This will be removed in future, added to allow 1P apps to disablle this feature themselves.
96+
Enabled by default, also configured to be enabled/disabled remotely by Microsoft.
97+
*/
98+
@property (nonatomic, readwrite) BOOL disableFRT;
9999

100100
#pragma mark Conditional access
101101
@property (nonatomic) MSIDClaimsRequest *claimsRequest;

IdentityCore/src/parameters/MSIDRequestParameters.m

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,6 @@ - (void)setAuthScheme:(MSIDAuthenticationScheme *)authScheme
242242
[self updateMSIDConfiguration];
243243
}
244244

245-
- (void)setDisableFRT:(BOOL)disableFRT
246-
{
247-
_disableFRT = disableFRT;
248-
[self updateMSIDConfiguration];
249-
}
250-
251245
- (void)updateMSIDConfiguration
252246
{
253247
MSIDAuthority *authority = self.cloudAuthority ? self.cloudAuthority : self.authority;
@@ -262,7 +256,6 @@ - (void)updateMSIDConfiguration
262256
config.applicationIdentifier = [MSIDIntuneApplicationStateManager intuneApplicationIdentifierForAuthority:authority
263257
appIdentifier:self.intuneApplicationIdentifier];
264258
config.authScheme = self.authScheme;
265-
config.disableFRT = self.disableFRT;
266259
_msidConfiguration = config;
267260
}
268261

@@ -372,6 +365,7 @@ - (instancetype)copyWithZone:(NSZone*)zone
372365
parameters->_clientId = [_clientId copyWithZone:zone];
373366
parameters->_nestedAuthBrokerClientId = [_nestedAuthBrokerClientId copyWithZone:zone];
374367
parameters->_nestedAuthBrokerRedirectUri = [_nestedAuthBrokerRedirectUri copyWithZone:zone];
368+
parameters->_disableFRT = _disableFRT;
375369
parameters->_target = [_target copyWithZone:zone];
376370
parameters->_oidcScope = [_oidcScope copyWithZone:zone];
377371
parameters->_accountIdentifier = [_accountIdentifier copyWithZone:zone];

IdentityCore/src/requests/MSIDInteractiveTokenRequest.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ - (void)updateCustomHeadersForFRTSupportIfNeeded
158158
customHeaders[MSID_WEBAUTH_REFRESH_TOKEN_KEY] = refreshToken;
159159
}
160160

161-
// MSIDConfiguration.disableFRT could have been set to YES when checking the useSingleFRT keychain item, so we need to check again here
162-
if (!self.requestParameters.msidConfiguration.disableFRT)
161+
// self.requestParameters.disableFRT could have been set to YES while checking the useSingleFRT keychain item, so we need to check again here
162+
if (!self.requestParameters.disableFRT)
163163
{
164164
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, self.requestParameters, @"Added ignore sso to custom headers for webview");
165165
customHeaders[MSID_WEBAUTH_IGNORE_SSO_KEY] = @"1";

0 commit comments

Comments
 (0)