Skip to content

Commit 69c6d7a

Browse files
authored
Merge pull request #2767 from AzureAD/ameyapat/add-bart-support-toggle-button
Refresh release/2.6.0 with MSAL test app changes for toggling BART support
2 parents cf7d1b8 + 78c7a3e commit 69c6d7a

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

MSAL/test/app/ios/MSALTestAppCacheViewController.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#import "MSIDMetadataCache.h"
6363
#import "MSIDAccountMetadataCacheItem.h"
6464
#import "MSIDAccountMetadataCacheKey.h"
65+
#import "MSIDBoundRefreshToken.h"
6566

6667
#define BAD_REFRESH_TOKEN @"bad-refresh-token"
6768
#define APP_METADATA @"App-Metadata"
@@ -166,6 +167,7 @@ - (void)deleteToken:(MSIDBaseToken *)token
166167
{
167168
case MSIDFamilyRefreshTokenType:
168169
case MSIDRefreshTokenType:
170+
case MSIDBoundRefreshTokenType:
169171
{
170172
if ([token isKindOfClass:[MSIDLegacyRefreshToken class]])
171173
{
@@ -485,6 +487,20 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
485487
}
486488
break;
487489
}
490+
case MSIDBoundRefreshTokenType:
491+
{
492+
MSIDBoundRefreshToken *bart = (MSIDBoundRefreshToken *) token;
493+
494+
cell.textLabel.text = [NSString stringWithFormat:@"BoundRefreshToken : %@, FamilyId : %@", bart.clientId, bart.familyId ? bart.familyId : @"0"];
495+
cell.detailTextLabel.text = [NSString stringWithFormat:@"Client_Id: %@", bart.clientId];
496+
497+
if ([bart.refreshToken isEqualToString:BAD_REFRESH_TOKEN])
498+
{
499+
cell.textLabel.textColor = [UIColor orangeColor];
500+
cell.detailTextLabel.text = [NSString stringWithFormat:@"Client_Id : %@", bart.clientId];
501+
}
502+
break;
503+
}
488504
case MSIDAccessTokenType:
489505
{
490506
MSIDAccessToken *accessToken = (MSIDAccessToken *) token;
@@ -589,6 +605,7 @@ - (UISwipeActionsConfiguration *)tableView:(__unused UITableView *)tableView tra
589605
{
590606
case MSIDFamilyRefreshTokenType:
591607
case MSIDRefreshTokenType:
608+
case MSIDBoundRefreshTokenType:
592609
{
593610
if ([token isKindOfClass:[MSIDLegacyRefreshToken class]])
594611
{

MSAL/test/app/ios/MSALTestAppSettingsViewController.m

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#import "MSIDWorkPlaceJoinUtil.h"
3535
#import "MSALPublicClientApplicationConfig.h"
3636
#import "MSALCacheConfig.h"
37+
#import "MSIDBartFeatureUtil.h"
3738

3839
static NSArray* s_profileRows = nil;
3940
static NSArray* s_deviceRows = nil;
@@ -82,6 +83,7 @@ @implementation MSALTestAppSettingsViewController
8283

8384
NSArray* _profileRows;
8485
NSArray* _deviceRows;
86+
NSArray* _bartSettingsRows;
8587
}
8688

8789
- (id)init
@@ -171,6 +173,27 @@ - (void)viewWillAppear:(BOOL)animated
171173
[MSALTestAppSettingsRow rowWithTitle:@"Device_Info - Device Id" value:^NSString *{ return aadDeviceIdentifier; }],
172174
[MSALTestAppSettingsRow rowWithTitle:@"Device_Info - Tenant Id" value:^NSString *{ return tenantIdentifier; }]];
173175

176+
MSALTestAppSettingsRow* toggleRow = [MSALTestAppSettingsRow rowWithTitle:@"Request bound app refresh tokens?"];
177+
toggleRow.valueBlock = ^NSString *{
178+
// You can replace this with actual toggle state logic
179+
BOOL isEnabled = [[MSIDBartFeatureUtil sharedInstance] isBartFeatureEnabled];
180+
return isEnabled ? @"YES" : @"NO";
181+
};
182+
__weak typeof(self) weakSelf = self;
183+
toggleRow.action = ^{
184+
typeof(self) strongSelf = weakSelf;
185+
if (!strongSelf) return;
186+
187+
// Toggle the setting
188+
BOOL currentState = [[MSIDBartFeatureUtil sharedInstance] isBartFeatureEnabled];
189+
[[MSIDBartFeatureUtil sharedInstance] setBartSupportInAppCache:!currentState];
190+
[strongSelf->_tableView reloadData];
191+
};
192+
193+
_bartSettingsRows = @[
194+
toggleRow
195+
];
196+
174197
self.navigationController.navigationBarHidden = YES;
175198

176199
[_tableView reloadData];
@@ -184,14 +207,16 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
184207
return _profileRows.count;
185208
if (section == 1)
186209
return _deviceRows.count;
210+
if (section == 2)
211+
return _bartSettingsRows.count;
187212

188213
return 0;
189214
}
190215

191216
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
192217
{
193218
(void)tableView;
194-
return 2;
219+
return 3;
195220
}
196221

197222
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
@@ -201,6 +226,8 @@ - (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSectio
201226
return @"Authentication Settings";
202227
if (section == 1)
203228
return @"Device State";
229+
if (section == 2)
230+
return @"Bound App Refresh Token Settings";
204231

205232
return nil;
206233
}
@@ -221,6 +248,11 @@ - (MSALTestAppSettingsRow*)rowForIndexPath:(NSIndexPath *)indexPath
221248
return _deviceRows[row];
222249
}
223250

251+
if (section == 2)
252+
{
253+
return _bartSettingsRows[row];
254+
}
255+
224256
return nil;
225257
}
226258

MSAL/test/app/mac/MSALCacheViewController.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#import "MSIDCacheConfig.h"
5050
#import "MSIDAssymetricKeyPair.h"
5151
#import "MSIDAuthScheme.h"
52+
#import "MSIDBoundRefreshToken.h"
5253

5354
static NSString *s_appMetadata = @"App-Metadata";
5455
static NSString *s_badRefreshToken = @"Bad-Refresh-Token";
@@ -237,6 +238,7 @@ - (void)deleteToken:(MSIDBaseToken *)token
237238
{
238239
case MSIDFamilyRefreshTokenType:
239240
case MSIDRefreshTokenType:
241+
case MSIDBoundRefreshTokenType:
240242
{
241243
[self.defaultAccessor validateAndRemoveRefreshToken:(MSIDRefreshToken *)token
242244
context:nil
@@ -367,6 +369,20 @@ - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTable
367369
MSIDBaseToken *token = (MSIDBaseToken *)item;
368370
switch (token.credentialType)
369371
{
372+
case MSIDBoundRefreshTokenType:
373+
{
374+
MSIDBoundRefreshToken *bart = (MSIDBoundRefreshToken *)token;
375+
textValue = [NSString stringWithFormat:@"Bound Refresh Token: ClientId - %@, Realm - %@, FamilyId - %@", bart.clientId, bart.realm, bart.familyId];
376+
377+
if ([bart.refreshToken isEqualToString:s_badRefreshToken])
378+
{
379+
cellView.textField.textColor = [NSColor redColor];
380+
[cellView.textField setStringValue:textValue];
381+
return cellView;
382+
}
383+
384+
break;
385+
}
370386
case MSIDFamilyRefreshTokenType:
371387
{
372388
MSIDFamilyRefreshToken *familyRefreshToken = (MSIDFamilyRefreshToken *)token;

0 commit comments

Comments
 (0)