Skip to content

Commit bc33e1c

Browse files
authored
Merge pull request #666 from aldbr/main_FIX_revoke-endpoint-rfc-aligned
fix: token revoke endpoint parameters
2 parents e8d3f1a + 6bb41e0 commit bc33e1c

File tree

16 files changed

+281
-295
lines changed

16 files changed

+281
-295
lines changed

diracx-cli/src/diracx/cli/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async def logout():
129129
# Revoke refresh token
130130
try:
131131
await api.auth.revoke_refresh_token_by_refresh_token(
132-
client_id=api.client_id, refresh_token=credentials.refresh_token
132+
client_id=api.client_id, token=credentials.refresh_token
133133
)
134134
except Exception as e:
135135
print(f"Error revoking the refresh token {e!r}")

diracx-client/src/diracx/client/_generated/aio/operations/_operations.py

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
build_auth_initiate_authorization_flow_request,
3636
build_auth_initiate_device_flow_request,
3737
build_auth_revoke_refresh_token_by_jti_request,
38-
build_auth_revoke_refresh_token_by_refresh_token_request,
3938
build_auth_userinfo_request,
4039
build_config_serve_config_request,
4140
build_jobs_add_heartbeat_request,
@@ -293,6 +292,7 @@ def __init__(self, *args, **kwargs) -> None:
293292
raise_if_not_implemented(
294293
self.__class__,
295294
[
295+
"revoke_refresh_token_by_refresh_token",
296296
"get_oidc_token",
297297
],
298298
)
@@ -583,59 +583,6 @@ async def get_refresh_tokens(self, **kwargs: Any) -> List[Any]:
583583

584584
return deserialized # type: ignore
585585

586-
@distributed_trace_async
587-
async def revoke_refresh_token_by_refresh_token(self, *, refresh_token: str, client_id: str, **kwargs: Any) -> str:
588-
"""Revoke Refresh Token By Refresh Token.
589-
590-
Revoke a refresh token.
591-
592-
:keyword refresh_token: Required.
593-
:paramtype refresh_token: str
594-
:keyword client_id: Required.
595-
:paramtype client_id: str
596-
:return: str
597-
:rtype: str
598-
:raises ~azure.core.exceptions.HttpResponseError:
599-
"""
600-
error_map: MutableMapping = {
601-
401: ClientAuthenticationError,
602-
404: ResourceNotFoundError,
603-
409: ResourceExistsError,
604-
304: ResourceNotModifiedError,
605-
}
606-
error_map.update(kwargs.pop("error_map", {}) or {})
607-
608-
_headers = kwargs.pop("headers", {}) or {}
609-
_params = kwargs.pop("params", {}) or {}
610-
611-
cls: ClsType[str] = kwargs.pop("cls", None)
612-
613-
_request = build_auth_revoke_refresh_token_by_refresh_token_request(
614-
refresh_token=refresh_token,
615-
client_id=client_id,
616-
headers=_headers,
617-
params=_params,
618-
)
619-
_request.url = self._client.format_url(_request.url)
620-
621-
_stream = False
622-
pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access
623-
_request, stream=_stream, **kwargs
624-
)
625-
626-
response = pipeline_response.http_response
627-
628-
if response.status_code not in [200]:
629-
map_error(status_code=response.status_code, response=response, error_map=error_map)
630-
raise HttpResponseError(response=response)
631-
632-
deserialized = self._deserialize("str", pipeline_response.http_response)
633-
634-
if cls:
635-
return cls(pipeline_response, deserialized, {}) # type: ignore
636-
637-
return deserialized # type: ignore
638-
639586
@distributed_trace_async
640587
async def revoke_refresh_token_by_jti(self, jti: str, **kwargs: Any) -> str:
641588
"""Revoke Refresh Token By Jti.

diracx-client/src/diracx/client/_generated/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ._models import ( # type: ignore
1515
BodyAuthGetOidcToken,
1616
BodyAuthGetOidcTokenGrantType,
17+
BodyAuthRevokeRefreshTokenByRefreshToken,
1718
BodyJobsRescheduleJobs,
1819
BodyJobsUnassignBulkJobsSandboxes,
1920
GroupInfo,
@@ -65,6 +66,7 @@
6566
__all__ = [
6667
"BodyAuthGetOidcToken",
6768
"BodyAuthGetOidcTokenGrantType",
69+
"BodyAuthRevokeRefreshTokenByRefreshToken",
6870
"BodyJobsRescheduleJobs",
6971
"BodyJobsUnassignBulkJobsSandboxes",
7072
"GroupInfo",

diracx-client/src/diracx/client/_generated/models/_models.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,46 @@ class BodyAuthGetOidcTokenGrantType(_serialization.Model):
9494
"""OAuth2 Grant type."""
9595

9696

97+
class BodyAuthRevokeRefreshTokenByRefreshToken(_serialization.Model):
98+
"""Body_auth_revoke_refresh_token_by_refresh_token.
99+
100+
All required parameters must be populated in order to send to server.
101+
102+
:ivar token: The refresh token to revoke. Required.
103+
:vartype token: str
104+
:ivar token_type_hint: Hint for the type of token being revoked.
105+
:vartype token_type_hint: str
106+
:ivar client_id: The client ID of the application requesting the revocation.
107+
:vartype client_id: str
108+
"""
109+
110+
_validation = {
111+
"token": {"required": True},
112+
}
113+
114+
_attribute_map = {
115+
"token": {"key": "token", "type": "str"},
116+
"token_type_hint": {"key": "token_type_hint", "type": "str"},
117+
"client_id": {"key": "client_id", "type": "str"},
118+
}
119+
120+
def __init__(
121+
self, *, token: str, token_type_hint: Optional[str] = None, client_id: str = "myDIRACClientID", **kwargs: Any
122+
) -> None:
123+
"""
124+
:keyword token: The refresh token to revoke. Required.
125+
:paramtype token: str
126+
:keyword token_type_hint: Hint for the type of token being revoked.
127+
:paramtype token_type_hint: str
128+
:keyword client_id: The client ID of the application requesting the revocation.
129+
:paramtype client_id: str
130+
"""
131+
super().__init__(**kwargs)
132+
self.token = token
133+
self.token_type_hint = token_type_hint
134+
self.client_id = client_id
135+
136+
97137
class BodyJobsRescheduleJobs(_serialization.Model):
98138
"""Body_jobs_reschedule_jobs.
99139

