|
1 | 1 | import hashlib
|
2 |
| -import json |
3 | 2 | import logging
|
4 | 3 | import time
|
5 | 4 | import uuid
|
6 | 5 | from contextlib import suppress
|
7 | 6 | from datetime import timedelta
|
8 | 7 | from urllib.parse import parse_qsl, urlparse
|
9 | 8 |
|
10 |
| -import requests |
11 | 9 | from django.apps import apps
|
12 | 10 | from django.conf import settings
|
13 | 11 | from django.contrib.auth.hashers import identify_hasher, make_password
|
|
16 | 14 | from django.urls import reverse
|
17 | 15 | from django.utils import timezone
|
18 | 16 | from django.utils.translation import gettext_lazy as _
|
19 |
| -from jwcrypto import jwk, jwt |
| 17 | +from jwcrypto import jwk |
20 | 18 | from jwcrypto.common import base64url_encode
|
21 | 19 | from oauthlib.oauth2.rfc6749 import errors
|
22 | 20 |
|
23 |
| -from .exceptions import BackchannelLogoutRequestError |
24 | 21 | from .generators import generate_client_id, generate_client_secret
|
25 | 22 | from .scopes import get_scopes_backend
|
26 | 23 | from .settings import oauth2_settings
|
@@ -636,53 +633,6 @@ def revoke(self):
|
636 | 633 | """
|
637 | 634 | self.delete()
|
638 | 635 |
|
639 |
| - def send_backchannel_logout_request(self, ttl=timedelta(minutes=10)): |
640 |
| - """ |
641 |
| - Send a logout token to the applications backchannel logout uri |
642 |
| - """ |
643 |
| - try: |
644 |
| - assert oauth2_settings.OIDC_BACKCHANNEL_LOGOUT_ENABLED, "Backchannel logout not enabled" |
645 |
| - assert self.application.algorithm != AbstractApplication.NO_ALGORITHM, ( |
646 |
| - "Application must provide signing algorithm" |
647 |
| - ) |
648 |
| - assert self.application.backchannel_logout_uri is not None, ( |
649 |
| - "URL for backchannel logout not provided by client" |
650 |
| - ) |
651 |
| - |
652 |
| - issued_at = timezone.now() |
653 |
| - expiration_date = issued_at + ttl |
654 |
| - |
655 |
| - claims = { |
656 |
| - "iss": oauth2_settings.OIDC_ISS_ENDPOINT, |
657 |
| - "sub": str(self.user.id), |
658 |
| - "aud": str(self.application.client_id), |
659 |
| - "iat": int(issued_at.timestamp()), |
660 |
| - "exp": int(expiration_date.timestamp()), |
661 |
| - "jti": self.jti, |
662 |
| - "events": {"http://schemas.openid.net/event/backchannel-logout": {}}, |
663 |
| - } |
664 |
| - |
665 |
| - # Standard JWT header |
666 |
| - header = {"typ": "logout+jwt", "alg": self.application.algorithm} |
667 |
| - |
668 |
| - # RS256 consumers expect a kid in the header for verifying the token |
669 |
| - if self.application.algorithm == AbstractApplication.RS256_ALGORITHM: |
670 |
| - header["kid"] = self.application.jwk_key.thumbprint() |
671 |
| - |
672 |
| - token = jwt.JWT( |
673 |
| - header=json.dumps(header, default=str), |
674 |
| - claims=json.dumps(claims, default=str), |
675 |
| - ) |
676 |
| - |
677 |
| - token.make_signed_token(self.application.jwk_key) |
678 |
| - |
679 |
| - headers = {"Content-Type": "application/x-www-form-urlencoded"} |
680 |
| - data = {"logout_token": token.serialize()} |
681 |
| - response = requests.post(self.application.backchannel_logout_uri, headers=headers, data=data) |
682 |
| - response.raise_for_status() |
683 |
| - except (AssertionError, requests.RequestException) as exc: |
684 |
| - raise BackchannelLogoutRequestError(str(exc)) |
685 |
| - |
686 | 636 | @property
|
687 | 637 | def scopes(self):
|
688 | 638 | """
|
@@ -913,15 +863,3 @@ def is_origin_allowed(origin, allowed_origins):
|
913 | 863 | return True
|
914 | 864 |
|
915 | 865 | return False
|
916 |
| - |
917 |
| - |
918 |
| -def send_backchannel_logout_requests(user): |
919 |
| - """ |
920 |
| - Creates logout tokens for all id tokens associated with the user |
921 |
| - """ |
922 |
| - id_tokens = IDToken.objects.filter(application__backchannel_logout_uri__isnull=False, user=user) |
923 |
| - for id_token in id_tokens: |
924 |
| - try: |
925 |
| - id_token.send_backchannel_logout_request() |
926 |
| - except BackchannelLogoutRequestError as exc: |
927 |
| - logger.warn(str(exc)) |
0 commit comments