Skip to content

Commit 393529c

Browse files
authored
Merge pull request #1558 from AzureAD/shahzaibj/msal-account-id-missing-fix
(prod) Fix for account id missing in msal get account
2 parents da690ad + 6a560ea commit 393529c

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

changelog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ MSAL Wiki : https://github.com/AzureAD/microsoft-authentication-library-for-andr
33
Version 2.2.3
44
----------
55
- Remove the broker check for MSA FRT saving function (#1571)
6-
6+
- Fix msal get account crash in Account Matcher due to NPE because account id was missing (#1558)
7+
78

89
Version 2.2.2
910
----------

msal/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ dependencies {
274274
transitive = false
275275
}
276276

277-
snapshotApi(group: 'com.microsoft.identity', name: 'common', version: '3.6.6', changing: true)
277+
snapshotApi(group: 'com.microsoft.identity', name: 'common', version: '3.6.7', changing: true)
278278

279-
distApi("com.microsoft.identity:common:3.6.6") {
279+
distApi("com.microsoft.identity:common:3.6.7") {
280280
transitive = false
281281
}
282282
}

msal/src/main/java/com/microsoft/identity/client/Account.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.microsoft.identity.common.internal.providers.microsoft.MicrosoftIdToken;
3232
import com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryIdToken;
3333
import com.microsoft.identity.common.internal.providers.oauth2.IDToken;
34+
import com.microsoft.identity.common.internal.util.AccountUtil;
3435
import com.microsoft.identity.common.internal.util.StringUtil;
3536

3637
import java.util.Map;
@@ -47,6 +48,7 @@ public class Account implements IAccount {
4748
private String mHomeOid;
4849
private String mHomeTenantId;
4950
private String mEnvironment;
51+
private String mHomeAccountId;
5052

5153
public Account(
5254
@Nullable final String clientInfo,
@@ -69,6 +71,7 @@ void setId(@Nullable final String id) {
6971
@NonNull
7072
@Override
7173
public String getId() {
74+
final String methodName = ":getId";
7275
String id;
7376

7477
ClientInfo clientInfo = null;
@@ -93,6 +96,24 @@ public String getId() {
9396
id = mHomeOid;
9497
}
9598

99+
if (StringUtil.isEmpty(id)) {
100+
com.microsoft.identity.common.logging.Logger.warn(
101+
TAG + methodName,
102+
"Unable to get account id from either ClientInfo or IdToken. Attempting to obtain from home account id."
103+
);
104+
id = AccountUtil.getUIdFromHomeAccountId(mHomeAccountId);
105+
}
106+
107+
if (StringUtil.isEmpty(id)) {
108+
com.microsoft.identity.common.logging.Logger.error(
109+
TAG + methodName,
110+
"Account ID is empty. Returning MISSING_FROM_THE_TOKEN_RESPONSE.",
111+
null
112+
);
113+
114+
id = MISSING_FROM_THE_TOKEN_RESPONSE;
115+
}
116+
96117
return id;
97118
}
98119

@@ -162,4 +183,8 @@ public String getAuthority() {
162183

163184
return MISSING_FROM_THE_TOKEN_RESPONSE;
164185
}
186+
187+
public void setHomeAccountId(@NonNull final String homeAccountId) {
188+
mHomeAccountId = homeAccountId;
189+
}
165190
}

msal/src/main/java/com/microsoft/identity/client/AccountAdapter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ private static List<IAccount> createRootAccounts(
293293
getIdToken(homeCacheRecord)
294294
);
295295

296+
((MultiTenantAccount) rootAccount).setHomeAccountId(homeCacheRecord.getAccount().getHomeAccountId());
297+
296298
// Set the tenant_id
297299
((MultiTenantAccount) rootAccount).setTenantId(
298300
StringUtil.getTenantInfo(

msal/versioning/version.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#Wed Aug 01 15:24:11 PDT 2018
2-
versionName=2.2.3
2+
versionName=2.2.3-RC1
33
versionCode=0

0 commit comments

Comments
 (0)