diff --git a/src/client/Microsoft.Identity.Client/TokenResponseHelper.cs b/src/client/Microsoft.Identity.Client/TokenResponseHelper.cs index a6ef28f368..46b9807aa5 100644 --- a/src/client/Microsoft.Identity.Client/TokenResponseHelper.cs +++ b/src/client/Microsoft.Identity.Client/TokenResponseHelper.cs @@ -47,7 +47,7 @@ public static string GetUsernameFromIdToken(IdToken idToken) public static string GetHomeAccountId(AuthenticationRequestParameters requestParams, MsalTokenResponse response, IdToken idToken) { ClientInfo clientInfo = response.ClientInfo != null ? ClientInfo.CreateFromJson(response.ClientInfo) : null; - string homeAccountId = clientInfo?.ToAccountIdentifier() ?? idToken?.Subject; // ADFS does not have client info, so we use subject + string homeAccountId = clientInfo?.ToAccountIdentifier() ?? idToken?.Subject ?? requestParams.Account?.HomeAccountId?.Identifier; // ADFS does not have client info, so we use subject if (homeAccountId == null) { diff --git a/tests/Microsoft.Identity.Test.Unit/CacheTests/TokenCacheTests.cs b/tests/Microsoft.Identity.Test.Unit/CacheTests/TokenCacheTests.cs index 63643c760b..05b088d434 100644 --- a/tests/Microsoft.Identity.Test.Unit/CacheTests/TokenCacheTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/CacheTests/TokenCacheTests.cs @@ -1085,6 +1085,38 @@ public async Task SaveAccessAndRefreshTokenWithIntersectingScopesTestAsync() Assert.AreEqual("access-token-2", (cache.Accessor.GetAllAccessTokens()).First().Secret); } + [TestMethod] + [TestCategory(TestCategories.TokenCacheTests)] + public async Task SaveAccessAndRefreshTokenWithNoClientInfoAsync() + { + var serviceBundle = TestCommon.CreateDefaultServiceBundle(); + ITokenCacheInternal cache = new TokenCache(serviceBundle, false); + MsalTokenResponse response = TestConstants.CreateMsalTokenResponse(); + + var requestParams = TestCommon.CreateAuthenticationRequestParameters(serviceBundle); + requestParams.AuthorityManager = new AuthorityManager( + requestParams.RequestContext, + Authority.CreateAuthorityWithTenant( + requestParams.AuthorityInfo, + TestConstants.Utid)); + AddHostToInstanceCache(serviceBundle, TestConstants.ProductionPrefNetworkEnvironment); + + await cache.SaveTokenResponseAsync(requestParams, response).ConfigureAwait(false); + + requestParams.Account = new Account(_homeAccountId, null, null); + response.IdToken = null; + response.ClientInfo = null; + response.AccessToken = "access-token-2"; + response.RefreshToken = "refresh-token-2"; + + await cache.SaveTokenResponseAsync(requestParams, response).ConfigureAwait(false); + + Assert.AreEqual(1, cache.Accessor.GetAllRefreshTokens().Count()); + Assert.AreEqual(1, cache.Accessor.GetAllAccessTokens().Count()); + Assert.AreEqual("refresh-token-2", (cache.Accessor.GetAllRefreshTokens()).First().Secret); + Assert.AreEqual("access-token-2", (cache.Accessor.GetAllAccessTokens()).First().Secret); + } + [TestMethod] [TestCategory(TestCategories.TokenCacheTests)] public void CacheAdfsTokenTest()