# OAuth Token revocation

* adds revocation of user tokens on logout
This commit is contained in:
mpeltriaux 2024-12-23 09:26:14 +01:00
parent fa89bbba99
commit 1c24cbea26
2 changed files with 24 additions and 0 deletions

View File

@ -155,3 +155,22 @@ class OAuthToken(UuidModel):
return user return user
def revoke(self) -> (int, int):
""" Revokes the tokens of the user
Returns:
revocation_status_codes (tuple): HTTP status code for revocation of access_token and refresh_token
"""
revoke_url = f"{SSO_SERVER_BASE}o/revoke_token/"
token = self.refresh_token
revocation_status_codes = requests.post(
revoke_url,
data={
'token': token,
'token_type_hint': "refresh_token",
},
auth=(OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET),
).status_code
return revocation_status_codes

View File

@ -24,5 +24,10 @@ class LogoutView(View):
Returns: Returns:
A redirect A redirect
""" """
user = request.user
oauth_token = user.oauth_token
if oauth_token:
oauth_token.revoke()
logout(request) logout(request)
return redirect(SSO_SERVER_BASE) return redirect(SSO_SERVER_BASE)