Skip to content

Commit

Permalink
feat(base): Enforceable SSO ONLY
Browse files Browse the repository at this point in the history
this setting removes the login form and forces a redirect to the SSO signin page.

!20 #1
  • Loading branch information
jon-nfc committed Jun 7, 2024
1 parent 3040d4a commit b38984f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#
DEBUG = False # SECURITY WARNING: don't run with debug turned on in production!
SSO_ENABLED = False # Enable SSO
SSO_LOGIN_ONLY_BACKEND = None # Use specified SSO backend as the ONLY method to login. (builting login form will not be used)

ALLOWED_HOSTS = [ '*' ]

Expand Down Expand Up @@ -258,6 +259,9 @@

if SSO_ENABLED:

if SSO_LOGIN_ONLY_BACKEND:
LOGIN_URL = f'/sso/login/{SSO_LOGIN_ONLY_BACKEND}/'

AUTHENTICATION_BACKENDS += (
*SSO_BACKENDS,
)
Expand Down
12 changes: 9 additions & 3 deletions app/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% load settings_value %}
{% settings_value "SSO_LOGIN_ONLY_BACKEND" as SSO_LOGIN_ONLY_BACKEND %}
<html>

<head>
Expand All @@ -6,14 +8,18 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

{% if SSO_LOGIN_ONLY_BACKEND %}
<meta http-equiv="refresh" content="0; url=/{{ settings.LOGIN_URL }}" />
{% else %}
<link rel="stylesheet" href="{% static 'base.css' %}">
<link rel="stylesheet" href="{% static 'content.css' %}">
<link rel="stylesheet" href="{% static 'data.css' %}">

{% endif %}
</head>

<body style="background-color: #393f44">


{% if not SSO_LOGIN_ONLY_BACKEND %}
<div style="height: 100%; width: 100%;">

<div style="display: block; text-align: center; inline-size: auto; margin: auto; background-color: #26292d; margin-top: -185px; height: 370px; margin-left: -272px; width: 544px; position: absolute; top: 50%; left: 50%; padding: 40px">
Expand All @@ -29,8 +35,8 @@
{% endfor %}
</form>
</div>

</div>
{% endif %}

</body>

Expand Down
4 changes: 3 additions & 1 deletion docs/projects/django-template/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This page details the configuration for setting up the application.

- `SSO_ENABLED`, boolean

Single Sign on (SSO) is made possible through the [social django application](https://python-social-auth.readthedocs.io/en/latest/configuration/django.html). Specific configuration for the backend that you would like to configure can be viewed within it's [documentation](https://python-social-auth.readthedocs.io/en/latest/backends/index.html). In most cases the only configuration will need to be done for the following attributes: `SSO_ENABLED`, `SSO_BACKENDS` and `SOCIAL_AUTH_`.
Single Sign on (SSO) is made possible through the [social django application](https://python-social-auth.readthedocs.io/en/latest/configuration/django.html). Specific configuration for the backend that you would like to configure can be viewed within it's [documentation](https://python-social-auth.readthedocs.io/en/latest/backends/index.html). In most cases the only configuration that will need to be defined are for the following attributes: `SSO_ENABLED`, optionally `SSO_BACKENDS` and those with prefix `SOCIAL_AUTH_`.

!!! danger
Within the social django documentation, it will state the the configuration key for the backends is within attribute `AUTHENTICATION_BACKENDS`, don't use this attribute. Instead use attribute `SSO_BACKENDS` so as not to effect the authentication of the ITSM application.
Expand All @@ -27,6 +27,8 @@ Attributes with prefix `SSO_` are specifically for this application.

SSO_ENABLED = True # Optional, boolean. Enable SSO Authentication

SSO_LOGIN_ONLY_BACKEND = 'oidc' # Optional, string. To only use SSO authentication, specify the backend name here

SSO_BACKENDS = ( # this attribute replaces `AUTHENTICATION_BACKENDS` and must be used instead of.
"social_core.backends.open_id_connect.OpenIdConnectAuth",
)
Expand Down
2 changes: 1 addition & 1 deletion docs/projects/django-template/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Settings for the application are stored within a docker volume at path `/etc/its

### Settings file

The settings file is a python file `.py` and must remain a valid python file for the application to work.
The settings file is a python file `.py` and must remain a valid python file for the application to work.

``` py title="settings.py"

Expand Down

0 comments on commit b38984f

Please sign in to comment.