Skip to content

Commit bff4d25

Browse files
Qup42dopry
authored andcommitted
Add configuration by authorization grant type for OIDC-RP Logout token deletion
1 parent 09e745d commit bff4d25

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

oauth2_provider/views/oidc.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,19 @@ def validate_logout_request(request, id_token_hint, client_id, post_logout_redir
265265
class RPInitiatedLogoutView(OIDCLogoutOnlyMixin, FormView):
266266
template_name = "oauth2_provider/logout_confirm.html"
267267
form_class = ConfirmLogoutForm
268-
token_types_to_delete = [
268+
# Only delete tokens for Application whose client type and authorization
269+
# grant type are in the respective lists.
270+
token_deletion_client_types = [
269271
Application.CLIENT_PUBLIC,
270272
Application.CLIENT_CONFIDENTIAL,
271273
]
274+
token_deletion_grant_types = [
275+
Application.GRANT_AUTHORIZATION_CODE,
276+
Application.GRANT_IMPLICIT,
277+
Application.GRANT_PASSWORD,
278+
Application.GRANT_CLIENT_CREDENTIALS,
279+
Application.GRANT_OPENID_HYBRID,
280+
]
272281

273282
def get_initial(self):
274283
return {
@@ -344,7 +353,9 @@ def do_logout(self, application=None, post_logout_redirect_uri=None, state=None)
344353
AccessToken = get_access_token_model()
345354
RefreshToken = get_refresh_token_model()
346355
access_tokens_to_delete = AccessToken.objects.filter(
347-
user=self.request.user, application__client_type__in=self.token_types_to_delete
356+
user=self.request.user,
357+
application__client_type__in=self.token_deletion_client_types,
358+
application__authorization_grant_type__in=self.token_deletion_grant_types,
348359
)
349360
# This queryset has to be evaluated eagerly. The queryset would be empty with lazy evaluation
350361
# because `access_tokens_to_delete` represents an empty queryset once `refresh_tokens_to_delete`

0 commit comments

Comments
 (0)