Skip to content

alues/otp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published

Languages