2015-07-13 20:36:15 +00:00
|
|
|
from django.conf import settings as django_settings
|
2015-03-04 19:24:41 +00:00
|
|
|
from django.core.urlresolvers import reverse
|
2015-11-12 20:12:18 +00:00
|
|
|
from django.http import HttpResponse
|
2015-03-04 19:24:41 +00:00
|
|
|
|
|
|
|
from oidc_provider import settings
|
|
|
|
|
|
|
|
|
2015-11-12 20:12:18 +00:00
|
|
|
def redirect(uri):
|
|
|
|
"""
|
|
|
|
Custom Response object for redirecting to a Non-HTTP url scheme.
|
|
|
|
"""
|
|
|
|
response = HttpResponse('', status=302)
|
|
|
|
response['Location'] = uri
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
2015-03-04 19:24:41 +00:00
|
|
|
def get_issuer():
|
2015-07-13 20:36:15 +00:00
|
|
|
"""
|
|
|
|
Construct the issuer full url. Basically is the site url with some path
|
|
|
|
appended.
|
|
|
|
"""
|
|
|
|
site_url = settings.get('SITE_URL')
|
|
|
|
path = reverse('oidc_provider:provider_info') \
|
2016-01-16 10:35:26 +00:00
|
|
|
.split('/.well-known/openid-configuration')[0]
|
2015-07-13 20:36:15 +00:00
|
|
|
issuer = site_url + path
|
2015-03-04 19:24:41 +00:00
|
|
|
|
2015-07-13 20:36:15 +00:00
|
|
|
return issuer
|
|
|
|
|
|
|
|
|
|
|
|
def get_rsa_key():
|
|
|
|
"""
|
|
|
|
Load the rsa key previously created with `creatersakey` command.
|
|
|
|
"""
|
2015-07-14 16:01:29 +00:00
|
|
|
file_path = settings.get('OIDC_RSA_KEY_FOLDER') + '/OIDC_RSA_KEY.pem'
|
2015-07-14 18:01:01 +00:00
|
|
|
try:
|
|
|
|
with open(file_path, 'r') as f:
|
|
|
|
key = f.read()
|
|
|
|
except IOError:
|
|
|
|
raise IOError('We could not find your key file on: ' + file_path)
|
2015-07-13 20:36:15 +00:00
|
|
|
|
|
|
|
return key
|
2015-08-11 18:58:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DefaultUserInfo(object):
|
2016-01-12 18:17:22 +00:00
|
|
|
"""
|
|
|
|
Default class for setting OIDC_USERINFO.
|
|
|
|
"""
|
2015-08-11 18:58:52 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_by_user(cls, user):
|
|
|
|
return None
|
2016-01-12 18:17:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def default_sub_generator(user):
|
|
|
|
"""
|
|
|
|
Default function for setting OIDC_IDTOKEN_SUB_GENERATOR.
|
|
|
|
"""
|
|
|
|
return str(user.id)
|
2016-01-19 20:37:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def default_after_userlogin_hook(request, user, client):
|
|
|
|
"""
|
|
|
|
Default function for setting OIDC_AFTER_USERLOGIN_HOOK.
|
|
|
|
"""
|
|
|
|
return None
|