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

Add 'query_params' to token introspect #984

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog.d/20240508_113916_sirosen_add_query_params.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Added
~~~~~

- Add support for added query parameters to
``ConfidentialAppAuthClient.oauth2_token_introspect`` via a ``query_params``
argument. (:pr:`NUMBER`)
44 changes: 44 additions & 0 deletions src/globus_sdk/_testing/data/auth/oauth2_token_introspect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import uuid

from globus_sdk._testing.models import RegisteredResponse, ResponseSet

_kingfish = {
"username": "[email protected]",
"name": "Christone Ingram",
"id": str(uuid.uuid1()),
"email": "[email protected]",
}
_client_id = str(uuid.uuid1())
_scope = "urn:globus:auth:scope:auth.globus.org:view_identity_set profile email openid"


RESPONSES = ResponseSet(
default=RegisteredResponse(
service="auth",
path="/v2/oauth2/token/introspect",
method="POST",
json={
"active": True,
"token_type": "Bearer",
"scope": _scope,
"client_id": _client_id,
"username": _kingfish["username"],
"name": _kingfish["name"],
"email": _kingfish["email"],
"exp": 1715289767,
"iat": 1715116967,
"nbf": 1715116967,
"sub": _kingfish["id"],
"aud": [
"auth.globus.org",
_client_id,
],
"iss": "https://auth.globus.org",
},
metadata={
"client_id": _client_id,
"scope": _scope,
**_kingfish,
},
)
)
15 changes: 13 additions & 2 deletions src/globus_sdk/services/auth/client/confidential_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,20 @@ def oauth2_get_dependent_tokens(
return self.oauth2_token(form_data, response_class=OAuthDependentTokenResponse)

def oauth2_token_introspect(
self, token: str, *, include: str | None = None
self,
token: str,
*,
include: str | None = None,
query_params: dict[str, t.Any] | None = None,
) -> GlobusHTTPResponse:
"""
Get information about a Globus Auth token.

:param token: An Access Token as a raw string, being evaluated
:param include: A value for the ``include`` parameter in the request body.
Default is to omit the parameter.
:param query_params: Any additional parameters to be passed through
as query params.

.. tab-set::

Expand Down Expand Up @@ -308,7 +314,12 @@ def oauth2_token_introspect(
body = {"token": token}
if include is not None:
body["include"] = include
return self.post("/v2/oauth2/token/introspect", data=body, encoding="form")
return self.post(
"/v2/oauth2/token/introspect",
data=body,
encoding="form",
query_params=query_params,
)

def create_child_client(
self,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import pytest
from globus_sdk._testing import get_last_request, load_response


@pytest.mark.xfail
def test_oauth2_token_introspect():
raise NotImplementedError
def test_oauth2_token_introspect(auth_client):
meta = load_response(auth_client.oauth2_token_introspect).metadata
response = auth_client.oauth2_token_introspect("some_very_cool_token")
assert response["username"] == meta["username"]
assert response["sub"] == meta["id"]

last_req = get_last_request()
assert len(last_req.params) == 0


def test_oauth2_token_introspect_allows_added_query_params(auth_client):
meta = load_response(auth_client.oauth2_token_introspect).metadata
response = auth_client.oauth2_token_introspect(
"some_very_cool_token", query_params={"foo": "bar"}
)
assert response["username"] == meta["username"]
assert response["sub"] == meta["id"]

last_req = get_last_request()
assert last_req.params["foo"] == "bar"
Loading