# HG changeset patch # User Matthew Wild # Date 1673368461 0 # Node ID 449e4ca4de32839e4789c8c1e403a7ac5abbf2d4 # Parent 4511e90d1d0864b476a2493dd3b9b4f82ae4bb33 mod_unified_push: Remove dependency on trunk util.jwt (0.12 compat) This should allow the module to work on 0.12, while preserving expiry checking (which was not built in to 0.12's util.jwt). diff -r 4511e90d1d08 -r 449e4ca4de32 mod_unified_push/README.md --- a/mod_unified_push/README.md Tue Jan 10 16:07:00 2023 +0000 +++ b/mod_unified_push/README.md Tue Jan 10 16:34:21 2023 +0000 @@ -56,4 +56,5 @@ ## Compatibility -Requires Prosody trunk (not compatible with 0.12). +| trunk | Works | +| 0.12 | Should work | diff -r 4511e90d1d08 -r 449e4ca4de32 mod_unified_push/mod_unified_push.lua --- a/mod_unified_push/mod_unified_push.lua Tue Jan 10 16:07:00 2023 +0000 +++ b/mod_unified_push/mod_unified_push.lua Tue Jan 10 16:34:21 2023 +0000 @@ -4,7 +4,7 @@ local base64 = require "util.encodings".base64; local datetime = require "util.datetime"; local id = require "util.id"; -local jwt_sign, jwt_verify = require "util.jwt".init("HS256", unified_push_secret); +local jwt = require "util.jwt"; local st = require "util.stanza"; local urlencode = require "util.http".urlencode; @@ -23,6 +23,23 @@ return s; end +-- COMPAT w/0.12 +local function jwt_sign(data) + return jwt.sign(data, unified_push_secret); +end + +-- COMPAT w/0.12: add expiry check +local function jwt_verify(token) + local ok, result = jwt.verify(token, unified_push_secret); + if not ok then + return ok, result; + end + if result.exp and result.exp < os.time() then + return nil, "token-expired"; + end + return ok, result; +end + -- Handle incoming registration from XMPP client function handle_register(event) local origin, stanza = event.origin, event.stanza;