diracx-client/src/diracx/client/_generated/operations/_operations.py

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,6 @@ def build_auth_get_refresh_tokens_request(**kwargs: Any) -> HttpRequest:
175175
return HttpRequest(method="GET", url=_url, headers=_headers, **kwargs)
176176

177177

178-
def build_auth_revoke_refresh_token_by_refresh_token_request( # pylint: disable=name-too-long
179-
*, refresh_token: str, client_id: str, **kwargs: Any
180-
) -> HttpRequest:
181-
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
182-
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
183-
184-
accept = _headers.pop("Accept", "application/json")
185-
186-
# Construct URL
187-
_url = "/api/auth/revoke"
188-
189-
# Construct parameters
190-
_params["refresh_token"] = _SERIALIZER.query("refresh_token", refresh_token, "str")
191-
_params["client_id"] = _SERIALIZER.query("client_id", client_id, "str")
192-
193-
# Construct headers
194-
_headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
195-
196-
return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)
197-
198-
199178
def build_auth_revoke_refresh_token_by_jti_request( # pylint: disable=name-too-long
200179
jti: str, **kwargs: Any
201180
) -> HttpRequest:
@@ -816,6 +795,7 @@ def __init__(self, *args, **kwargs) -> None:
816795
raise_if_not_implemented(
817796
self.__class__,
818797
[
798+
"revoke_refresh_token_by_refresh_token",
819799
"get_oidc_token",
820800
],
821801
)
@@ -1104,59 +1084,6 @@ def get_refresh_tokens(self, **kwargs: Any) -> List[Any]:
11041084

11051085
return deserialized # type: ignore
11061086

