Skip to content

Commit dd25fe3

Browse files
authored
Merge pull request #794 from AzureAD/hotfix/1.0.4
Release MSAL 1.0.4
2 parents 217bfa5 + 7f08ed7 commit dd25fe3

16 files changed

+214
-34
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/MSALAccount+Internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
@property (nonatomic) MSALAccountId *homeAccountId;
4343
@property (nonatomic) NSString *username;
4444
@property (nonatomic) NSString *environment;
45-
@property (nonatomic) NSMutableArray<MSALTenantProfile *> *mTenantProfiles;
45+
@property (nonatomic) NSMutableDictionary<NSString *, MSALTenantProfile *> *mTenantProfiles;
4646
@property (nonatomic) NSDictionary<NSString *, NSString *> *accountClaims;
4747
@property (nonatomic) NSString *identifier;
4848
@property (nonatomic) MSIDAccountIdentifier *lookupAccountIdentifier;

MSAL/src/MSALAccount.m

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ - (instancetype)initWithUsername:(NSString *)username
6161
_identifier = homeAccountId.identifier;
6262
_lookupAccountIdentifier = [[MSIDAccountIdentifier alloc] initWithDisplayableId:username homeAccountId:homeAccountId.identifier];
6363

64-
if (tenantProfiles.count > 0)
65-
{
66-
self.mTenantProfiles = [[NSMutableArray alloc] initWithArray:tenantProfiles];
67-
}
64+
[self addTenantProfiles:tenantProfiles];
6865
}
6966

7067
return self;
@@ -80,7 +77,7 @@ - (instancetype)initWithMSIDAccount:(MSIDAccount *)account
8077

8178
MSALTenantProfile *tenantProfile = [[MSALTenantProfile alloc] initWithIdentifier:account.localAccountId
8279
tenantId:account.realm
83-
environment:account.environment
80+
environment:account.storageEnvironment ?: account.environment
8481
isHomeTenantProfile:account.isHomeTenantAccount
8582
claims:allClaims];
8683
if (tenantProfile)
@@ -95,7 +92,7 @@ - (instancetype)initWithMSIDAccount:(MSIDAccount *)account
9592

9693
return [self initWithUsername:account.username
9794
homeAccountId:homeAccountId
98-
environment:account.environment
95+
environment:account.storageEnvironment ?: account.environment
9996
tenantProfiles:tenantProfiles];
10097
}
10198

@@ -135,7 +132,7 @@ - (instancetype)copyWithZone:(NSZone *)zone
135132
NSString *username = [self.username copyWithZone:zone];
136133
MSALAccountId *homeAccountId = [self.homeAccountId copyWithZone:zone];
137134
NSString *environment = [self.environment copyWithZone:zone];
138-
NSArray *tenantProfiles = [[NSMutableArray alloc] initWithArray:self.mTenantProfiles copyItems:YES];
135+
NSArray *tenantProfiles = [[NSMutableArray alloc] initWithArray:[self tenantProfiles] copyItems:YES];
139136

140137
MSALAccount *account = [[MSALAccount allocWithZone:zone] initWithUsername:username homeAccountId:homeAccountId environment:environment tenantProfiles:tenantProfiles];
141138
account.accountClaims = [self.accountClaims copyWithZone:zone];
@@ -162,8 +159,6 @@ - (BOOL)isEqual:(id)object
162159
- (NSUInteger)hash
163160
{
164161
NSUInteger hash = 0;
165-
hash = hash * 31 + self.username.hash;
166-
hash = hash * 31 + self.homeAccountId.hash;
167162
hash = hash * 31 + self.environment.hash;
168163
return hash;
169164
}
@@ -173,8 +168,16 @@ - (BOOL)isEqualToAccount:(MSALAccount *)user
173168
if (!user) return NO;
174169

175170
BOOL result = YES;
176-
result &= (!self.username && !user.username) || [self.username isEqualToString:user.username];
177-
result &= (!self.homeAccountId && !user.homeAccountId) || [self.homeAccountId.identifier isEqualToString:user.homeAccountId.identifier];
171+
172+
if (self.homeAccountId.identifier && user.homeAccountId.identifier)
173+
{
174+
result &= [self.homeAccountId.identifier isEqualToString:user.homeAccountId.identifier];
175+
}
176+
else if (self.username || user.username)
177+
{
178+
result &= [self.username.lowercaseString isEqualToString:user.username.lowercaseString];
179+
}
180+
178181
result &= (!self.environment && !user.environment) || [self.environment isEqualToString:user.environment];
179182
return result;
180183
}
@@ -183,20 +186,24 @@ - (BOOL)isEqualToAccount:(MSALAccount *)user
183186

184187
- (NSArray<MSALTenantProfile *> *)tenantProfiles
185188
{
186-
return self.mTenantProfiles;
189+
return self.mTenantProfiles.allValues;
187190
}
188191

