YLzone / lua-resty-otp

OTP for OpenResty

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Name

lua-resty-otp - Lua OTP lib for OpenResty

Table of Contents

Status

ci-ubuntu

This library is already usable though still highly experimental.

The Lua API is still in flux and may change in the near future without notice.

Back to TOC

Usage

Calculate OTP token

local lib_otp = require ("resty.otp")
local TOTP = lib_otp.totp_init("JBSWY3DPEHPK3PXP")
-- UTC format of date `20200101 00:00:00` -> 946656000
-- use `ngx.time()` instead of `946656000` in prod env
ngx.say("TOTP_Token -> ", TOTP:calc_token(946656000))

Output

458138

Back to TOC

Generate QR Code

local lib_otp = require ("resty.otp")
local TOTP = lib_otp.totp_init("JBSWY3DPEHPK3PXP")
local url = TOTP: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

Back to TOC

Verify OTP

local lib_otp = require ("resty.otp")
local TOTP = lib_otp.totp_init("JBSWY3DPEHPK3PXP")
local token = ngx.var.arg_otp
ngx.say("Verify Token : ", TOTP:verify_token(token))

Use OTP from Google Authenticator

curl localhost/check?otp=734923

Output

Verify Token : true

Back to TOC

Bugs and Patches

Please report bugs or submit patches by

  1. Creating a ticket on the GitHub Issue Tracker.

Back to TOC

About

OTP for OpenResty

License:Apache License 2.0


Languages

Language:Lua 38.8%Language:Shell 19.1%Language:Makefile 16.5%Language:Raku 15.2%Language:Perl 10.5%