Skip to content

Commit 8576bc8

Browse files
authored
Merge pull request #787 from AzureAD/oldalton/fix_external_account_matching
Fix external account matching when account doesn't have an identifier
2 parents 217bfa5 + c8ef969 commit 8576bc8

File tree

11 files changed

+69
-13
lines changed

11 files changed

+69
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [1.0.4] - 2019-11-26
2+
### Fixed
3+
- Fixed external account matching when identifier is not present (#787)
4+
15
## [1.0.3] - 2019-11-15
26
### Added
37
- Added default implementation for ADAL legacy persistence

MSAL.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "MSAL"
3-
s.version = "1.0.3"
3+
s.version = "1.0.4"
44
s.summary = "Microsoft Authentication Library (MSAL) Preview for iOS"
55

66
s.description = <<-DESC

MSAL/resources/ios/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0.3</string>
18+
<string>1.0.4</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

MSAL/resources/mac/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0.3</string>
18+
<string>1.0.4</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSHumanReadableCopyright</key>

MSAL/src/MSALPublicClientApplication.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ - (MSALAccount *)accountForHomeAccountId:(NSString *)homeAccountId
357357
- (MSALAccount *)accountForIdentifier:(NSString *)identifier
358358
error:(NSError **)error
359359
{
360+
MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, nil, @"Querying MSAL account for identifier %@", MSID_PII_LOG_TRACKABLE(identifier));
361+
360362
MSALAccountsProvider *request = [[MSALAccountsProvider alloc] initWithTokenCache:self.tokenCache
361363
clientId:self.internalConfig.clientId
362364
externalAccountProvider:self.externalAccountHandler];
@@ -368,12 +370,16 @@ - (MSALAccount *)accountForIdentifier:(NSString *)identifier
368370

369371
if (error) *error = [MSALErrorConverter msalErrorFromMsidError:msidError];
370372

373+
MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, nil, @"Found MSAL account with identifier %@, username %@", MSID_PII_LOG_TRACKABLE(account.identifier), MSID_PII_LOG_EMAIL(account.username));
374+
371375
return account;
372376
}
373377

374378
- (NSArray<MSALAccount *> *)accountsForParameters:(MSALAccountEnumerationParameters *)parameters
375379
error:(NSError **)error
376380
{
381+
MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, nil, @"Querying MSAL accounts with parameters (identifier=%@, tenantProfileId=%@, username=%@, return only signed in accounts %d)", MSID_PII_LOG_MASKABLE(parameters.identifier), MSID_PII_LOG_MASKABLE(parameters.tenantProfileIdentifier), MSID_PII_LOG_EMAIL(parameters.username), parameters.returnOnlySignedInAccounts);
382+
377383
MSALAccountsProvider *request = [[MSALAccountsProvider alloc] initWithTokenCache:self.tokenCache
378384
clientId:self.internalConfig.clientId
379385
externalAccountProvider:self.externalAccountHandler];
@@ -382,12 +388,16 @@ - (MSALAccount *)accountForIdentifier:(NSString *)identifier
382388

383389
if (error) *error = [MSALErrorConverter msalErrorFromMsidError:msidError];
384390

391+
MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, nil, @"Found MSAL accounts with count %ld", (long)accounts.count);
392+
385393
return accounts;
386394
}
387395

388396
- (MSALAccount *)accountForUsername:(NSString *)username
389397
error:(NSError * __autoreleasing *)error
390398
{
399+
MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, nil, @"Querying MSAL account for username %@", MSID_PII_LOG_EMAIL(username));
400+
391401
MSALAccountsProvider *request = [[MSALAccountsProvider alloc] initWithTokenCache:self.tokenCache
392402
clientId:self.internalConfig.clientId
393403
externalAccountProvider:self.externalAccountHandler];
@@ -396,6 +406,8 @@ - (MSALAccount *)accountForUsername:(NSString *)username
396406
MSALAccount *account = [request accountForParameters:parameters error:&msidError];
397407

398408
if (error) *error = [MSALErrorConverter msalErrorFromMsidError:msidError];
409+
410+
MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, nil, @"Found MSAL account with identifier %@, username %@", MSID_PII_LOG_TRACKABLE(account.identifier), MSID_PII_LOG_EMAIL(account.username));
399411

400412
return account;
401413
}

MSAL/src/MSAL_Internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#define MSAL_VER_HIGH 1
2929
#define MSAL_VER_LOW 0
30-
#define MSAL_VER_PATCH 3
30+
#define MSAL_VER_PATCH 4
3131

