Skip to content

[JSDK-36] Access token cache#83

Merged
tl-andrea-dilisio merged 28 commits intomainfrom
jsdk-36
Mar 14, 2022
Merged

[JSDK-36] Access token cache#83
tl-andrea-dilisio merged 28 commits intomainfrom
jsdk-36

Conversation

@tl-andrea-dilisio
Copy link
Contributor

@tl-andrea-dilisio tl-andrea-dilisio commented Mar 9, 2022

Inspired by this article.

I'm combining both an interceptor and an authenticator to handle token caching and refreshes on 401 events.


private final Clock clock;

public SimpleAccessTokenCache(Clock clock) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the Clock param makes testing easier.

Please note that this is not a monotonic implementation. But in the end I think it's fine

AccessToken accessToken = new AccessToken(
UUID.randomUUID().toString(),
RandomUtils.nextInt(),
3600,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to mimic reality more and ease the testing phase


@BeforeAll
public static void setup(WireMockRuntimeInfo wireMockRuntimeInfo) {
@BeforeEach
Copy link
Contributor Author

@tl-andrea-dilisio tl-andrea-dilisio Mar 10, 2022

Choose a reason for hiding this comment

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

Even if not a problem in past, this should have been done probably already as this guarantees tha each integration test is stateless. It now becomes a requirement, so that we can test cache properly

@@ -0,0 +1,6 @@
{
"access_token": "eyJ***immediate",
"expires_in": 1,
Copy link
Contributor Author

@tl-andrea-dilisio tl-andrea-dilisio Mar 10, 2022

Choose a reason for hiding this comment

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

this is to ease integration tests

@tl-andrea-dilisio tl-andrea-dilisio marked this pull request as ready for review March 10, 2022 23:33
@tl-andrea-dilisio tl-andrea-dilisio requested a review from a team March 10, 2022 23:33
@tl-andrea-dilisio tl-andrea-dilisio added the enhancement New feature or request label Mar 11, 2022
@tl-luca-baggi
Copy link
Contributor

LGTM

@tl-andrea-dilisio tl-andrea-dilisio merged commit 4a01d9c into main Mar 14, 2022
@tl-andrea-dilisio tl-andrea-dilisio deleted the jsdk-36 branch March 14, 2022 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

3 participants