Simple OTP lib for OpenResty
- base32_encode
- base32_decode
- TOTP
HOTP
local module_otp = require ("otp")
local OTP = module_otp.totp_init("JBSWY3DPEHPK3PXP")
ngx.say("TOTP_Token -> ", OTP:calc_token())
Output
TOTP_Token -> 123456
local OTP = module_otp.totp_init("JBSWY3DPEHPK3PXP")
local url = OTP:get_qr_url('OpenResty-TOTP', 'hello@example.com')
local html = [[
<img src='%s' />
]]
html = string.format(html, url)
ngx.header['Content-Type'] = 'text/html'
ngx.say(html)
Output
Scan the QR Code with Google Authenticator
local module_otp = require ("otp")
local OTP = module_otp.totp_init("JBSWY3DPEHPK3PXP")
local token = ngx.var.arg_otp
ngx.say("Verify Token : ", OTP:verify_token(token))
Use OTP from Google Authenticator
curl localhost/check?otp=734923
Output
Verify Token : true
Thanks! alues