Compare commits
6 Commits
3dd877c837
...
919e5812f9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
919e5812f9 | ||
|
|
ef5a02baea | ||
|
|
8a994fe9d6 | ||
|
|
6e8d06dad3 | ||
|
|
35e0c0b362 | ||
|
|
e4eef5f4b8 |
|
|
@ -13,7 +13,7 @@ http {
|
||||||
client_max_body_size 1024M; #允许最大100k的请求体
|
client_max_body_size 1024M; #允许最大100k的请求体
|
||||||
client_body_buffer_size 1024M; #设置缓冲区大小
|
client_body_buffer_size 1024M; #设置缓冲区大小
|
||||||
|
|
||||||
#lua_code_cache off; #关闭代码缓存,修改lua脚本不需要重启
|
lua_code_cache on; #代码缓存
|
||||||
|
|
||||||
lua_package_path '$prefix/src/?/?.lua;$prefix/src/?.lua;/home/frankly/work/AuthPlatform/src/?/?.lua;/home/frankly/work/AuthPlatform/src/?.lua;;';
|
lua_package_path '$prefix/src/?/?.lua;$prefix/src/?.lua;/home/frankly/work/AuthPlatform/src/?/?.lua;/home/frankly/work/AuthPlatform/src/?.lua;;';
|
||||||
lua_package_cpath '$prefix/src/share/lib/?.so;/home/frankly/work/AuthPlatform/src/share/lib/?.so;;';
|
lua_package_cpath '$prefix/src/share/lib/?.so;/home/frankly/work/AuthPlatform/src/share/lib/?.so;;';
|
||||||
|
|
@ -52,17 +52,13 @@ http {
|
||||||
## 应用路径 todo 路径问题
|
## 应用路径 todo 路径问题
|
||||||
set $APP_PATH '/home/frankly/work/AuthPlatform';
|
set $APP_PATH '/home/frankly/work/AuthPlatform';
|
||||||
|
|
||||||
#访问时允许跨域处理
|
# 全局 CORS 配置 访问时允许跨域处理
|
||||||
access_by_lua_block {
|
add_header Access-Control-Allow-Origin *;
|
||||||
ngx.header["Access-Control-Allow-Origin"] = "*";
|
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';
|
||||||
ngx.header["Access-Control-Allow-Methods"] = "GET, POST, DELETE, PUT";
|
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
|
||||||
ngx.header["Access-Control-Allow-Headers"] = "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization";
|
|
||||||
ngx.header["Access-Control-Max-Age"] = 1728000;
|
if ($request_method = 'OPTIONS') {
|
||||||
ngx.header["Access-Control-Expose-Headers"] = "Content-Length,Content-Range";
|
return 204;
|
||||||
if ngx.var.request_method == "OPTIONS" then
|
|
||||||
ngx.status = 204
|
|
||||||
ngx.exit(ngx.OK)
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#OP端点配置
|
#OP端点配置
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ local jwt = require "resty.jwt"
|
||||||
local cjson = require("cjson.safe")
|
local cjson = require("cjson.safe")
|
||||||
local jsonschema = require("jsonschema")
|
local jsonschema = require("jsonschema")
|
||||||
local conf = require("config")
|
local conf = require("config")
|
||||||
|
local status = require("util.status")
|
||||||
|
local resp = require("util.response")
|
||||||
|
|
||||||
-- 定义一个JSON Schema
|
-- 定义一个JSON Schema
|
||||||
local schema = {
|
local schema = {
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ local function authorizatePassword(args)
|
||||||
-- 2.验证用户名和密码,应用程序id和应用程序密钥
|
-- 2.验证用户名和密码,应用程序id和应用程序密钥
|
||||||
local code, res = oauthDao.authenticateUserPasswd(args.username, args.password)
|
local code, res = oauthDao.authenticateUserPasswd(args.username, args.password)
|
||||||
if code ~= 0 or res == nil then
|
if code ~= 0 or res == nil then
|
||||||
resp:response(status.ACCOUNT_NOT_EXIST)
|
resp:response(status.USER_LOGIN_ERROR)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
print("验证用户名和密码: ", args.username)
|
print("验证用户名和密码: ", args.username)
|
||||||
|
|
@ -139,9 +139,10 @@ local function authorizateCode(args)
|
||||||
-- 1.校验必填参数验证数据是否符合json
|
-- 1.校验必填参数验证数据是否符合json
|
||||||
local ok = validator.validateToken(args)
|
local ok = validator.validateToken(args)
|
||||||
if not ok then
|
if not ok then
|
||||||
resp:response(status.TOKEN_INVALID)
|
resp:response(status.PARAM_IS_INVALID)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
print("consume code:", args.code)
|
||||||
-- 2.校验 code 有效性
|
-- 2.校验 code 有效性
|
||||||
local code_data, err = authcode.consume(args.code)--, args.client_id)
|
local code_data, err = authcode.consume(args.code)--, args.client_id)
|
||||||
if not code_data then
|
if not code_data then
|
||||||
|
|
@ -234,6 +235,9 @@ end
|
||||||
function _M:token()
|
function _M:token()
|
||||||
-- 1. 解析请求参数(支持 form-data 和 json)
|
-- 1. 解析请求参数(支持 form-data 和 json)
|
||||||
local args = getUriArgs()
|
local args = getUriArgs()
|
||||||
|
if args == nil then
|
||||||
|
ngx.exit(ngx.HTTP_BAD_REQUEST)
|
||||||
|
end
|
||||||
local grant_type = args.grant_type
|
local grant_type = args.grant_type
|
||||||
--print("grant_type类型: ", grant_type)
|
--print("grant_type类型: ", grant_type)
|
||||||
if grant_type == "password" then
|
if grant_type == "password" then
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,9 @@ function _M.getSystemDepartments()
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code, ret = departmentDao.getSystemDepartments()
|
local code, ret = departmentDao.getSystemDepartments()
|
||||||
resp:response(code, ret)
|
local state = status.SUCCESS
|
||||||
|
if code ~= 0 then state = status.DATA_IS_WRONG end
|
||||||
|
resp: response(state, ret)
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据组织id获取组织架构信息
|
--根据组织id获取组织架构信息
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ function _M.getSystemUser(m)
|
||||||
local code, ret = userDao.getSystemUser(m.id)
|
local code, ret = userDao.getSystemUser(m.id)
|
||||||
local state = status.SUCCESS
|
local state = status.SUCCESS
|
||||||
if code ~= 0 then state = status.DATA_IS_WRONG end
|
if code ~= 0 then state = status.DATA_IS_WRONG end
|
||||||
resp: response(state, ret)
|
resp:response(state, ret)
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据用户id获取用户信息
|
--根据用户id获取用户信息
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,18 @@ local id = snow:generateUniqueId()-- 生成ID
|
||||||
|
|
||||||
--max =a and b or c--a?b:c
|
--max =a and b or c--a?b:c
|
||||||
|
|
||||||
|
local STATUS_CODE = {
|
||||||
|
-- 成功状态码
|
||||||
|
SUCCESS = { code = 200, message = "操作成功" },
|
||||||
|
UNKNOWN_ERROR = { code = 9999, message = "未知错误" }
|
||||||
|
}
|
||||||
|
|
||||||
|
local val = STATUS_CODE.SUCCESS
|
||||||
|
local status = val or STATUS_CODE.UNKNOWN_ERROR
|
||||||
|
local msg = status.message
|
||||||
|
ngx.say("message:"..msg)
|
||||||
|
|
||||||
|
|
||||||
--local openssl = require("openssl")
|
--local openssl = require("openssl")
|
||||||
--
|
--
|
||||||
---- 生成RSA密钥对
|
---- 生成RSA密钥对
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ function _M:json(state, message, data, http_status)
|
||||||
msg = status.message
|
msg = status.message
|
||||||
end
|
end
|
||||||
local response = { code = code, msg = msg, result = data, timestamp = ngx.time() }
|
local response = { code = code, msg = msg, result = data, timestamp = ngx.time() }
|
||||||
|
print("response:", cjson.encode(response))
|
||||||
return {
|
return {
|
||||||
code = response_status,
|
code = response_status,
|
||||||
headers = { content_type = 'application/json; charset=UTF-8' },
|
headers = { content_type = 'application/json; charset=UTF-8' },
|
||||||
|
|
@ -27,6 +28,7 @@ function _M:json(state, data, http_status)
|
||||||
local msg = status.message
|
local msg = status.message
|
||||||
local response_status = http_status or ngx.HTTP_OK
|
local response_status = http_status or ngx.HTTP_OK
|
||||||
local response = { code = code, msg = msg, result = data,timestamp = ngx.time() }
|
local response = { code = code, msg = msg, result = data,timestamp = ngx.time() }
|
||||||
|
--print("response:", cjson.encode(response))
|
||||||
return {
|
return {
|
||||||
code = response_status,
|
code = response_status,
|
||||||
headers = { content_type = 'application/json; charset=UTF-8' },
|
headers = { content_type = 'application/json; charset=UTF-8' },
|
||||||
|
|
@ -59,14 +61,16 @@ function _M:send(response)
|
||||||
ngx.header[name] = value
|
ngx.header[name] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--print("send data:", response.body)
|
||||||
if response.body ~= nil then
|
if response.body ~= nil then
|
||||||
|
--print("send data:", response.body)
|
||||||
ngx.say(response.body)
|
ngx.say(response.body)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M:response(state, result)
|
function _M:response(state, result)
|
||||||
local response = self:json(state, result)
|
local resp = self:json(state, result)
|
||||||
self:send(response)
|
self:send(resp)
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user