Skip to content

Conversation

@Avery-Dunn
Copy link
Contributor

The first commit in this PR refactors the logic for determining when a refresh should be performed, since it had gotten complex as different scenarios and edge cases were introduced over the years. That refactor should not affect the existing refresh behavior.

The second commit adds the existence of the claims parameter as reason to refresh, as per #794. With this change app developers will no longer need to explicitly use the forceRefresh() API when dealing with tokens that have claims/client capabilities/etc.

@Avery-Dunn Avery-Dunn requested a review from a team as a code owner April 16, 2024 16:36
Copy link
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

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

Missing unit tests is primary concern.

@Avery-Dunn Avery-Dunn requested a review from bgavrilMS May 5, 2024 23:06
Copy link
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

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

More test coverage (unit test) needed.

User user = labUserProvider.getDefaultUser(AzureEnvironment.AZURE);

Set<String> scopes = new HashSet<>();
PublicClientApplication pca = PublicClientApplication.builder(
Copy link
Member

Choose a reason for hiding this comment

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

I think unit tests should cover this not integration tests. Integration tests are expensive. There is no integration point that is worth testing unless you pass in some well-known claims and can assert the result.

Unit tests should cover:

  • cca.AcquireTokenSilent
  • cca.AcquireTokenForClient
  • pca.AcquireTokenSilent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the latest commit I added extra tests using some dummy cache data, to show that a token is returned when using the AcquireTokenSilent API without claims and not returned when claims are added to the request.

I did not add a specific test for the implicit silent call in the 'cca.AcquireTokenForClient' scenario, because internally it reaches the exact same code as the explicit AcquireTokenSilent call and that behavior is covered by other tests.

@bgavrilMS
Copy link
Member

Any updates on this @Avery-Dunn ?

assertNotNull(result);
assertEquals("token", result.accessToken());

ClaimsRequest cr = new ClaimsRequest();
Copy link
Member

@bgavrilMS bgavrilMS Aug 15, 2024

Choose a reason for hiding this comment

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

This is not good API experience ( I know it exists already).

Is there an overload where the claims are injected as a string? After all, this is what the app developers will use.|

Later edit: can we pls deprecate Claims|Request and associated APIs? And just keep claims(string) ?"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For simplicity I'm not deprecating in this PR/release, but I created this task to get it deprecated in the next one: #855

InteractiveRequestParameters parameters = InteractiveRequestParameters.builder(new URI("http://localhost:8080"))
.claimsChallenge("{\"id_token\":{\"auth_time\":{\"essential\":true}},\"access_token\":{\"auth_time\":{\"essential\":true},\"xms_cc\":{\"values\":[\"abc\"]}}}")
.claimsChallenge(TestConfiguration.CLAIMS_CHALLENGE)
.claims(cr)
Copy link
Member

Choose a reason for hiding this comment

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

Why both claims and claims channelge?

Can we deprecate this claims and ClaimsRequest object model?

Copy link
Contributor Author

@Avery-Dunn Avery-Dunn Aug 23, 2024

Choose a reason for hiding this comment

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

For simplicity I'm not deprecating in this PR/release, but I created this task to get it deprecated in the next one: #855

Copy link
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

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

Unsure about claims(string) and claimsrequest(CR) - propose to deprecate strongly typed model and it is inconsistent with other MSALs.

@Avery-Dunn Avery-Dunn deleted the avdunn/claims-refresh-fix branch January 21, 2025 21:13
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.

3 participants