Mercurial > prosody-modules
comparison mod_unified_push/mod_unified_push.lua @ 5150:2b6c543c4d3a
mod_unified_push: Fixes for paseto backend initialization
Now generates and stores a random key automatically.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 14 Jan 2023 15:32:24 +0000 |
| parents | fa56ed2bacab |
| children | 514c8a0e9aa1 |
comparison
equal
deleted
inserted
replaced
| 5149:fa56ed2bacab | 5150:2b6c543c4d3a |
|---|---|
| 67 end | 67 end |
| 68 push_store:set(reg_id, data); | 68 push_store:set(reg_id, data); |
| 69 return reg_id; | 69 return reg_id; |
| 70 end; | 70 end; |
| 71 verify = function (token) | 71 verify = function (token) |
| 72 if token == "_private" then return nil, "invalid-token"; end | |
| 72 local data = push_store:get(token); | 73 local data = push_store:get(token); |
| 73 if not data then | 74 if not data then |
| 74 return nil, "item-not-found"; | 75 return nil, "item-not-found"; |
| 75 elseif data.exp and data.exp < os.time() then | 76 elseif data.exp and data.exp < os.time() then |
| 76 push_store:set(token, nil); | 77 push_store:set(token, nil); |
| 79 return data; | 80 return data; |
| 80 end; | 81 end; |
| 81 }; | 82 }; |
| 82 }; | 83 }; |
| 83 | 84 |
| 84 if pcall(require, "util.paseto") then | 85 if pcall(require, "util.paseto") and require "util.paseto".v3_local then |
| 85 local sign, verify = require "util.paseto".init(unified_push_secret); | 86 local paseto = require "util.paseto".v3_local; |
| 87 local state = push_store:get("_private"); | |
| 88 local key = state and state.paseto_v3_local_key; | |
| 89 if not key then | |
| 90 key = paseto.new_key(); | |
| 91 push_store:set("_private", { paseto_v3_local_key = key }); | |
| 92 end | |
| 93 local sign, verify = paseto.init(key); | |
| 86 backends.paseto = { sign = sign, verify = verify }; | 94 backends.paseto = { sign = sign, verify = verify }; |
| 87 end | 95 end |
| 88 | 96 |
| 89 local backend = module:get_option_string("unified_push_backend", backends.paseto and "paseto" or "storage"); | 97 local backend = module:get_option_string("unified_push_backend", backends.paseto and "paseto" or "storage"); |
| 90 | 98 |
