update metadata encoding handling
This commit is contained in:
parent
4c2d2e11e9
commit
79871d20f0
|
@ -25,6 +25,7 @@ import requests
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.core.files.storage import default_storage
|
from django.core.files.storage import default_storage
|
||||||
|
from django.utils.encoding import force_bytes, force_text
|
||||||
|
|
||||||
import lasso
|
import lasso
|
||||||
|
|
||||||
|
@ -59,12 +60,12 @@ class AuthenticAdapter(DefaultAdapter):
|
||||||
os.makedirs(cache_path)
|
os.makedirs(cache_path)
|
||||||
for idp in providers:
|
for idp in providers:
|
||||||
if 'METADATA_URL' in idp and 'METADATA' not in idp:
|
if 'METADATA_URL' in idp and 'METADATA' not in idp:
|
||||||
url_hash = hashlib.sha1(idp['METADATA_URL']).hexdigest()
|
url_hash = hashlib.sha1(force_bytes(idp['METADATA_URL'])).hexdigest()
|
||||||
metadata_cache_filename = os.path.join(cache_path, url_hash)
|
metadata_cache_filename = os.path.join(cache_path, url_hash)
|
||||||
if os.path.exists(metadata_cache_filename):
|
if os.path.exists(metadata_cache_filename):
|
||||||
stat_info = os.stat(metadata_cache_filename)
|
stat_info = os.stat(metadata_cache_filename)
|
||||||
if stat_info.st_size and stat_info.st_mtime > (time.time() - 86400):
|
if stat_info.st_size and stat_info.st_mtime > (time.time() - 86400):
|
||||||
idp['METADATA'] = open(metadata_cache_filename).read().decode('utf-8')
|
idp['METADATA'] = force_text(open(metadata_cache_filename).read())
|
||||||
continue
|
continue
|
||||||
verify_ssl_certificate = mellon_utils.get_setting(idp, 'VERIFY_SSL_CERTIFICATE')
|
verify_ssl_certificate = mellon_utils.get_setting(idp, 'VERIFY_SSL_CERTIFICATE')
|
||||||
try:
|
try:
|
||||||
|
@ -73,11 +74,11 @@ class AuthenticAdapter(DefaultAdapter):
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
if os.path.exists(metadata_cache_filename):
|
if os.path.exists(metadata_cache_filename):
|
||||||
# accept older cache in case of error
|
# accept older cache in case of error
|
||||||
idp['METADATA'] = open(metadata_cache_filename).read().decode('utf-8')
|
idp['METADATA'] = force_text(open(metadata_cache_filename).read())
|
||||||
continue
|
continue
|
||||||
idp['METADATA'] = response.text
|
idp['METADATA'] = response.text
|
||||||
with open(metadata_cache_filename, 'w') as fd:
|
with open(metadata_cache_filename, 'wb') as fd:
|
||||||
fd.write(response.text.encode('utf-8'))
|
fd.write(response.content)
|
||||||
return providers
|
return providers
|
||||||
|
|
||||||
def lookup_user(self, idp, saml_attributes):
|
def lookup_user(self, idp, saml_attributes):
|
||||||
|
|
Loading…
Reference in New Issue