Mercurial > prosody-modules
changeset 4734:e58ec4b3cf90
mod_rest: Add an anonymous mode
Could be useful for a demo instance.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 01 Nov 2021 15:08:21 +0100 |
parents | 755dd83e9214 |
children | 58a20d5ac6e9 |
files | mod_rest/mod_rest.lua |
diffstat | 1 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_rest/mod_rest.lua Wed Oct 27 20:54:54 2021 +0200 +++ b/mod_rest/mod_rest.lua Mon Nov 01 15:08:21 2021 +0100 @@ -58,6 +58,16 @@ return nil; end +if module:get_option_string("authentication") == "anonymous" and module:get_option_boolean("anonymous_rest") then + www_authenticate_header = nil; + function check_credentials(request) -- luacheck: ignore 212/request + return { + username = id.medium():lower(); + host = module.host; + } + end +end + -- (table, string) -> table local function amend_from_path(data, path) local st_kind, st_type, st_to = path:match("^([mpi]%w+)/(%w+)/(.*)$"); @@ -233,7 +243,7 @@ local echo = path == "echo"; if echo then path = nil; end - if not request.headers.authorization then + if not request.headers.authorization and www_authenticate_header then response.headers.www_authenticate = www_authenticate_header; return post_errors.new("noauthz"); else