189192
- (void)addTenantProfiles:(NSArray<MSALTenantProfile *> *)tenantProfiles
190193
{
191194
if (tenantProfiles.count <= 0) return;
192195

193-
if (self.mTenantProfiles)
196+
if (!self.mTenantProfiles)
194197
{
195-
[self.mTenantProfiles addObjectsFromArray:tenantProfiles];
198+
self.mTenantProfiles = [NSMutableDictionary new];
196199
}
197-
else
200+
201+
for (MSALTenantProfile *profile in tenantProfiles)
198202
{
199-
self.mTenantProfiles = [[NSMutableArray alloc] initWithArray:tenantProfiles];
203+
if (profile.tenantId && !self.mTenantProfiles[profile.tenantId])
204+
{
205+
self.mTenantProfiles[profile.tenantId] = profile;
206+
}
200207
}
201208
}
202209

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: 18 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);
@@ -97,6 +95,20 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)jsonDictionary error:(NSE
9795
{
9896
_identifier = [MSIDAccountIdentifier homeAccountIdentifierFromUid:_objectId utid:_tenantId];
9997
}
98+
else
99+
{
100+
NSDictionary *additionalPropertiesDictionary = [jsonDictionary msidObjectForKey:@"additionalProperties" ofClass:[NSDictionary class]];
101+
102+
if (additionalPropertiesDictionary)
103+
{
104+
NSString *homeAccountId = [additionalPropertiesDictionary msidObjectForKey:@"home_account_id" ofClass:[NSString class]];
105+
106+
if (![NSString msidIsStringNilOrBlank:homeAccountId])
107+
{
108+
_identifier = homeAccountId;
109+
}
110+
}
111+
}
100112

101113
NSMutableDictionary *claims = [NSMutableDictionary new];
102114

@@ -134,17 +146,17 @@ - (BOOL)matchesParameters:(MSALAccountEnumerationParameters *)parameters
134146

135147
if (parameters.identifier)
136148
{
137-
matchResult &= ([self.identifier caseInsensitiveCompare:parameters.identifier] == NSOrderedSame);
149+
matchResult &= (self.identifier && [self.identifier caseInsensitiveCompare:parameters.identifier] == NSOrderedSame);
138150
}
139151

140152
if (parameters.username)
141153
{
142-
matchResult &= ([self.username caseInsensitiveCompare:parameters.username] == NSOrderedSame);
154+
matchResult &= (self.username && [self.username caseInsensitiveCompare:parameters.username] == NSOrderedSame);
143155
}
144156

145157
if (parameters.tenantProfileIdentifier)
146158
{
147-
matchResult &= ([self.objectId caseInsensitiveCompare:parameters.tenantProfileIdentifier] == NSOrderedSame);
159+
matchResult &= (self.objectId && [self.objectId caseInsensitiveCompare:parameters.tenantProfileIdentifier] == NSOrderedSame);
148160
}
149161

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

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ - (instancetype)initWithMSALAccount:(id<MSALAccount>)account
104104

105105
jsonDictionary[@"signInStatus"] = @{appBundleId : @"SignedIn"};
106106
jsonDictionary[@"username"] = account.username;
107-
jsonDictionary[@"additionalProperties"] = @{@"createdBy": appName};
107+
108+
NSMutableDictionary *additionalProperties = [NSMutableDictionary new];
109+
[additionalProperties addEntriesFromDictionary:@{@"createdBy": appName}];
110+
[additionalProperties addEntriesFromDictionary:[self additionalPropertiesFromMSALAccount:account claims:claims]];
111+
jsonDictionary[@"additionalProperties"] = additionalProperties;
108112
[jsonDictionary addEntriesFromDictionary:[self claimsFromMSALAccount:account claims:claims]];
109113
return [self initWithJSONDictionary:jsonDictionary error:error];
110114
}
@@ -118,6 +122,7 @@ - (BOOL)matchesParameters:(MSALAccountEnumerationParameters *)parameters
118122
NSString *appIdentifier = [[NSBundle mainBundle] bundleIdentifier];
119123
NSString *signinStatus = [self.signinStatusDictionary msidStringObjectForKey:appIdentifier];
120124

125+
MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, nil, @"Requested to only returned signed in accounts. Current sign in status for the app is %@", signinStatus);
121126
return [signinStatus isEqualToString:@"SignedIn"];
122127
}
123128
else if (![self.signinStatusDictionary count])
@@ -179,6 +184,7 @@ - (BOOL)updateAccountWithMSALAccount:(id<MSALAccount>)account
179184

180185
mutableAdditionalInfo[@"updatedBy"] = appName;
181186
mutableAdditionalInfo[@"updatedAt"] = [[[self class] dateFormatter] stringFromDate:[NSDate date]];
187+
[mutableAdditionalInfo addEntriesFromDictionary:[self additionalPropertiesFromMSALAccount:account claims:nil]];
182188

183189
oldDictionary[@"additionalProperties"] = mutableAdditionalInfo;
184190

@@ -197,6 +203,16 @@ - (NSDictionary *)claimsFromMSALAccount:(id<MSALAccount>)account claims:(NSDicti
197203
return nil;
198204
}
199205

206+
- (NSDictionary *)additionalPropertiesFromMSALAccount:(id<MSALAccount>)account claims:(NSDictionary *)claims
207+
{
208+
if (account.identifier)
209+
{
210+
return @{@"home_account_id": account.identifier};
211+
}
212+
213+
return nil;
214+
}
215+
200216
#pragma mark - Helpers
201217

202218
+ (NSDateFormatter *)dateFormatter

0 commit comments

Comments
 (0)