Skip to content

Update AccountInfo construction to include tenant-specific claims #7949

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

Merged
merged 19 commits into from
Aug 4, 2025

Conversation

hectormmg
Copy link
Member

@hectormmg hectormmg commented Jul 28, 2025

This PR:

  • Updates username AccountInfo property to be tenant-profile sensitive. Any AccountInfo object returned will now reflect the preferred_username of the tenant profile it represents instead of keeping the home tenant username computed value.
  • Promotes loginHint to an AccountInfo property so client applications can directly reference it in the account instead of through account.idTokenClaims.login_hint.

@Copilot Copilot AI review requested due to automatic review settings July 28, 2025 19:35
@github-actions github-actions bot added documentation Related to documentation. msal-node Related to msal-node package msal-browser Related to msal-browser package msal-common Related to msal-common package labels Jul 28, 2025
Copilot

This comment was marked as outdated.

@hectormmg hectormmg requested a review from Copilot July 30, 2025 17:11
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates AccountInfo construction to be tenant-profile sensitive by adding a loginHint property and making the username property reflect tenant-specific values rather than home tenant values.

  • Adds loginHint as a direct property on AccountInfo objects, promoting it from being accessed through idTokenClaims
  • Updates username to be tenant-profile specific, reflecting the preferred_username of the tenant profile
  • Updates TenantProfile type to include username and loginHint properties

Reviewed Changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/msal-common/src/account/AccountInfo.ts Adds loginHint property to AccountInfo type and updates TenantProfile to include username and loginHint
lib/msal-common/src/cache/entities/AccountEntity.ts Updates AccountEntity to store and handle loginHint property
lib/msal-common/src/protocol/Authorize.ts Updates login hint extraction to check account property first before falling back to token claims
lib/msal-browser/src/naa/AccountInfo.ts Adds loginHint property to NAA-specific AccountInfo type
lib/msal-browser/src/naa/mapping/NestedAppAuthAdapter.ts Updates adapter to include loginHint when constructing account info
Test files Updates test constants and mocks to include loginHint property in account objects
API review files Updates API definitions to reflect new loginHint property
Change files Adds changelog entries for the feature across packages

tenantId: "3338040d-6c67-4c5b-b112-36a304b66dad",
username: "AbeLi@microsoft.com",
};
const testAccount = BASIC_TEST_ACCOUNT_INFO;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great bit of refactoring/cleanup here. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly if I had more time I'd dig in and refactor test account creation with the level of simplicity I did for multi-tenant support. I think we should standardize the way we set up our tests so it's more maintainable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Account Info should be generated from a proper test ID token basically.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try asking copilot to do it for you.

peterzenz
peterzenz previously approved these changes Jul 31, 2025
isHomeTenant: tenantIdMatchesHomeTenant(tenantId, homeAccountId),
};
} else {
return {
tenantId,
localAccountId,
username: "",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious, when do we expect to be building a TenantProfile without any idTokenClaims? Isn't an idToken a pre-requisite?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't expect this code will be reached. This is a side-effect of the calling pattern, idTokenClaims are optional because of how the ResponseHandler checks for an ID token in the server response. I do think our flow will build an account as long as client_info is included in the response, which is why it doesn't fail when the server response doesn't include ID token

tnorling
tnorling previously approved these changes Aug 1, 2025
Copy link
Collaborator

@tnorling tnorling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to update any docs to reflect the changes making login_hint available on AccountInfo?

Co-authored-by: Thomas Norling <thomas.norling@microsoft.com>
@hectormmg hectormmg dismissed stale reviews from tnorling and peterzenz via 05e72a8 August 2, 2025 18:51
@hectormmg
Copy link
Member Author

Do we need to update any docs to reflect the changes making login_hint available on AccountInfo?

Added a few doc updates @tnorling

@hectormmg hectormmg requested review from tnorling and peterzenz August 2, 2025 19:16
@hectormmg hectormmg enabled auto-merge (squash) August 2, 2025 19:22
- As the account object's `upn` ID token claim (not recommended)

> [!NOTE]
> The `username` and `upn` properties are partially supported in place of the actual `login_hint` claim, but they are not recommended. Please use the `loginHint` or `idTokenClaims.login_hint` account properties if they are available.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we call out that login_hint is an optional claim that the app has to opt-in to? We should be really clear that we want folks to go enable this and use it in their application.

@hectormmg hectormmg merged commit bd49c2d into dev Aug 4, 2025
8 checks passed
@hectormmg hectormmg deleted the update-account-claims branch August 4, 2025 18:52
hectormmg added a commit that referenced this pull request Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Related to documentation. msal-browser Related to msal-browser package msal-common Related to msal-common package msal-node Related to msal-node package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants