Skip to content

Customizable token cache #759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Customizable token cache #759

wants to merge 1 commit into from

Conversation

rayluo
Copy link
Collaborator

@rayluo rayluo commented Oct 21, 2024

Inspired by its cousin in MSAL .Net, this PR refactors MSAL Python's token cache to provide an INTERNAL helper which can store additional values from token request or response.

Implementation details (which are not exactly the same as MSAL .Net, but the overall purpose is the same):

  • We have to differentiate between request and response because they are two different data sources in this code base. And the use case (CDT experiment) needs both of them.
  • The same additional values are also used in token search.
  • Currently, the changes above are only applicable to access token.
  • The preexisting hard-coded key_id was also refactored this time to utilize the new generic declaration, and the existing test case was updated to reflect that.
  • This PR does not bring other behavior changes, and all the existing test cases still pass. So, it should be safe to merge.
  • Some other prototypes for recent projects will be built on top of this PR.

Customizable data and response to be saved into token cache
@rayluo rayluo requested a review from a team as a code owner October 21, 2024 19:01
@@ -238,6 +239,10 @@ class ClientApplication(object):
"You can enable broker by following these instructions. "
"https://msal-python.readthedocs.io/en/latest/#publicclientapplication")

_TOKEN_CACHE_DATA: dict[str, str] = { # field_in_data: field_in_cache

Choose a reason for hiding this comment

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

The type annotation dict[str, str] for _TOKEN_CACHE_DATA uses Python 3.9+ syntax. If you intend to support Python 3.7 or 3.8 (as implied by the import on line 9), consider using Dict[str, str] from typing for compatibility.

Choose a reason for hiding this comment

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

Consider adding a comment
# Maps field names from input data to their corresponding field names in the token cache.
# This is used to ensure that certain token types (e.g., SSH certificates, POP tokens)
# are correctly associated with their identifying keys in the cache.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @maliksahil , it has been a while, how is it going? :-)

Thanks for catching that type annotation issue. I'll take a look at why that typo was not caught by our test automation, when we revive this PR.

Why did you notice this PR in the first place? Are you working on some cutting-edge scenario that needs the behavior of this PR?

Choose a reason for hiding this comment

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

Haha going well my friend. We are always looking at cutting edge stuff. Hope you and everyone else are well.

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.

2 participants