Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,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()
Expand Down