simple-sso/src/ssso_sessions.lua

36 lines
778 B
Lua
Raw Normal View History

local crypto = require("ssso_crypto")
2021-09-02 22:58:01 +02:00
local login = require("ssso_login")
local nginx = require("ssso_nginx")
local function get_session()
2021-10-02 23:45:31 +02:00
local profile, jws, tslimit
2021-09-02 22:58:01 +02:00
local user, password = nginx.get_basic_auth()
2021-09-02 22:58:01 +02:00
if user and password then
2021-10-02 23:45:31 +02:00
profile = login.check_credentials_and_get_profile(user, password)
if profile then
jws, tslimit = crypto.get_jws_and_tslimit(profile)
2021-09-02 22:58:01 +02:00
end
end
2021-10-02 23:45:31 +02:00
if not profile then
2021-09-02 22:58:01 +02:00
local cookie = nginx.get_jws_cookie()
if not cookie or cookie == "" then
return nil, 401
end
2021-10-02 23:45:31 +02:00
profile, jws, tslimit = crypto.get_profile_and_new_jws(cookie)
2021-09-02 22:58:01 +02:00
end
2021-10-02 23:45:31 +02:00
if profile then
nginx.set_jws_cookie(jws, tslimit)
2021-10-02 23:45:31 +02:00
return profile, 200
else
return nil, 403
end
end
return {
get_session = get_session,
}