{"id":15349293,"url":"https://github.com/leslie-tsang/lua-resty-otp","last_synced_at":"2025-09-01T12:42:25.836Z","repository":{"id":41900821,"uuid":"422900668","full_name":"leslie-tsang/lua-resty-otp","owner":"leslie-tsang","description":"OTP for OpenResty","archived":false,"fork":false,"pushed_at":"2025-03-13T01:11:50.000Z","size":25,"stargazers_count":9,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T04:17:25.506Z","etag":null,"topics":["lua","lua-library","luajit","openresty","openresty-lua","openresty-module","otp","otp-library","otp-verification","otpauth","resty"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leslie-tsang.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-30T14:15:53.000Z","updated_at":"2025-04-02T11:38:36.000Z","dependencies_parsed_at":"2023-02-16T00:15:56.800Z","dependency_job_id":null,"html_url":"https://github.com/leslie-tsang/lua-resty-otp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leslie-tsang%2Flua-resty-otp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leslie-tsang%2Flua-resty-otp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leslie-tsang%2Flua-resty-otp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leslie-tsang%2Flua-resty-otp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leslie-tsang","download_url":"https://codeload.github.com/leslie-tsang/lua-resty-otp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249003972,"owners_count":21196793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lua","lua-library","luajit","openresty","openresty-lua","openresty-module","otp","otp-library","otp-verification","otpauth","resty"],"created_at":"2024-10-01T11:54:18.869Z","updated_at":"2025-04-15T04:17:30.745Z","avatar_url":"https://github.com/leslie-tsang.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"Name\n====\n\nlua-resty-otp - Lua OTP lib for OpenResty\n\n\nTable of Contents\n=================\n\n* [Name](#name)\n* [Status](#status)\n* [Usage](#usage)\n    * [Calculate OTP token](#calculate-otp-token)\n    * [Generate QR Code](#generate-qr-code)\n    * [Verify OTP](#verify-otp)\n* [Bugs and Patches](#bugs-and-patches)\n\nStatus\n======\n\n[![ci-ubuntu](https://github.com/leslie-tsang/lua-resty-otp/actions/workflows/ci-unit-test.yml/badge.svg)](https://github.com/leslie-tsang/lua-resty-otp/actions/workflows/ci-unit-test.yml)\n\nThis library is already usable though still highly experimental.\n\nThe Lua API is still in flux and may change in the near future without notice.\n\n[Back to TOC](#table-of-contents)\n\nUsage\n================\n## Calculate OTP token\n```lua\nlocal lib_otp = require (\"resty.otp\")\nlocal TOTP = lib_otp.totp_init(\"JBSWY3DPEHPK3PXP\")\n-- UTC format of date `20200101 00:00:00` -\u003e 946656000\n-- use `ngx.time()` instead of `946656000` in prod env\nngx.say(\"TOTP_Token -\u003e \", TOTP:calc_token(946656000))\n```\n\n\u003e Output\n\n```bash\n458138\n```\n\n[Back to TOC](#table-of-contents)\n\n## Generate QR Code\n```lua\nlocal lib_otp = require (\"resty.otp\")\nlocal TOTP = lib_otp.totp_init(\"JBSWY3DPEHPK3PXP\")\nlocal url = TOTP:get_qr_url('OpenResty-TOTP', 'hello@example.com')\nlocal html = [[\n\u003cimg src='%s' /\u003e\n]]\n\nhtml = string.format(html, url)\nngx.header['Content-Type'] = 'text/html'\nngx.say(html)\n```\n\n\u003e Output\n\n![QR Code](https://chart.googleapis.com/chart?chs=200x200\u0026cht=qr\u0026chl=200x200\u0026chld=M|0\u0026chl=otpauth%3A%2F%2Ftotp%2Fhello%40example.com%3Fsecret%3DJBSWY3DPEHPK3PXP%26issuer%3DOpenResty-TOTP)\n\nScan the QR Code with Google Authenticator\n\n[Back to TOC](#table-of-contents)\n\n## Verify OTP\n```lua\nlocal lib_otp = require (\"resty.otp\")\nlocal TOTP = lib_otp.totp_init(\"JBSWY3DPEHPK3PXP\")\nlocal token = ngx.var.arg_otp\nngx.say(\"Verify Token : \", TOTP:verify_token(token))\n```\n\nUse OTP from Google Authenticator\n\n```bash\ncurl localhost/check?otp=734923\n```\n\n\u003e Output\n\n```bash\nVerify Token : true\n```\n\n[Back to TOC](#table-of-contents)\n\nBugs and Patches\n================\n\nPlease report bugs or submit patches by\n\n1. Creating a ticket on the [GitHub Issue Tracker](https://github.com/leslie-tsang/lua-resty-otp/issues).\n\n[Back to TOC](#table-of-contents)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleslie-tsang%2Flua-resty-otp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleslie-tsang%2Flua-resty-otp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleslie-tsang%2Flua-resty-otp/lists"}