Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(prod) Fix for account id missing in msal get account #1558

Merged
merged 7 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion changelog
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ MSAL Wiki : https://github.com/AzureAD/microsoft-authentication-library-for-andr
Version 2.2.3
----------
- Remove the broker check for MSA FRT saving function (#1571)
- Picks up common@3.6.6
- Fix msal get account crash in Account Matcher due to NPE because account id was missing (#1558)
- Picks up common@3.6.7

Version 2.2.2
----------
Expand Down
4 changes: 2 additions & 2 deletions msal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ dependencies {
transitive = false
}

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

distApi("com.microsoft.identity:common:3.6.6") {
distApi("com.microsoft.identity:common:3.6.7") {
transitive = false
}
}
Expand Down
24 changes: 24 additions & 0 deletions msal/src/main/java/com/microsoft/identity/client/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.microsoft.identity.common.internal.providers.microsoft.MicrosoftIdToken;
import com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryIdToken;
import com.microsoft.identity.common.internal.providers.oauth2.IDToken;
import com.microsoft.identity.common.internal.util.AccountUtil;
import com.microsoft.identity.common.internal.util.StringUtil;

import java.util.Map;
Expand All @@ -47,6 +48,7 @@ public class Account implements IAccount {
private String mHomeOid;
private String mHomeTenantId;
private String mEnvironment;
private String mHomeAccountId;

public Account(
@Nullable final String clientInfo,
Expand All @@ -69,6 +71,7 @@ void setId(@Nullable final String id) {
@NonNull
@Override
public String getId() {
final String methodName = ":getId";
String id;

ClientInfo clientInfo = null;
Expand All @@ -93,6 +96,23 @@ public String getId() {
id = mHomeOid;
}

if (StringUtil.isEmpty(id)) {
com.microsoft.identity.common.logging.Logger.warn(
TAG + methodName,
"Unable to get account id from either ClientInfo or IdToken. Attempting to obtain from home account id."
);
id = AccountUtil.getUIdFromHomeAccountId(mHomeAccountId);
}

if (StringUtil.isEmpty(id)) {
com.microsoft.identity.common.logging.Logger.warn(
shahzaibj marked this conversation as resolved.
Show resolved Hide resolved
TAG + methodName,
"Account ID is empty. Returning MISSING_FROM_THE_TOKEN_RESPONSE."
);

id = MISSING_FROM_THE_TOKEN_RESPONSE;
}

return id;
}

Expand Down Expand Up @@ -162,4 +182,8 @@ public String getAuthority() {

return MISSING_FROM_THE_TOKEN_RESPONSE;
}

public void setHomeAccountId(@NonNull final String homeAccountId) {
mHomeAccountId = homeAccountId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ private static List<IAccount> createRootAccounts(
getIdToken(homeCacheRecord)
);

((MultiTenantAccount) rootAccount).setHomeAccountId(homeCacheRecord.getAccount().getHomeAccountId());

// Set the tenant_id
((MultiTenantAccount) rootAccount).setTenantId(
StringUtil.getTenantInfo(
Expand Down
2 changes: 1 addition & 1 deletion msal/versioning/version.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Wed Aug 01 15:24:11 PDT 2018
versionName=2.2.3
versionName=2.2.3-RC1
versionCode=0