forked from jitsi/luajwt
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample.lua
executable file
·40 lines (30 loc) · 858 Bytes
/
example.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env lua
local function t2s(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. t2s(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
--
local jwt = require "luajwtjitsi"
local key = "example_key"
local claim = {
iss = "12345678",
nbf = os.time(),
exp = os.time() + 3600,
}
local header = {
test = "test123"
}
local alg = "HS256" -- default alg
local token, err = jwt.encode(claim, key, alg, header)
print("Token:", token)
local validate = true -- validate exp and nbf (default: true)
local decoded, err = jwt.decode(token, key, validate)
print("Claim:", t2s(decoded) )