nginx-lua-oauth2

一个用于 OAuth 2.0 的 Nginx Lua 插件

$ opm get Valdanitooooo/nginx-lua-oauth2

nginx-lua-oauth2

用于 OAuth2 认证的 nginx 模块

  1. 安装 lua-cjson 和 nginx-extras

    sudo apt install lua-cjson nginx-extras

  1. 安装此库

    sudo cp -r nginx-lua-oauth2.lua resty /usr/share/lua/5.1/

  1. 将此内容放入您的 nginx 配置文件

        location /auth/ {
            resolver 8.8.8.8 8.8.4.4;
            lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
            access_by_lua_block {
                require("nginx-lua-oauth2").auth({
                    client_id = "dd9323ac-1bf8-45d1-806b-09b45e4d989f",
                    client_secret = "APwi9H4yOXMJ+NGeie/n8kXVBzry2misJi1fxrFNcRk=",
                    token_url = "https://login.windows.net/8371d803-6f9a-46e1-a8ae-eec4a1998cbd/oauth2/token",
                    authorize_url = "https://login.windows.net/8371d803-6f9a-46e1-a8ae-eec4a1998cbd/oauth2/authorize",
                    token_params = { resource = 'https://graph.windows.net/' }, # optional!
                    authorize_params = { resource = 'https://graph.windows.net/' }, # optional!
                    ssl_verify = true # optional
                })
            }
        }
  1. 尽情享受。

当前的 access_token / refresh_token 可以通过读取

cookie "oauth2_access_token" 或 "oauth2_refresh_token" 获取

作者

valdanito

许可证

apache2

依赖

版本