Skip to content

Commit

Permalink
Merge pull request #811 from GSA/flask-session
Browse files Browse the repository at this point in the history
keep session live for active user
  • Loading branch information
FuhuXia authored Feb 12, 2025
2 parents 67d62e2 + 185b6c8 commit 336e976
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
7 changes: 5 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ DB_CKAN_PASSWORD=pass
DB_CKAN_DB=ckan

CKAN___SECRET_KEY=CHANGE_ME
CKAN___BEAKER__SESSION__URL=postgresql://ckan:ckan@db/ckan
CKAN___BEAKER__SESSION__SECRET=CHANGE_ME

# uncomment to have session behave same as apps on cloud.gov
# CKAN___SESSION_PERMANENT=False
# CKAN___PERMANENT_SESSION_LIFETIME=900

CKAN___WTF_CSRF_SECRET_KEY=CHANGE_ME
# See https://docs.ckan.org/en/latest/maintaining/configuration.html#api-token-settings
CKAN___API_TOKEN__JWT__ENCODE__SECRET=string:CHANGE_ME
Expand Down
8 changes: 7 additions & 1 deletion ckanext/datagov_inventory/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ckan.plugins.toolkit import config
import ckan.authz as authz

from flask import Blueprint, redirect
from flask import Blueprint, redirect, session
import logging
import re

Expand Down Expand Up @@ -131,3 +131,9 @@ def check_dataset_access():
if toolkit.request.path in ('/dataset/', '/dataset'):
if not current_user.is_authenticated and not g.user:
return base.render(u'error/anonymous.html'), 403


@pusher.before_app_request
def refresh_session():
""" Refresh session expiration time on each request """
session.modified = True
14 changes: 2 additions & 12 deletions config/ckan.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,9 @@ ckanext.datajson.inventory_links_enabled = True
ckanext.datajson.export_map_filename = export.inventory.map.sample.json
ckanext.datajson.url_enabled = False

# This is the secret token that the beaker library uses to hash the cookie sent
# to the client. `ckan make-config` generates a unique value for this each
# time it generates a config file.
beaker.session.secret = $CKAN___BEAKER__SESSION__SECRET

beaker.session.type=ext:database
beaker.session.cookie_expires=true
beaker.session.secure = True
beaker.session.samesite = Lax
#beaker.session.url = $CKAN___BEAKER__SESSION__URL
# 900 seconds = 15 mins
beaker.session.timeout=900
beaker.session.lock_dir=/var/tmp/ckan/lock
SESSION_PERMANENT=False
PERMANENT_SESSION_LIFETIME=900

# `paster make-config` generates a unique value for this each time it generates
# a config file.
Expand Down

0 comments on commit 336e976

Please sign in to comment.