Simple OTP lib for OpenResty
- base32_encode
- base32_decode
- TOTP
HOTP
localmodule_otp=require ("otp")
localOTP=module_otp.totp_init("JBSWY3DPEHPK3PXP")
ngx.say("TOTP_Token -> ", OTP:calc_token())Output
TOTP_Token -> 123456
localOTP=module_otp.totp_init("JBSWY3DPEHPK3PXP")
localurl=OTP:get_qr_url('OpenResty-TOTP', 'hello@example.com')
localhtml=[[<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
localmodule_otp=require ("otp")
localOTP=module_otp.totp_init("JBSWY3DPEHPK3PXP")
localtoken=ngx.var.arg_otpngx.say("Verify Token : ", OTP:verify_token(token))Use OTP from Google Authenticator
curl localhost/check?otp=734923Output
Verify Token : true
Thanks! alues