Mercurial > prosody-modules
comparison mod_rest/mod_rest.lua @ 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 | e6f46d1b3337 |
children | 58a20d5ac6e9 |
comparison
equal
deleted
inserted
replaced
4733:755dd83e9214 | 4734:e58ec4b3cf90 |
---|---|
54 return false; | 54 return false; |
55 end | 55 end |
56 return token_info.session; | 56 return token_info.session; |
57 end | 57 end |
58 return nil; | 58 return nil; |
59 end | |
60 | |
61 if module:get_option_string("authentication") == "anonymous" and module:get_option_boolean("anonymous_rest") then | |
62 www_authenticate_header = nil; | |
63 function check_credentials(request) -- luacheck: ignore 212/request | |
64 return { | |
65 username = id.medium():lower(); | |
66 host = module.host; | |
67 } | |
68 end | |
59 end | 69 end |
60 | 70 |
61 -- (table, string) -> table | 71 -- (table, string) -> table |
62 local function amend_from_path(data, path) | 72 local function amend_from_path(data, path) |
63 local st_kind, st_type, st_to = path:match("^([mpi]%w+)/(%w+)/(.*)$"); | 73 local st_kind, st_type, st_to = path:match("^([mpi]%w+)/(%w+)/(.*)$"); |
231 local from; | 241 local from; |
232 local origin; | 242 local origin; |
233 local echo = path == "echo"; | 243 local echo = path == "echo"; |
234 if echo then path = nil; end | 244 if echo then path = nil; end |
235 | 245 |
236 if not request.headers.authorization then | 246 if not request.headers.authorization and www_authenticate_header then |
237 response.headers.www_authenticate = www_authenticate_header; | 247 response.headers.www_authenticate = www_authenticate_header; |
238 return post_errors.new("noauthz"); | 248 return post_errors.new("noauthz"); |
239 else | 249 else |
240 origin = check_credentials(request); | 250 origin = check_credentials(request); |
241 if not origin then | 251 if not origin then |