1107-
@distributed_trace
1108-
def revoke_refresh_token_by_refresh_token(self, *, refresh_token: str, client_id: str, **kwargs: Any) -> str:
1109-
"""Revoke Refresh Token By Refresh Token.
1110-
1111-
Revoke a refresh token.
1112-
1113-
:keyword refresh_token: Required.
1114-
:paramtype refresh_token: str
1115-
:keyword client_id: Required.
1116-
:paramtype client_id: str
1117-
:return: str
1118-
:rtype: str
1119-
:raises ~azure.core.exceptions.HttpResponseError:
1120-
"""
1121-
error_map: MutableMapping = {
1122-
401: ClientAuthenticationError,
1123-
404: ResourceNotFoundError,
1124-
409: ResourceExistsError,
1125-
304: ResourceNotModifiedError,
1126-
}
1127-
error_map.update(kwargs.pop("error_map", {}) or {})
1128-
1129-
_headers = kwargs.pop("headers", {}) or {}
1130-
_params = kwargs.pop("params", {}) or {}
1131-
1132-
cls: ClsType[str] = kwargs.pop("cls", None)
1133-
1134-
_request = build_auth_revoke_refresh_token_by_refresh_token_request(
1135-
refresh_token=refresh_token,
1136-
client_id=client_id,
1137-
headers=_headers,
1138-
params=_params,
1139-
)
1140-
_request.url = self._client.format_url(_request.url)
1141-
1142-
_stream = False
1143-
pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
1144-
_request, stream=_stream, **kwargs
1145-
)
1146-
1147-
response = pipeline_response.http_response
1148-
1149-
if response.status_code not in [200]:
1150-
map_error(status_code=response.status_code, response=response, error_map=error_map)
1151-
raise HttpResponseError(response=response)
1152-
1153-
deserialized = self._deserialize("str", pipeline_response.http_response)
1154-
1155-
if cls:
1156-
return cls(pipeline_response, deserialized, {}) # type: ignore
1157-
1158-
return deserialized # type: ignore
1159-
11601087
@distributed_trace
11611088
def revoke_refresh_token_by_jti(self, jti: str, **kwargs: Any) -> str:
11621089
"""Revoke Refresh Token By Jti.

diracx-client/src/diracx/client/patches/auth/aio.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
from __future__ import annotations
9+
from ast import Dict
910

1011
__all__ = [
1112
"AuthOperations",
@@ -19,15 +20,15 @@
1920
_models,
2021
AuthOperations as _AuthOperations,
2122
)
22-
from .common import prepare_request, handle_response
23+
from .common import handle_revoke_response, prepare_oidc_request, handle_oidc_response, prepare_revoke_request
2324

2425

2526
class AuthOperations(_AuthOperations):
2627
@distributed_trace_async
2728
async def get_oidc_token(
2829
self, device_code: str, client_id: str, **kwargs
2930
) -> TokenResponse | _models.DeviceFlowErrorResponse:
30-
request = prepare_request(
31+
request = prepare_oidc_request(
3132
device_code=device_code,
3233
client_id=client_id,
3334
format_url=self._client.format_url,
@@ -39,7 +40,30 @@ async def get_oidc_token(
3940
)
4041
)
4142

42-
response = handle_response(pipeline_response, self._deserialize)
43+
response = handle_oidc_response(pipeline_response, self._deserialize)
4344
if isinstance(response, _models.DeviceFlowErrorResponse):
4445
return response
4546
return TokenResponse.model_validate(response.as_dict())
47+
48+
@distributed_trace_async
49+
async def revoke_refresh_token_by_refresh_token(
50+
self,
51+
*,
52+
token: str,
53+
client_id: str,
54+
token_type_hint: str = "refresh_token",
55+
**kwargs,
56+
) -> str:
57+
request = prepare_revoke_request(
58+
token=token,
59+
client_id=client_id,
60+
token_type_hint=token_type_hint,
61+
format_url=self._client.format_url,
62+
)
63+
64+
pipeline_response: PipelineResponse = (
65+
await self._client._pipeline.run( # pylint: disable=protected-access
66+
request, stream=False, **kwargs
67+
)
68+
)
69+
return handle_revoke_response(pipeline_response, self._deserialize)

diracx-client/src/diracx/client/patches/auth/common.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from __future__ import annotations
44

55
__all__ = [
6-
"prepare_request",
7-
"handle_response",
6+
"prepare_oidc_request",
7+
"handle_oidc_response",
88
]
99

1010
from typing import Any
@@ -18,20 +18,24 @@
1818
from ..._generated.operations._operations import _SERIALIZER
1919

2020

21-
def build_token_request(**kwargs: Any) -> HttpRequest:
21+
def build_request(**kwargs: Any) -> HttpRequest:
2222
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
2323

2424
accept = _headers.pop("Accept", "application/json")
2525

26-
_url = "/api/auth/token"
26+
_url = kwargs.pop("url")
2727

2828
_headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
2929

30-
return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs)
30+
_method = kwargs.pop("method")
3131

32+
return HttpRequest(method=_method, url=_url, headers=_headers, **kwargs)
3233

33-
def prepare_request(device_code, client_id, format_url) -> HttpRequest:
34-
request = build_token_request(
34+
35+
def prepare_oidc_request(device_code, client_id, format_url) -> HttpRequest:
36+
request = build_request(
37+
method="POST",
38+
url="/api/auth/token",
3539
data={
3640
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
3741
"device_code": device_code,
@@ -42,7 +46,21 @@ def prepare_request(device_code, client_id, format_url) -> HttpRequest:
4246
return request
4347

4448

45-
def handle_response(
49+
def prepare_revoke_request(token, client_id, token_type_hint, format_url) -> HttpRequest:
50+
request = build_request(
51+
method="POST",
52+
url="/api/auth/revoke",
53+
data={
54+
"token": token,
55+
"client_id": client_id,
56+
"token_type_hint": token_type_hint,
57+
}
58+
)
59+
request.url = format_url(request.url)
60+
return request
61+
62+
63+
def handle_oidc_response(
4664
pipeline_response: PipelineResponse, deserialize
4765
) -> TokenResponse | DeviceFlowErrorResponse:
4866
response = pipeline_response.http_response
@@ -54,3 +72,14 @@ def handle_response(
5472
else:
5573
map_error(status_code=response.status_code, response=response, error_map={})
5674
raise HttpResponseError(response=response)
75+
76+
77+
def handle_revoke_response(
78+
pipeline_response: PipelineResponse, deserialize
79+
) -> str:
80+
response = pipeline_response.http_response
81+
82+
if response.status_code != 200:
83+
map_error(status_code=response.status_code, response=response, error_map={})
84+
raise HttpResponseError(response=response)
85+
return deserialize("str", pipeline_response)

0 commit comments

Comments
 (0)