Skip to content

Latest commit

 

History

History
64 lines (48 loc) · 1.2 KB

README.md

File metadata and controls

64 lines (48 loc) · 1.2 KB

Simple OTP lib for OpenResty

  • base32_encode
  • base32_decode
  • TOTP
  • HOTP

Calculate token

    local module_otp = require ("otp")
    local OTP = module_otp.totp_init("JBSWY3DPEHPK3PXP")
    ngx.say("TOTP_Token -> ", OTP:calc_token())

Output

    TOTP_Token -> 123456

Generate QR Code

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

QR Code

Scan the QR Code with Google Authenticator


Verify OTP

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