Compare commits

...

2 Commits

3 changed files with 21 additions and 13 deletions

View File

@ -56,7 +56,7 @@ http {
access_by_lua_block { access_by_lua_block {
ngx.header["Access-Control-Allow-Origin"] = "*"; ngx.header["Access-Control-Allow-Origin"] = "*";
ngx.header["Access-Control-Allow-Methods"] = "GET, POST, DELETE, PUT"; ngx.header["Access-Control-Allow-Methods"] = "GET, POST, DELETE, PUT";
ngx.header["Access-Control-Allow-Headers"] = "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range"; 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; ngx.header["Access-Control-Max-Age"] = 1728000;
ngx.header["Access-Control-Expose-Headers"] = "Content-Length,Content-Range"; ngx.header["Access-Control-Expose-Headers"] = "Content-Length,Content-Range";
if ngx.var.request_method == "OPTIONS" then if ngx.var.request_method == "OPTIONS" then

View File

@ -47,17 +47,17 @@ function _M:getUserByUsername(username)
end end
-- 查询数据表中的所有用户信息 -- 查询数据表中的所有用户信息
function _M.getSystemUsers(pageNum, pageSize) function _M:getSystemUsers(pageNum, pageSize)
return userModel:paginate(pageNum, pageSize) return userModel:paginate(pageNum, pageSize)
end end
--根据用户id获取用户信息 --根据用户id获取用户信息
function _M.getSystemUser(id) function _M:getSystemUser(id)
return userModel:find(id) return userModel:find(id)
end end
--增加用户信息到数据表 --增加用户信息到数据表
function _M.addSystemUser(jsonData) function _M:addSystemUser(jsonData)
if jsonData == nil or jsonData == "" then if jsonData == nil or jsonData == "" then
return 0x000001, nil return 0x000001, nil
end end

View File

@ -12,6 +12,7 @@ local rsa = require("util.rsa")
local authcode = require("util.authcode") local authcode = require("util.authcode")
local token = require("util.token") local token = require("util.token")
local client = require("util.client") local client = require("util.client")
local conf = require("config")
local _M = {} local _M = {}
@ -151,17 +152,19 @@ local function authorizateCode(args)
return return
end end
-- 4.生成密钥对 -- 4.生成密钥对
local pub_key, priv_key, err = rsa.generate_rsa_keys(2048) --local pub_key, priv_key, err = rsa.generate_rsa_keys(2048)
if err then --if err then
print("密钥生成失败: ", err) -- print("密钥生成失败: ", err)
local result = resp:json(0x00001) -- local result = resp:json(0x00001)
resp:send(result) -- resp:send(result)
return -- return
end --end
print("token pubkey:", pub_key) --print("token pubkey:", pub_key)
local priv_key = conf.secret_key
local user_id = code_data.user_id local user_id = code_data.user_id
local client_id = code_data.client_id local client_id = code_data.client_id
local scope = code_data.scope local scope = code_data.scope
print("authorizateCode user_id:", user_id, " client_id:", client_id)
-- 5.生成新 Access Token -- 5.生成新 Access Token
local new_access_token = token.generate_access_token(priv_key, user_id, client_id, scope) local new_access_token = token.generate_access_token(priv_key, user_id, client_id, scope)
-- 生成新 Refresh Token滚动刷新 -- 生成新 Refresh Token滚动刷新
@ -249,6 +252,7 @@ function _M:userinfo()
--end --end
-- 4.对token进行验证 -- 4.对token进行验证
--print("userinfo pubkey:", pub_key) --print("userinfo pubkey:", pub_key)
local pub_key = conf.secret_key
local jwt_obj = jwt:verify(pub_key, token) local jwt_obj = jwt:verify(pub_key, token)
--如果校验结果中的verified==false则表示令牌无效 --如果校验结果中的verified==false则表示令牌无效
if jwt_obj.verified == false then if jwt_obj.verified == false then
@ -264,10 +268,14 @@ function _M:userinfo()
ngx.exit(ngx.HTTP_UNAUTHORIZED) ngx.exit(ngx.HTTP_UNAUTHORIZED)
end end
--通过用户id获取用户信息 --通过用户id获取用户信息
print("-- get jwt_obj.payload value --")
for key, value in pairs(jwt_obj.payload) do
print("jwt_obj.payload: ", key, " ", value)
end
local user_id = jwt_obj.payload.sub local user_id = jwt_obj.payload.sub
local code, rest = oauthDao.getUser(user_id) local code, rest = oauthDao.getUser(user_id)
--读取数据错误 --读取数据错误
if code ~= 0 or table.getn(ret) < 0 then if code ~= 0 or rest == nil then
local result = resp:json(0x000001) local result = resp:json(0x000001)
resp:send(result) resp:send(result)
return return