Skip to content

Commit 94da54f

Browse files
committed
Seperate claims and forced refresh reasons
1 parent e312512 commit 94da54f

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AcquireTokenSilentSupplier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ private boolean shouldRefresh(SilentParameters parameters, AuthenticationResult
119119

120120
//If forceRefresh is true, no reason to check any other option
121121
if (parameters.forceRefresh()) {
122-
setCacheTelemetry(CacheRefreshReason.FORCE_REFRESH_OR_CLAIMS);
122+
setCacheTelemetry(CacheRefreshReason.FORCE_REFRESH);
123123
log.debug("Refreshing access token because forceRefresh parameter is true.");
124124
return true;
125125
}
126126

127127
//If the request contains claims then the token should be refreshed, to ensure that the returned token has the correct claims
128128
// Note: these are the types of claims found in (for example) a claims challenge, and do not include client capabilities
129129
if (parameters.claims() != null) {
130-
setCacheTelemetry(CacheRefreshReason.FORCE_REFRESH_OR_CLAIMS);
130+
setCacheTelemetry(CacheRefreshReason.CLAIMS);
131131
log.debug("Refreshing access token because the claims parameter is not null.");
132132
return true;
133133
}

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/CacheRefreshReason.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ public enum CacheRefreshReason {
1212
*/
1313
NOT_APPLICABLE(0),
1414
/**
15-
* Silent call was made with the force refresh option, or claims were set
15+
* Silent call was made with the force refresh option
1616
*/
17-
FORCE_REFRESH_OR_CLAIMS(1),
17+
FORCE_REFRESH(1),
18+
/**
19+
* Silent call was made with claims set
20+
*/
21+
CLAIMS(1),
1822
/**
1923
* Access token was missing from the cache, but a valid refresh token was used to retrieve a new access token
2024
*/

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/SilentRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SilentRequest extends MsalRequest {
3232

3333
if (parameters.forceRefresh()) {
3434
application.serviceBundle().getServerSideTelemetry().getCurrentRequest().cacheInfo(
35-
CacheRefreshReason.FORCE_REFRESH_OR_CLAIMS);
35+
CacheRefreshReason.FORCE_REFRESH);
3636
}
3737
}
3838
}

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AcquireTokenSilentlyTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,16 @@ void testTokenRefreshReasons() throws Exception {
174174
silentParameters = SilentParameters.builder(Collections.singleton("someScopes"), result.account()).forceRefresh(true).build();
175175
result = cca.acquireTokenSilently(silentParameters).get();
176176

177-
assertRefreshedToken(result, "forcedRefreshToken", CacheRefreshReason.FORCE_REFRESH_OR_CLAIMS, cca.tokenCache.accessTokens.size());
177+
assertRefreshedToken(result, "forcedRefreshToken", CacheRefreshReason.FORCE_REFRESH, cca.tokenCache.accessTokens.size());
178178

179179
//Finally, force a refresh by setting claims
180180
responseParameters.put("access_token", "claimsToken");
181181
TestHelper.createTokenRequestMock(httpClientMock, TestHelper.getSuccessfulTokenResponse(responseParameters), 200);
182182

183-
silentParameters = SilentParameters.builder(Collections.singleton("someScopes"), result.account()).claims(new ClaimsRequest()).forceRefresh(true).build();
183+
silentParameters = SilentParameters.builder(Collections.singleton("someScopes"), result.account()).claims(new ClaimsRequest()).build();
184184
result = cca.acquireTokenSilently(silentParameters).get();
185185

186-
assertRefreshedToken(result, "claimsToken", CacheRefreshReason.FORCE_REFRESH_OR_CLAIMS, cca.tokenCache.accessTokens.size());
186+
assertRefreshedToken(result, "claimsToken", CacheRefreshReason.CLAIMS, cca.tokenCache.accessTokens.size());
187187
}
188188

189189
//Asserts that there is one expected token in the cache, and that it was refreshed with the expected reason

0 commit comments

Comments
 (0)