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.
This commit is contained in:
Benjamin Dauvergne 2018-11-22 12:34:11 +01:00
parent d856fc07ca
commit ce1b796473
1 changed files with 9 additions and 7 deletions

View File

@ -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()