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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the AuthClient inheritance tree #849

Merged
merged 11 commits into from Oct 5, 2023
Merged

Conversation

sirosen
Copy link
Member

@sirosen sirosen commented Aug 30, 2023

  • introduce AuthLoginClient and AuthServiceClient as the dividing line between each part of the tree
  • AuthClient becomes an alias for AuthLoginClient
  • the "app client" classes inherit from login client
  • a new base class, AuthBaseClient, provides OIDC and JWK methods, base data like service name, scopes, and error class, but no other methods

The calls provided on AuthBaseClient are those which are simple GET methods (and a decorated version thereof) which do not require authentication. As such, they make sense to expose equally to all client types.


馃摎 Documentation preview 馃摎: https://globus-sdk-python--849.org.readthedocs.build/en/849/

- introduce AuthLoginClient and AuthServiceClient as the dividing line
  between each part of the tree
- AuthClient becomes an alias for AuthLoginClient
- the "app client" classes inherit from login client
- a new base class, AuthBaseClient, provides OIDC and JWK methods,
  base data like service name, scopes, and error class, but no other
  methods

The calls provided on AuthBaseClient are those which are simple GET
methods (and a decorated version thereof) which do not require
authentication. As such, they make sense to expose equally to all
client types.
- RefreshTokenAuthorizer must be provided an AuthLoginClient, not an
  AuthClient
- OAuth2FlowManagers should be constrained to the appropriate client
  classes

Some additional type-checking retrofitting and an improvement to the
format of a docstring was included with this change.
To protect against a subtle backwards incompatible change, check at
runtime to see if an AuthClient (now AuthServiceClient) has been
passed to RefreshTokenAuthorizer.

Although it is possible to make this work under current SDK versions
under very constrained conditions -- using client credentials -- most
likely such usage indicates user error.

As such, the newly constrained usage (as expressed by type hints and
supported methods) is now captured in a usage error.
After discussion, our team agreed that this rename was not
providing sufficient value to justify, and that this naming problem
may have better solutions in SDK v4 if we reorganize the login clients
to potentially act as client wrappers.
1. Define helpers for getting and decoding JWK data
2. Use those helpers to explicitly implement common JWK handling
   methods in both AuthClient and AuthLoginClient
3. Remove the mixin
4. Assert the base client classes satisfy the internal protocol in a
   dedicated mypy test case
The methods which are copied (with no sophisticated code sharing)
between the two flavors of auth client class now have
warning/preceding comments which designate them as copies and indicate
a proposed path for SDK v4 to eliminate the duplication.
changelog.d/20230829_122956_sirosen_loginclient.rst Outdated Show resolved Hide resolved
changelog.d/20230829_122956_sirosen_loginclient.rst Outdated Show resolved Hide resolved
src/globus_sdk/authorizers/refresh_token.py Outdated Show resolved Hide resolved
tests/unit/test_auth_clients.py Outdated Show resolved Hide resolved
@kurtmckee
Copy link
Member

This looks great! I have but one last bit of feedback, but if you push back then I'm going to approve this PR. 馃憤

Copy link
Member

@kurtmckee kurtmckee left a comment

Choose a reason for hiding this comment

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

I'm approving this, whether the final suggestions get incorporated or not. I don't have a strong opinion about it. 馃榾

@sirosen sirosen merged commit 66356b9 into globus:main Oct 5, 2023
16 checks passed
@sirosen sirosen deleted the loginclient branch October 5, 2023 23:55
sirosen added a commit to sirosen/globus-sdk-python that referenced this pull request Oct 6, 2023
The `oauth2_userinfo` method was accidentally placed on the
`AuthLoginClient` class in globus#849 rather than the `AuthClient` class.

The mistake was made because it has a name which suggests that it is
an OAuth2 login-related method, when that is not the case.

In order to more clearly delineate that this is an API-client
method, the `oauth2_` prefix is here stripped and deprecated. A
compatibility shim method is included for now, but it emits a
deprecation warning.

The new name is `AuthClient.userinfo`.

Data in `_testing` has also been shimmed temporarily. This is an
arguably unnecessary step, but it is nearly trivial and saves us
potential migration and rollout pain at the time of our next release.
Because `_testing` has a weaker compatibility contract, the shim there
can be removed after a single release.
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.

None yet

2 participants