lua-resty-telegram-auth
用于 ngx_lua 模块的 Telegram 登录小部件
$ opm get iredun/lua-resty-telegram-auth
lua-resty-telegram-auth
lua-resty-telegram-auth 是一个模块,用于通过 Telegram 登录小部件 关闭对任何位置的访问。
免责声明
此模块为测试版,仅供娱乐,用于尝试使用新技术。在生产环境中使用,风险自负。
概要
worker_processes 1;
events {
worker_connections 1024;
}
http {
init_by_lua_block {
require "telegram-auth".init({
bot_token = "<BOT TOKEN>",
bot_username = "<BOT USERNAME WITHOUT @>",
user_ids = {"1", "2", "3"}
})
}
server {
listen 80;
charset utf-8;
location / {
default_type text/html;
access_by_lua_block {
local tg = require "telegram-auth"
tg.check_auth()
}
content_by_lua_block {
ngx.say("sensetive data")
}
}
location /telegram-auth {
default_type text/html;
content_by_lua_block {
local tg = require "telegram-auth"
tg.auth()
}
}
}
}
安装
使用 OpenResty 包管理器 (opm)
❯ opm get iredun/lua-resty-telegram-auth
lua-resty-telegram-auth
的 OPM 仓库位于 <https://opm.openresty.org.cn/package/iredun/lua-resty-telegram-auth/>。
使用 Nginx Lua 模块
首先,检查并安装所有依赖项
在 nginx.conf
中设置纯 Lua 外部库的搜索路径(';;' 为默认路径)
lua_package_path '/foo/bar/?.lua;/blah/?.lua;/path-to-module/lua-resty-telegram-auth/?.lua;;';
配置
这是一个示例
init_by_lua_block {
require "telegram-auth".init({
bot_token = "<BOT TOKEN>",
bot_username = "<BOT USERNAME WITHOUT @>",
user_ids = {"1", "2", "3"}
})
}
以下是可能的配置选项
| 选项 | 默认值 | 描述 | | --------------- | ---------------- | ----------------------------------------------- | | bot_token
| nil
| 您的 Telegram 机器人令牌 | | bot_username
| nil
| 您的 Telegram 机器人用户名(不含 @) | | auth_url
| /telegram-auth
| 重定向用户以显示身份验证页面的位置 | | auth_template
| auth.html
| 渲染身份验证页面的模板路径 | | user_ids
| {}
| 可以访问的用户 ID 列表 | | cookie_name
| tg-auth-string
| 用于存储 TG 数据的 Cookie 名称 |
身份验证模板上下文
在模板中,您可以访问变量
telgram_bot_username
callback_url
- 当前 URLauth_url
默认模板可以在 html/auth.html
中找到。
Cookie
在 Cookie 中,您可以获取包含用户信息的 JSON 数据。
{
"last_name": "Smith",
"id": "11111",
"photo_url": "<url>",
"auth_date": "1715359637",
"hash": "hash for check user data",
"username": "jsmith",
"first_name": "John"
}
开发者
您可以在 Docker 中启动基本示例,只需更改 nginx/default.conf
中的初始化设置并运行即可。
docker-compose up -d
作者
Ivan Redun (iredun)
许可证
3bsd
依赖项
版本
-
用于 ngx_lua 模块的 Telegram 登录小部件 2024-05-10 21:41:51