Skip to content
Snippets Groups Projects
Verified Commit e54bc82e authored by nd's avatar nd
Browse files

add support for a session timeout

parent 05579748
No related branches found
No related tags found
No related merge requests found
Pipeline #6115 failed
...@@ -16,9 +16,16 @@ def create_app(test_config=None): ...@@ -16,9 +16,16 @@ def create_app(test_config=None):
# oauthlib enforces the OAuth2.0 requirement to use HTTPS, when this is not set # oauthlib enforces the OAuth2.0 requirement to use HTTPS, when this is not set
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' # That behaviour sucks, so disable it os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' # That behaviour sucks, so disable it
def session_valid():
if not session.get('user_id'):
return False
if datetime.datetime.now().timestamp() > session['logintime'] + current_app.config['SESSION_LIFETIME_SECONDS']:
return False
return True
@app.route("/auth") @app.route("/auth")
def auth(): def auth():
if not session.get('user_id'): if not session_valid():
abort(401) abort(401)
resp = Response('Ok', 200) resp = Response('Ok', 200)
resp.headers['OAUTH-USER-ID'] = session['user_id'] resp.headers['OAUTH-USER-ID'] = session['user_id']
...@@ -38,6 +45,7 @@ def create_app(test_config=None): ...@@ -38,6 +45,7 @@ def create_app(test_config=None):
client = get_oauth() client = get_oauth()
url, state = client.authorization_url(app.config['OAUTH2_AUTH_URL']) url, state = client.authorization_url(app.config['OAUTH2_AUTH_URL'])
session['state'] = state session['state'] = state
session['logintime'] = datetime.datetime.now().timestamp()
parts = request.full_path.split('?rawurl=', 1) parts = request.full_path.split('?rawurl=', 1)
if len(parts) == 2: if len(parts) == 2:
session['url'] = parts[1] session['url'] = parts[1]
......
...@@ -12,3 +12,4 @@ OAUTH2_USERINFO_URL = 'http://localhost:5001/oauth2/userinfo' ...@@ -12,3 +12,4 @@ OAUTH2_USERINFO_URL = 'http://localhost:5001/oauth2/userinfo'
SESSION_COOKIE_SECURE=True SESSION_COOKIE_SECURE=True
SESSION_COOKIE_HTTPONLY=True SESSION_COOKIE_HTTPONLY=True
SESSION_COOKIE_SAMESITE='Strict' SESSION_COOKIE_SAMESITE='Strict'
SESSION_LIFETIME_SECONDS=3600
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment