Skip to content

Commit

Permalink
Add a new setting to redirect unknown URLs to either the SSO portal o…
Browse files Browse the repository at this point in the history
…r a 404 page
  • Loading branch information
Salamandar committed Mar 10, 2023
1 parent fa8be37 commit 0b7ab46
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ Whether authentication should use secure connection or not (**default**: `https`

---------------

### err404_to_portal

Wether to redirect unknown URLs to the portal or to a 404 page (**default**: `true`).

---------------

### domains

List of handled domains (**default**: similar to `portal_domain`).
Expand Down
10 changes: 8 additions & 2 deletions access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,15 @@ for permission_name, permission_infos in pairs(conf["permissions"]) do
end
end

---
--- 5. REDIRECT TO 404 PAGE IF UNKNOWN URL -> PORTAL IS DISABLED
---
if not conf["err404_to_portal"] and longest_url_match == "" then
return ngx.exit(ngx.HTTP_NOT_FOUND)
end

---
--- 5. CHECK CLIENT-PROVIDED AUTH HEADER (should almost never happen?)
--- 6. CHECK CLIENT-PROVIDED AUTH HEADER (should almost never happen?)
---

if permission ~= nil then
Expand All @@ -336,7 +342,7 @@ end

--
--
-- 6. APPLY PERMISSION
-- 7. APPLY PERMISSION
--
--

Expand Down
3 changes: 2 additions & 1 deletion conf.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@
},
"portal_domain": "example.tld",
"portal_path": "/yunohost/sso/",
"err404_to_portal": true,
"redirected_regex": {
"example.tld/yunohost[\\/]?$": "https://example.tld/yunohost/sso/"
},
"redirected_urls": {}
}
}
3 changes: 2 additions & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function get_config()
-- If the timestamp of the modification or the size is different, reload the configuration.
config_attributes = new_config_attributes
config_persistent_attributes = new_config_persistent_attributes

local conf_file = assert(io.open(conf_path, "r"), "Configuration file is missing")
conf = json.decode(conf_file:read("*all"))
conf_file:close()
Expand Down Expand Up @@ -83,6 +83,7 @@ function get_config()
default_conf = {
portal_scheme = "https",
portal_path = "/ssowat/",
err404_to_portal = true,
local_portal_domain = "yunohost.local",
domains = { conf["portal_domain"], "yunohost.local" },
session_timeout = 60 * 60 * 24, -- one day
Expand Down

0 comments on commit 0b7ab46

Please sign in to comment.