File tree 2 files changed +26
-5
lines changed
2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -23,4 +23,16 @@ location /saml/ {
23
23
proxy_set_header X-Saml-Acs /saml/login;
24
24
proxy_pass http://saml:5000/;
25
25
}
26
- ```
26
+
27
+ location @error401 {
28
+ return 302 https://$http_host/saml/login?url=$request_uri;
29
+ }
30
+ ```
31
+
32
+ ## SECRET_KEY
33
+
34
+ This app wants an environment variable ` SECRET_KEY ` , which should be a secure,
35
+ randomly-generated string. Otherwise, we generate one on the fly, which only
36
+ works long as the app is running, and won't work in a distributed environment.
37
+ SECRET_KEY is used to sign cookies, so setting a new key effectively
38
+ invalidates all existing sessions.
Original file line number Diff line number Diff line change 5
5
from urllib .parse import urljoin
6
6
from datetime import timedelta
7
7
import os
8
- import uuid
8
+ import secrets
9
9
app = Flask (__name__ )
10
10
app .wsgi_app = ProxyFix (app .wsgi_app )
11
11
if os .environ .get ('SECRET_KEY' ):
12
12
app .secret_key = os .environ ['SECRET_KEY' ]
13
13
else :
14
14
app .logger .error ('Generating burner SECRET_KEY for demo purposes' )
15
- app .secret_key = str ( uuid . uuid1 () )
15
+ app .secret_key = secrets . token_urlsafe ( 32 )
16
16
app .config .update (
17
17
SESSION_COOKIE_NAME = '_saml_session' ,
18
18
SESSION_COOKIE_HTTPONLY = True ,
19
19
SESSION_COOKIE_SECURE = True ,
20
- PERMANENT_SESSION_LIFETIME = timedelta (minutes = 10 ) # TODO: refine this
20
+ PERMANENT_SESSION_LIFETIME = timedelta (hours = 12 )
21
21
)
22
22
23
+
23
24
@app .route ('/status' )
24
25
@app .route ('/status/group/<group>' )
25
26
def status (group = None ):
@@ -35,7 +36,7 @@ def status(group=None):
35
36
if not userid :
36
37
abort (401 )
37
38
if group and group not in groups :
38
- abort (403 )
39
+ abort (403 )
39
40
headers = {'X-Saml-User' : userid ,
40
41
'X-Saml-Groups' : ':' .join (groups )}
41
42
txt = f'Logged in as: { userid } \n Groups: { str (groups )} '
@@ -73,3 +74,11 @@ def login():
73
74
def logout ():
74
75
session .clear ()
75
76
return 'Logged out'
77
+
78
+
79
+ @app .route ('/' )
80
+ def healthz ():
81
+ """Return a 200 along with some useful links."""
82
+ return '''
83
+ <p><a href="login">Sign in</a></p><p><a href="logout">Logout</a></p>
84
+ '''
You can’t perform that action at this time.
0 commit comments