Skip to content
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

Improve control over identity_id extraction in experimental TokenStorage #1055

Merged

Conversation

sirosen
Copy link
Member

@sirosen sirosen commented Sep 19, 2024

Add a private-to-the-SDK hook for controlling extraction of identity_id, and use that hook to implement the appropriate override for ValidatingTokenStorage to use its own identity_id value when handling refresh tokens.
Additionally, fix OAuthDependentTokenResponse handling in the general case, and add tests which validate these behaviors.

These changes fix a bug in the handling of token refreshes under GlobusApp.


📚 Documentation preview 📚: https://globus-sdk-python--1055.org.readthedocs.build/en/1055/

Depending on the response context (the type of OAuthTokenResponse in
use) and the calling context (ValidatingTokenStorage or the
base class), there are various optimal behaviors for `identity_id`
determination.

In order to avoid declaring any new public interface which would need
support, this is defined as an internal-only hook,
`TokenStorage._extract_identity_id`, and given various behaviors in
different scenarios.

In the typical case, it acts exactly as it used to. The following
scenarios modify its behavior:
- on dependent token responses, it returns None
- in the ValidatingTokenStorage, it returns
  `ValidatingTokenStorage.identity_id` IFF the response is an
  OAuthRefreshTokenResponse
Define tests which ensure that all of the standard TokenStorage
classes handle the variants of OAuthTokenResponse gracefully.
Refresh and dependent token responses should be accepted, in spite of
their data shapes not including `id_token`.

In the case of refresh token data, `id_token` is absent, and in the
case of dependent token data, the top-level structure is an array.

As a control against these two tests, check the behavior of an
authorization code grant response containing an `id_token`.
A dedicated test case stores token data twice, using a refresh token
response for the second store. It verifies that under such a usage,
the original identity information is preserved.
Copy link
Contributor

@derek-globus derek-globus left a comment

Choose a reason for hiding this comment

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

Concise and clean fix!

@derek-globus
Copy link
Contributor

derek-globus commented Sep 19, 2024

Bug report which prompted this fix: #1050

@sirosen sirosen force-pushed the control-tokenstorage-identity-id-extraction branch from 6bfd4ac to 437c00d Compare September 19, 2024 19:33
@sirosen
Copy link
Member Author

sirosen commented Sep 19, 2024

I fixed a little typo in the changelog; I'll go ahead with the merge as soon as CI is ✔️

@sirosen sirosen merged commit 9ed7542 into globus:main Sep 19, 2024
15 checks passed
@sirosen sirosen deleted the control-tokenstorage-identity-id-extraction branch September 19, 2024 20:38
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