3 |
3 |
import base64
|
4 |
4 |
import uuid
|
5 |
5 |
|
|
6 |
from six import text_type, string_types
|
|
7 |
|
6 |
8 |
from jwcrypto.jwk import JWK, JWKSet, InvalidJWKValue
|
7 |
9 |
from jwcrypto.jwt import JWT
|
8 |
10 |
|
9 |
11 |
from django.core.exceptions import ImproperlyConfigured
|
10 |
12 |
from django.conf import settings
|
11 |
|
from django.utils.encoding import smart_bytes
|
|
13 |
from django.utils.encoding import force_bytes, force_text
|
12 |
14 |
from django.utils.six.moves.urllib import parse as urlparse
|
13 |
15 |
|
14 |
16 |
from authentic2 import hooks, crypto
|
... | ... | |
70 |
72 |
|
71 |
73 |
def clean_words(data):
|
72 |
74 |
'''Clean and order a list of words'''
|
73 |
|
return u' '.join(sorted(map(unicode.strip, data.split())))
|
|
75 |
return u' '.join(sorted(map(text_type.strip, data.split())))
|
74 |
76 |
|
75 |
77 |
|
76 |
78 |
def url_domain(url):
|
... | ... | |
81 |
83 |
if client.identifier_policy in (client.POLICY_PAIRWISE, client.POLICY_PAIRWISE_REVERSIBLE):
|
82 |
84 |
return make_pairwise_sub(client, user)
|
83 |
85 |
elif client.identifier_policy == client.POLICY_UUID:
|
84 |
|
return unicode(user.uuid)
|
|
86 |
return force_text(user.uuid)
|
85 |
87 |
elif client.identifier_policy == client.POLICY_EMAIL:
|
86 |
88 |
return user.email
|
87 |
89 |
else:
|
... | ... | |
152 |
154 |
|
153 |
155 |
def normalize_claim_values(values):
|
154 |
156 |
values_list = []
|
155 |
|
if isinstance(values, basestring) or not hasattr(values, '__iter__'):
|
|
157 |
if isinstance(values, string_types) or not hasattr(values, '__iter__'):
|
156 |
158 |
return values
|
157 |
159 |
for value in values:
|
158 |
160 |
if isinstance(value, bool):
|
... | ... | |
192 |
194 |
def get_session_id(request, client):
|
193 |
195 |
'''Derive an OIDC Session Id from the real session identifier, the sector
|
194 |
196 |
identifier of the RP and the secret key of the Django instance'''
|
195 |
|
session_key = smart_bytes(request.session.session_key)
|
196 |
|
sector_identifier = smart_bytes(get_sector_identifier(client))
|
197 |
|
secret_key = smart_bytes(settings.SECRET_KEY)
|
|
197 |
session_key = force_bytes(request.session.session_key)
|
|
198 |
sector_identifier = force_bytes(get_sector_identifier(client))
|
|
199 |
secret_key = force_bytes(settings.SECRET_KEY)
|
198 |
200 |
return hashlib.md5(session_key + sector_identifier + secret_key).hexdigest()
|
199 |
201 |
|
200 |
202 |
|
201 |
|
-
|