-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
90 lines (69 loc) · 3.25 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
----------------------------------------------------
Django identity.external middlewares
----------------------------------------------------
Set of middlewares to simplify consumption of external identity
information in Web projects set up with Django Web framework.
---------------------------------------------------
identity.external.PersistentRemoteUserMiddlewareVar
When non-standard (different than REMOTE_USER) environment variable is
used to pass information about externally authenticated user, this
middleware can be used to customize the variable name without writing
Python code.
For example, when consuming the information from some authentication
HTTP proxy, HTTP request header values are passed as HTTP_-prefixed
environment variables. If the authenticated user name is in
X-Remote-User HTTP request header, it is available in HTTP_X_REMOTE_USER
environment variable. Setting variable REMOTE_USER_VAR to
HTTP_X_REMOTE_USER, for example with Apache HTTP Server directive
SetEnv REMOTE_USER_VAR HTTP_X_REMOTE_USER
and enabling identity.external.PersistentRemoteUserMiddlewareVar in
MIDDLEWARE list after
django.contrib.auth.middleware.AuthenticationMiddleware like
MIDDLEWARE = [
...
'django.contrib.auth.middleware.AuthenticationMiddleware',
'identity.external.PersistentRemoteUserMiddlewareVar',
...
]
will run django.contrib.auth.middleware.PersistentRemoteUserMiddleware
with value from environment variable HTTP_X_REMOTE_USER.
------------------------------------------
identity.external.RemoteUserAttrMiddleware
When user is externally authenticated, for example via
django.contrib.auth.middleware.RemoteUserMiddleware or
django.contrib.auth.middleware.PersistentRemoteUserMiddleware, additional
user attributes can be provided by the external authentication source.
This middleware will update user's email address, first and last name,
and group membership in groups prefixed with ext: with information coming
from environment variables
REMOTE_USER_EMAIL
REMOTE_USER_FIRSTNAME
REMOTE_USER_LASTNAME
REMOTE_USER_GROUP_N
REMOTE_USER_GROUP_1, REMOTE_USER_GROUP_2, ...
REMOTE_USER_GROUPS
where the REMOTE_USER prefix of these variables can be changed with the
REMOTE_USER_VAR environment variable, just like with
identity.external.PersistentRemoteUserMiddlewareVar.
The values are used verbating, as provided by Django. When
REMOTE_USER_VALUES_ENCODING environment variable is set to base64url,
the values are expected to be in this format and decoded to Unicode.
Users that are in external group admins (and thus get assigned to group
ext:admins in Django) will also get the is_staff flag set and thus will be
able to log in to the admin application.
The ext: prefixed groups have to be already created in Django database for
the user membership to be updated in them.
In the MIDDLEWARE list, this middleware has to be listed after the
authenticating middleware, for example
MIDDLEWARE = [
...
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.PersistentRemoteUserMiddleware',
'identity.external.RemoteUserAttrMiddleware',
...
]
--------
See also
External authentication for Django projects
Presentation at EuroPython 2015
https://www.adelton.com/django/external-authentication-for-django-projects