3232
#define STR_HELPER(x) #x
3333
#define STR(x) STR_HELPER(x)

MSAL/src/configuration/external/ios/MSALLegacySharedADALAccount.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)jsonDictionary error:(NSE
5151
self = [super initWithJSONDictionary:jsonDictionary error:error];
5252

5353
if (self)
54-
{
55-
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, nil, @"Creating external account from ADAL account");
56-
54+
{
5755
if (![_accountType isEqualToString:kADALAccountType])
5856
{
5957
MSID_LOG_WITH_CTX(MSIDLogLevelError, nil, @"Failed to create ADAL account. Wrong account type %@ provided", _accountType);
@@ -134,17 +132,17 @@ - (BOOL)matchesParameters:(MSALAccountEnumerationParameters *)parameters
134132

135133
if (parameters.identifier)
136134
{
137-
matchResult &= ([self.identifier caseInsensitiveCompare:parameters.identifier] == NSOrderedSame);
135+
matchResult &= (self.identifier && [self.identifier caseInsensitiveCompare:parameters.identifier] == NSOrderedSame);
138136
}
139137

140138
if (parameters.username)
141139
{
142-
matchResult &= ([self.username caseInsensitiveCompare:parameters.username] == NSOrderedSame);
140+
matchResult &= (self.username && [self.username caseInsensitiveCompare:parameters.username] == NSOrderedSame);
143141
}
144142

145143
if (parameters.tenantProfileIdentifier)
146144
{
147-
matchResult &= ([self.objectId caseInsensitiveCompare:parameters.tenantProfileIdentifier] == NSOrderedSame);
145+
matchResult &= (self.objectId && [self.objectId caseInsensitiveCompare:parameters.tenantProfileIdentifier] == NSOrderedSame);
148146
}
149147

150148
return matchResult &= [super matchesParameters:parameters];

MSAL/src/configuration/external/ios/MSALLegacySharedAccount.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ - (BOOL)matchesParameters:(MSALAccountEnumerationParameters *)parameters
118118
NSString *appIdentifier = [[NSBundle mainBundle] bundleIdentifier];
119119
NSString *signinStatus = [self.signinStatusDictionary msidStringObjectForKey:appIdentifier];
120120

121+
MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, nil, @"Requested to only returned signed in accounts. Current sign in status for the app is %@", signinStatus);
121122
return [signinStatus isEqualToString:@"SignedIn"];
122123
}
123124
else if (![self.signinStatusDictionary count])

MSAL/src/configuration/external/ios/MSALLegacySharedAccountsProvider.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ - (instancetype)initWithSharedKeychainAccessGroup:(NSString *)sharedGroup
9090
- (nullable NSArray<id<MSALAccount>> *)accountsWithParametersImpl:(MSALAccountEnumerationParameters *)parameters
9191
error:(NSError * _Nullable * _Nullable)error
9292
{
93-
MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, nil, @"Reading accounts with parameters %@", MSID_PII_LOG_MASKABLE(parameters));
93+
MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, nil, @"Reading accounts with parameters (identifier=%@, tenantProfileId=%@, username=%@, return only signed in accounts %d)", MSID_PII_LOG_MASKABLE(parameters.identifier), MSID_PII_LOG_MASKABLE(parameters.tenantProfileIdentifier), MSID_PII_LOG_EMAIL(parameters.username), parameters.returnOnlySignedInAccounts);
9494

9595
NSMutableSet *allAccounts = [NSMutableSet new];
9696
NSTimeInterval lastWrite = [[NSDate distantPast] timeIntervalSince1970];

MSAL/src/configuration/external/ios/MSALLegacySharedMSAAccount.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ - (BOOL)matchesParameters:(MSALAccountEnumerationParameters *)parameters
110110

111111
if (parameters.identifier)
112112
{
113-
matchResult &= ([self.identifier caseInsensitiveCompare:parameters.identifier] == NSOrderedSame);
113+
matchResult &= (self.identifier && [self.identifier caseInsensitiveCompare:parameters.identifier] == NSOrderedSame);
114114
}
115115

116116
if (parameters.username)
117117
{
118-
matchResult &= ([self.username caseInsensitiveCompare:parameters.username] == NSOrderedSame);
118+
matchResult &= (self.username && [self.username caseInsensitiveCompare:parameters.username] == NSOrderedSame);
119119
}
120120

121121
if (parameters.tenantProfileIdentifier)

0 commit comments

Comments
 (0)