Skip to content

Commit 8faed83

Browse files
committed
Merge branch 'master' of github.com:knaperek/djangosaml2 into ACS_customizable
# Conflicts: # djangosaml2/views.py
2 parents 162abf6 + 9700447 commit 8faed83

File tree

20 files changed

+684
-364
lines changed

20 files changed

+684
-364
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: djangosaml2
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: [3.6, 3.7, 3.8]
19+
django-version: ["2.2", "3.0", "master"]
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v1
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
- name: Install dependencies and testing utilities
28+
run: |
29+
sudo apt-get update && sudo apt-get install xmlsec1
30+
python -m pip install --upgrade pip tox rstcheck setuptools codecov
31+
- name: Readme check
32+
if: ${{ matrix.python-version }} == 3.8 && ${{ matrix.django-version }} == "3.0"
33+
run: rstcheck README.rst
34+
- name: Tests
35+
run: tox -e py${{ matrix.python-version }}-django${{ matrix.django-version }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
db.sqlite3
12
.tox/
23
*.pyc
34
*.egg-info
@@ -12,3 +13,5 @@ venv
1213
tags
1314
.idea/
1415
.vscode/
16+
build/
17+
dist/

.travis.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

CHANGES

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
Changes
22
=======
3+
4+
0.19.0 (2020-05-x)
5+
------------------
6+
7+
- Support several required fields during User creation
8+
- Don't pass sigalg parameter when not signing login request
9+
- ALLOW_SAML_HOSTNAMES validation for redirect
10+
- Custom attribute mapping for Django user model (example)
11+
- Slo absence workaround
12+
- Metadata EntityID exception handling
13+
- Fix unsigned authentication request to POST endpoint
14+
- py38 Test fixes
15+
- CI with Github actions
16+
- Backend restructuring for easier subclassing
17+
318
0.18.1 (2020-02-15)
419
----------
520
- Fixed regression from 0.18.0. Thanks to OskarPersson

README.rst

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
djangosaml2
33
===========
44

5-
.. image:: https://travis-ci.org/knaperek/djangosaml2.svg?branch=master
6-
:target: https://travis-ci.org/knaperek/djangosaml2
7-
:align: left
5+
.. image:: https://github.com/knaperek/djangosaml2/workflows/djangosaml2/badge.svg
6+
:target: https://github.com/knaperek/djangosaml2/workflows/djangosaml2/badge.svg
87

98

10-
djangosaml2 is a Django application that integrates the PySAML2 library
11-
into your project. This mean that you can protect your Django based project
12-
with a service provider based on PySAML. This way it will talk SAML2 with
9+
A Django application that builds a Fully Compliant SAML2 Service Provider on top of PySAML2 library.
10+
This mean that you can protect your Django based project
11+
with a SAML2 SSO Authentication. This way it will talk SAML2 with
1312
your Identity Provider allowing you to use this authentication mechanism.
1413
This document will guide you through a few simple steps to accomplish
1514
such goal.
@@ -82,15 +81,9 @@ A typical configuration would look like this::
8281
'djangosaml2.backends.Saml2Backend',
8382
)
8483

85-
.. note::
86-
87-
Before djangosaml2 0.5.0 this authentication backend was
88-
automatically added by djangosaml2. This turned out to be
89-
a bad idea since some applications want to use their own
90-
custom policies for authorization and the authentication
91-
backend is a good place to define that. Starting from
92-
djangosaml2 0.5.0 it is now possible to define such
93-
backends.
84+
It is possible to subclass the provided Saml2Backend and customize the behaviour
85+
by overriding some methods. This way you can perform your custom cleaning or authorization
86+
policy, and modify the way users are looked up and created.
9487

9588
Finally we have to tell Django what the new login url we want to use is::
9689

@@ -113,6 +106,24 @@ If you want to allow several authentication mechanisms in your project
113106
you should set the LOGIN_URL option to another view and put a link in such
114107
view to the ``/saml2/login/`` view.
115108

109+
Handling Post-Login Redirects
110+
-----------------------------
111+
It is often desireable for the client to maintain the URL state (or at least manage it) so that
112+
the URL once authentication has completed is consistent with the desired application state (such
113+
as retaining query parameters, etc.) By default, the HttpRequest objects get_host() method is used
114+
to determine the hostname of the server, and redirect URL's are allowed so long as the destination
115+
host matches the output of get_host(). However, in some cases it becomes desireable for additional
116+
hostnames to be used for the post-login redirect. In such cases, the setting::
117+
118+
SAML_ALLOWED_HOSTS = []
119+
120+
May be set to a list of allowed post-login redirect hostnames (note, the URL components beyond the hostname
121+
may be specified by the client - typically with the ?next= parameter.)
122+
123+
In the absence of a ?next= parameter, the LOGIN_REDIRECT_URL setting will be used (assuming the destination hostname
124+
either matches the output of get_host() or is included in the SAML_ALLOWED_HOSTS setting)
125+
126+
116127
Preferred Logout binding
117128
------------------------
118129
Use the following setting to choose your preferred binding for SP initiated logout requests::
@@ -206,6 +217,7 @@ We will see a typical configuration for protecting a Django project::
206217
'optional_attributes': ['eduPersonAffiliation'],
207218

208219
# in this section the list of IdPs we talk to are defined
220+
# This is not mandatory! All the IdP available in the metadata will be considered.
209221
'idp': {
210222
# we do not need a WAYF service since there is
211223
# only an IdP defined here. This IdP should be
@@ -320,7 +332,7 @@ Custom error handler
320332

321333
When an error occurs during the authentication flow, djangosaml2 will render
322334
a simple error page with an error message and status code. You can customize
323-
this behaviour by specifying the path to your own error handler in the settings:
335+
this behaviour by specifying the path to your own error handler in the settings::
324336

325337
SAML_ACS_FAILURE_RESPONSE_FUNCTION = 'python.path.to.your.view'
326338

@@ -377,10 +389,12 @@ can set in the settings.py file::
377389

378390
This setting is True by default.
379391

392+
The following setting lets you specify a URL for redirection after a successful
393+
authentication::
394+
380395
ACS_DEFAULT_REDIRECT_URL = reverse_lazy('some_url_name')
381396

382-
This setting lets you specify a URL for redirection after a successful
383-
authentication. Particularly useful when you only plan to use
397+
Particularly useful when you only plan to use
384398
IdP initiated login and the IdP does not have a configured RelayState
385399
parameter. The default is ``/``.
386400

@@ -524,9 +538,18 @@ following url::
524538
Now if you go to the /test/ url you will see your SAML attributes and also
525539
a link to do a global logout.
526540

527-
You can also run the unit tests with the following command::
541+
Unit tests
542+
==========
528543

544+
You can also run the unit tests as follows::
545+
546+
pip install -r requirements-dev.txt
547+
python3 tests/manage.py migrate
548+
529549
python tests/run_tests.py
550+
# or
551+
python tests/manage.py test -v 3
552+
530553

531554
If you have `tox`_ installed you can simply call tox inside the root directory
532555
and it will run the tests in multiple versions of Python.

0 commit comments

Comments
 (0)