Skip to content

Commit 363bfe0

Browse files
committed
fix: token revoke endpoint parameters
1 parent 072a1ce commit 363bfe0

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

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-routers/src/diracx/routers/auth/management.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from __future__ import annotations
88

99
import logging
10-
from typing import Annotated, Any
10+
from typing import Annotated, Any, Literal
1111

12-
from fastapi import Depends, HTTPException, status
12+
from fastapi import Depends, Form, HTTPException, status
1313
from joserfc.errors import DecodeError
1414
from typing_extensions import TypedDict
1515
from uuid_utils import UUID
@@ -66,8 +66,16 @@ async def get_refresh_tokens(
6666
async def revoke_refresh_token_by_refresh_token(
6767
auth_db: AuthDB,
6868
settings: AuthSettings,
69-
refresh_token: str,
70-
client_id: str,
69+
token: Annotated[str, Form(description="The refresh token to revoke")],
70+
# Unused but necessary parameter: https://datatracker.ietf.org/doc/html/rfc7009#section-2.1
71+
token_type_hint: Annotated[
72+
Literal["access_token", "refresh_token"],
73+
Form(description="Hint for the type of token being revoked"),
74+
] = "refresh_token", # noqa: S107
75+
client_id: Annotated[
76+
str,
77+
Form(description="The client ID of the application requesting the revocation"),
78+
] = "myDIRACClientID",
7179
) -> str:
7280
"""Revoke a refresh token."""
7381
# Test the client_id
@@ -77,9 +85,7 @@ async def revoke_refresh_token_by_refresh_token(
7785
)
7886

7987
try:
80-
await revoke_refresh_token_by_refresh_token_bl(
81-
auth_db, None, refresh_token, settings
82-
)
88+
await revoke_refresh_token_by_refresh_token_bl(auth_db, None, token, settings)
8389
except DecodeError:
8490
logger.warning("Someone tried to revoke its token but failed.")
8591

diracx-routers/tests/auth/test_standard.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,8 +1124,8 @@ async def test_revoke_refresh_token_classic(test_client, auth_httpx_mock: HTTPXM
11241124
# Normal user tries to delete a random and non-existing RT: should respond with a 200
11251125
r = test_client.post(
11261126
"/api/auth/revoke",
1127-
params={
1128-
"refresh_token": "does-not-exist",
1127+
data={
1128+
"token": "does-not-exist",
11291129
"client_id": DIRAC_CLIENT_ID,
11301130
},
11311131
)
@@ -1134,8 +1134,8 @@ async def test_revoke_refresh_token_classic(test_client, auth_httpx_mock: HTTPXM
11341134
# Normal user tries to delete his/her RT: should work
11351135
r = test_client.post(
11361136
"/api/auth/revoke",
1137-
params={
1138-
"refresh_token": normal_user_refresh_token,
1137+
data={
1138+
"token": normal_user_refresh_token,
11391139
"client_id": DIRAC_CLIENT_ID,
11401140
},
11411141
)
@@ -1152,8 +1152,8 @@ async def test_revoke_refresh_token_classic(test_client, auth_httpx_mock: HTTPXM
11521152
# Normal user tries to delete a valid RT using the wrong client id
11531153
r = test_client.post(
11541154
"/api/auth/revoke",
1155-
params={
1156-
"refresh_token": normal_user_refresh_token,
1155+
data={
1156+
"token": normal_user_refresh_token,
11571157
"client_id": "a_wrong_dirac_client_id",
11581158
},
11591159
)

0 commit comments

Comments
 (0)