From 666234043849b649d749b1ff9153cb93c7c2b9aa Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 22 Nov 2018 12:34:11 +0100 Subject: [PATCH 1/2] idp_oidc: use force_bytes/text and six.text_type instead of smart_bytes and unicode (#27540) Just some cleaning, not really related to #27540. --- src/authentic2_idp_oidc/utils.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/authentic2_idp_oidc/utils.py b/src/authentic2_idp_oidc/utils.py index 88e0dbf3..b908957e 100644 --- a/src/authentic2_idp_oidc/utils.py +++ b/src/authentic2_idp_oidc/utils.py @@ -3,12 +3,14 @@ import hashlib import base64 import uuid +from six import text_type, string_types + from jwcrypto.jwk import JWK, JWKSet, InvalidJWKValue from jwcrypto.jwt import JWT from django.core.exceptions import ImproperlyConfigured from django.conf import settings -from django.utils.encoding import smart_bytes +from django.utils.encoding import force_bytes, force_text from django.utils.six.moves.urllib import parse as urlparse from authentic2 import hooks, crypto @@ -70,7 +72,7 @@ def scope_set(data): def clean_words(data): '''Clean and order a list of words''' - return u' '.join(sorted(map(unicode.strip, data.split()))) + return u' '.join(sorted(map(text_type.strip, data.split()))) def url_domain(url): @@ -81,7 +83,7 @@ def make_sub(client, user): if client.identifier_policy in (client.POLICY_PAIRWISE, client.POLICY_PAIRWISE_REVERSIBLE): return make_pairwise_sub(client, user) elif client.identifier_policy == client.POLICY_UUID: - return unicode(user.uuid) + return force_text(user.uuid) elif client.identifier_policy == client.POLICY_EMAIL: return user.email else: @@ -152,7 +154,7 @@ def reverse_pairwise_sub(client, sub): def normalize_claim_values(values): values_list = [] - if isinstance(values, basestring) or not hasattr(values, '__iter__'): + if isinstance(values, string_types) or not hasattr(values, '__iter__'): return values for value in values: if isinstance(value, bool): @@ -192,9 +194,9 @@ def get_issuer(request): def get_session_id(request, client): '''Derive an OIDC Session Id from the real session identifier, the sector identifier of the RP and the secret key of the Django instance''' - session_key = smart_bytes(request.session.session_key) - sector_identifier = smart_bytes(get_sector_identifier(client)) - secret_key = smart_bytes(settings.SECRET_KEY) + session_key = force_bytes(request.session.session_key) + sector_identifier = force_bytes(get_sector_identifier(client)) + secret_key = force_bytes(settings.SECRET_KEY) return hashlib.md5(session_key + sector_identifier + secret_key).hexdigest() -- 2.20.1