@@ -16,12 +16,6 @@ local resty_session = require "resty.session"
16
16
local t = require (" api-umbrella.web-app.utils.gettext" ).gettext
17
17
local table_keys = require (" pl.tablex" ).keys
18
18
19
- require " resty.session.ciphers.api_umbrella"
20
- require " resty.session.hmac.api_umbrella"
21
- require " resty.session.identifiers.api_umbrella"
22
- require " resty.session.storage.api_umbrella_db"
23
- require " resty.session.serializers.api_umbrella"
24
-
25
19
local supported_languages = table_keys (LOCALE_DATA )
26
20
27
21
-- Custom error handler so we only show the default lapis debug details in
78
72
-- server-side control on expiring sessions, and it can't be spoofed even with
79
73
-- knowledge of the encryption secret key.
80
74
local session_db_options = {
81
- storage = " api_umbrella_db" ,
82
- cipher = " api_umbrella" ,
83
- hmac = " api_umbrella" ,
84
- serializer = " api_umbrella" ,
85
- identifier = " api_umbrella" ,
86
- name = " _api_umbrella_session" ,
75
+ storage = " postgres" ,
76
+ postgres = pg_utils .db_config ,
87
77
secret = assert (config [" secret_key" ]),
88
- random = {
89
- length = 40 ,
90
- },
91
- cookie = {
92
- samesite = " Lax" ,
93
- secure = true ,
94
- httponly = true ,
95
- idletime = 30 * 60 , -- 30 minutes
96
- lifetime = 12 * 60 * 60 , -- 12 hours
97
- renew = - 1 , -- Disable renew
98
- },
78
+ cookie_name = " _api_umbrella_session" ,
79
+ cookie_same_site = " Lax" ,
80
+ cookie_secure = true ,
81
+ cookie_http_only = true ,
82
+ idling_timeout = 30 * 60 , -- 30 minutes
83
+ absolute_timeout = 12 * 60 * 60 , -- 12 hours
99
84
}
100
85
local function init_session_db (self )
101
86
if not self .session_db then
113
98
-- session records in the database for the CSRF token).
114
99
local session_cookie_options = {
115
100
storage = " cookie" ,
116
- cipher = " api_umbrella" ,
117
- hmac = " api_umbrella" ,
118
- serializer = " api_umbrella" ,
119
- identifier = " api_umbrella" ,
120
- name = " _api_umbrella_session_client" ,
121
101
secret = assert (config [" secret_key" ]),
122
- random = {
123
- length = 40 ,
124
- },
125
- cookie = {
126
- samesite = " Lax" ,
127
- secure = true ,
128
- httponly = true ,
129
- lifetime = 48 * 60 * 60 , -- 48 hours
130
- renew = 1 * 60 * 60 , -- 1 hour
131
- },
102
+ cookie_name = " _api_umbrella_session_client" ,
103
+ cookie_same_site = " Lax" ,
104
+ cookie_secure = true ,
105
+ cookie_http_only = true ,
106
+ rolling_timeout = 1 * 60 * 60 , -- 1 hour
107
+ absolute_timeout = 48 * 60 * 60 , -- 48 hours
132
108
}
133
109
local function init_session_cookie (self )
134
110
if not self .session_cookie then
@@ -139,17 +115,19 @@ end
139
115
local function current_admin_from_session (self )
140
116
local current_admin
141
117
self :init_session_db ()
142
- local _ , _ , open_err = self .session_db :start ()
143
- if open_err then
118
+ local _ , open_err = self .session_db :open ()
119
+ if open_err and open_err ~= " missing session cookie " then
144
120
if open_err == " session cookie idle time has passed" or open_err == " session cookie has expired" then
145
121
flash .session (self , " info" , t (" Your session expired. Please sign in again to continue." ))
146
122
else
147
123
ngx .log (ngx .ERR , " session open error: " , open_err )
148
124
end
125
+
126
+ return nil
149
127
end
150
128
151
- if self . session_db and self .session_db . data and self . session_db . data [ " admin_id" ] then
152
- local admin_id = self . session_db . data [ " admin_id " ]
129
+ local admin_id = self .session_db : get ( " admin_id" )
130
+ if admin_id then
153
131
local admin = Admin :find ({ id = admin_id })
154
132
if admin and not admin :is_access_locked () then
155
133
current_admin = admin
0 commit comments