Skip to content

Take home account from request, if not available elsewhere.#5657

Open
yowl wants to merge 3 commits into
AzureAD:mainfrom
yowl:ping-identity-home-account-refresh
Open

Take home account from request, if not available elsewhere.#5657
yowl wants to merge 3 commits into
AzureAD:mainfrom
yowl:ping-identity-home-account-refresh

Conversation

@yowl
Copy link
Copy Markdown

@yowl yowl commented Jan 14, 2026

Fixes #5618

Changes proposed in this request
When refreshing a token, PingIdentity does not return the home account. This change takes the home account from the request if existing places do not supply it.

Testing
Added a test for the TokenCache for the PingIdentity scenario I face.

Performance impact
None done, minor impact of and extra ?? when there is no ID/client_info returned.

Documentation
This is a PR to fix an issue with the experimental feature of using an OIDC that is not Azure, namely PingIdentity. When getting a refresh token, the client_info is not returned, and nor is a new identity token. I believe that according to the spec these are optional so seems a valid scenario. In this case to get the right cache key the home account is taken from the request. If that is not present we will be back to a NRE again, but at least for PingIdentity we seem to be able to refresh tokens.

First PR here, so hopefully this is at least food for thought, if it is not the right approach.

Thanks for looking.

@yowl yowl requested a review from a team as a code owner January 14, 2026 21:58
Comment thread src/client/Microsoft.Identity.Client/TokenResponseHelper.cs Outdated
@bgavrilMS bgavrilMS force-pushed the ping-identity-home-account-refresh branch from 8dbdc68 to eac383b Compare January 27, 2026 18:19
@bgavrilMS bgavrilMS enabled auto-merge (squash) March 16, 2026 22:36
Copilot AI review requested due to automatic review settings May 22, 2026 13:43
@bgavrilMS bgavrilMS force-pushed the ping-identity-home-account-refresh branch from 277e75e to e8991f3 Compare May 22, 2026 13:43
Copy link
Copy Markdown
Contributor

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 addresses a token refresh caching failure for generic OIDC providers (e.g., PingIdentity) that omit client_info and may omit id_token on refresh responses, by sourcing the home account id from the original request when needed.

Changes:

  • Extend home account id derivation to fall back to requestParams.Account.HomeAccountId.Identifier when client_info and id_token are not available.
  • Add a unit test covering a refresh-style token response with missing client_info/id_token to ensure tokens can still be cached and updated.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/client/Microsoft.Identity.Client/TokenResponseHelper.cs Adds a fallback source for homeAccountId when refresh responses omit client_info/id_token.
tests/Microsoft.Identity.Test.Unit/CacheTests/TokenCacheTests.cs Adds a unit test reproducing the PingIdentity refresh response shape (missing client_info/id_token).
Comments suppressed due to low confidence (1)

src/client/Microsoft.Identity.Client/TokenResponseHelper.cs:54

  • GetHomeAccountId still returns null when client_info, id_token, and requestParams.Account are missing. TokenCache.SaveTokenResponseAsync uses this value to build cache partition keys (e.g., InMemoryPartitionedUserTokenCacheAccessor.SaveAccessToken), which will throw ArgumentNullException later. Consider failing fast here (e.g., throw a MsalClientException with a clear message) instead of only logging and returning null.
            string homeAccountId = clientInfo?.ToAccountIdentifier() ?? idToken?.Subject ?? requestParams.Account?.HomeAccountId?.Identifier; // ADFS does not have client info, so we use subject

            if (homeAccountId == null)
            {
                requestParams.RequestContext.Logger.Info("Cannot determine home account ID - or id token or no client info and no subject ");

Comment on lines +1088 to +1091
[TestMethod]
[TestCategory(TestCategories.TokenCacheTests)]
public async Task SaveAccessAndRefreshTokenWithNoClientInfoAsync()
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] ArgumentNullException when attempting to obtain a refresh token with Ping Identity.

5 participants