-
Notifications
You must be signed in to change notification settings - Fork 343
feat: Implement token revocation in STS client and add revoke() metho… #1849
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
Merged
nbayati
merged 11 commits into
googleapis:main
from
kdeniz-git:implement-token-revocation-in-sts-client
Nov 11, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dddc3b1
feat: Implement token revocation in STS client and add revoke() metho…
kdeniz-git efa3288
Merge branch 'main' into implement-token-revocation-in-sts-client
kdeniz-git 1983277
clear the local state of the credential after a successful revocation
kdeniz-git 54de6dc
Merge branch 'implement-token-revocation-in-sts-client' of github.com…
kdeniz-git fa96f41
Merge branch 'main' into implement-token-revocation-in-sts-client
daniel-sanche 964e889
Merge branch 'main' into implement-token-revocation-in-sts-client
nbayati 29d050f
Fix the broken test_revoke_auth_success
kdeniz-git 18cb99b
Merge branch 'implement-token-revocation-in-sts-client' of github.com…
kdeniz-git 953ce10
Add unit test to increase coverage and fix the linting issues
kdeniz-git 7502a60
Delete the pyenv-installer that got accidentally added
kdeniz-git fa07d22
Merge branch 'main' into implement-token-revocation-in-sts-client
nbayati File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,7 @@ def __init__(self, token_exchange_endpoint, client_authentication=None): | |
| super(Client, self).__init__(client_authentication) | ||
| self._token_exchange_endpoint = token_exchange_endpoint | ||
|
|
||
| def _make_request(self, request, headers, request_body): | ||
| def _make_request(self, request, headers, request_body, url=None): | ||
| # Initialize request headers. | ||
| request_headers = _URLENCODED_HEADERS.copy() | ||
|
|
||
|
|
@@ -69,9 +69,12 @@ def _make_request(self, request, headers, request_body): | |
| # Apply OAuth client authentication. | ||
| self.apply_client_authentication_options(request_headers, request_body) | ||
|
|
||
| # Use default token exchange endpoint if no url is provided. | ||
| url = url or self._token_exchange_endpoint | ||
|
|
||
| # Execute request. | ||
| response = request( | ||
| url=self._token_exchange_endpoint, | ||
| url=url, | ||
| method="POST", | ||
| headers=request_headers, | ||
| body=urllib.parse.urlencode(request_body).encode("utf-8"), | ||
|
|
@@ -87,10 +90,12 @@ def _make_request(self, request, headers, request_body): | |
| if response.status != http_client.OK: | ||
| utils.handle_error_response(response_body) | ||
|
|
||
| response_data = json.loads(response_body) | ||
| # A successful token revocation returns an empty response body. | ||
| if not response_body: | ||
| return {} | ||
|
|
||
| # Return successful response. | ||
| return response_data | ||
| # Other successful responses should be valid JSON. | ||
| return json.loads(response_body) | ||
|
|
||
| def exchange_token( | ||
| self, | ||
|
|
@@ -174,3 +179,23 @@ def refresh_token(self, request, refresh_token): | |
| None, | ||
| {"grant_type": "refresh_token", "refresh_token": refresh_token}, | ||
| ) | ||
|
|
||
| def revoke_token(self, request, token, token_type_hint, revoke_url): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: It seems like token_type_hint could be optional. It might be good to mention that in the docstrings, and in the signature |
||
| """Revokes the provided token based on the RFC7009 spec. | ||
|
|
||
| Args: | ||
| request (google.auth.transport.Request): A callable used to make | ||
| HTTP requests. | ||
| token (str): The OAuth 2.0 token to revoke. | ||
| token_type_hint (str): Hint for the type of token being revoked. | ||
| revoke_url (str): The STS endpoint URL for revoking tokens. | ||
|
|
||
| Raises: | ||
| google.auth.exceptions.OAuthError: If the token revocation endpoint | ||
| returned an error. | ||
| """ | ||
| request_body = {"token": token} | ||
| if token_type_hint: | ||
| request_body["token_type_hint"] = token_type_hint | ||
|
|
||
| return self._make_request(request, None, request_body, revoke_url) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.