Adds a setting variable for custom template paths
This commit is contained in:
parent
d5111ed881
commit
41003e1e83
4 changed files with 35 additions and 4 deletions
|
@ -176,3 +176,15 @@ Credentials Grant. https://tools.ietf.org/html/rfc6749#section-4.3
|
|||
decide what works best for you, so you will have to implement a solution for
|
||||
this that suits your needs.
|
||||
|
||||
OIDC_TEMPLATES
|
||||
==============
|
||||
OPTIONAL. A dictionary pointing to templates for authorize and error pages.
|
||||
Default is::
|
||||
|
||||
{
|
||||
'authorize': 'oidc_provider/authorize.html',
|
||||
'error': 'oidc_provider/error.html'
|
||||
}
|
||||
|
||||
.. note::
|
||||
The templates that are not specified here will use the default ones.
|
||||
|
|
|
@ -33,3 +33,6 @@ You can copy the sample html here and edit them with your own styles.
|
|||
|
||||
<h3>{{ error }}</h3>
|
||||
<p>{{ description }}</p>
|
||||
|
||||
You can also customize paths to your custom templates by putting them in ``OIDC_TEMPLATES`` in the settings.
|
||||
|
||||
|
|
|
@ -139,6 +139,13 @@ class DefaultSettings(object):
|
|||
"""
|
||||
return False
|
||||
|
||||
@property
|
||||
def OIDC_TEMPLATES(self):
|
||||
return {
|
||||
'authorize': 'oidc_provider/authorize.html',
|
||||
'error': 'oidc_provider/error.html'
|
||||
}
|
||||
|
||||
default_settings = DefaultSettings()
|
||||
|
||||
|
||||
|
@ -161,12 +168,19 @@ def get(name, import_str=False):
|
|||
Helper function to use inside the package.
|
||||
"""
|
||||
value = None
|
||||
default_value = getattr(default_settings, name)
|
||||
|
||||
try:
|
||||
value = getattr(default_settings, name)
|
||||
value = getattr(settings, name)
|
||||
except AttributeError:
|
||||
if value is None and name in default_settings.required_attrs:
|
||||
if name in default_settings.required_attrs:
|
||||
raise Exception('You must set ' + name + ' in your settings.')
|
||||
finally:
|
||||
if isinstance(default_value, dict) and value:
|
||||
default_value.update(value)
|
||||
value = default_value
|
||||
|
||||
value = value or default_value
|
||||
|
||||
value = import_from_str(value) if import_str else value
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@ from oidc_provider import signals
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
OIDC_TEMPLATES = settings.get('OIDC_TEMPLATES')
|
||||
|
||||
|
||||
class AuthorizeView(View):
|
||||
|
||||
|
@ -103,7 +105,7 @@ class AuthorizeView(View):
|
|||
'scopes': authorize.get_scopes_information(),
|
||||
}
|
||||
|
||||
return render(request, 'oidc_provider/authorize.html', context)
|
||||
return render(request, OIDC_TEMPLATES['authorize'], context)
|
||||
else:
|
||||
if authorize.params['prompt'] == 'none':
|
||||
raise AuthorizeError(authorize.params['redirect_uri'], 'login_required', authorize.grant_type)
|
||||
|
@ -116,7 +118,7 @@ class AuthorizeView(View):
|
|||
'description': error.description,
|
||||
}
|
||||
|
||||
return render(request, 'oidc_provider/error.html', context)
|
||||
return render(request, OIDC_TEMPLATES['error'], context)
|
||||
|
||||
except (AuthorizeError) as error:
|
||||
uri = error.create_uri(
|
||||
|
|
Loading…
Reference in a new issue