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
|
|
|
|
|
|
|
|
|
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
|
2016-02-12 16:02:35 +00:00
|
|
|
|
2016-02-17 22:23:10 +00:00
|
|
|
def default_idtoken_processing_hook(id_token, user):
|
2016-02-12 16:02:35 +00:00
|
|
|
"""
|
|
|
|
Hook to perform some additional actions ti `id_token` dictionary just before serialization.
|
|
|
|
|
|
|
|
:param id_token: dictionary contains values that going to be serialized into `id_token`
|
|
|
|
:type id_token: dict
|
2016-02-17 22:23:10 +00:00
|
|
|
:param user: user instance
|
2016-02-12 16:02:35 +00:00
|
|
|
:return: custom modified dictionary of values for `id_token`
|
|
|
|
:rtype dict
|
|
|
|
"""
|
|
|
|
return id_token
|