修改oauth2.0中authorize认证接口错误问题,增加生成验证码图标测试
This commit is contained in:
parent
836d908f4c
commit
7c22e73f66
|
|
@ -13,12 +13,6 @@ local routes = {
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
------------ OIDC OAuth2.0认证相关路由配置 ---
|
------------ OIDC OAuth2.0认证相关路由配置 ---
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
--OP端点配置
|
|
||||||
{
|
|
||||||
paths = { "/yum/v1/.well-known/openid-configuration" },
|
|
||||||
methods = { "GET", "POST" },
|
|
||||||
handler = oauthService.openidConfig,
|
|
||||||
},
|
|
||||||
--获取授权码
|
--获取授权码
|
||||||
{
|
{
|
||||||
paths = { "/yum/v1/oauth/v2/authorize" },
|
paths = { "/yum/v1/oauth/v2/authorize" },
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,10 @@ end
|
||||||
--根据客户端id和重定向地址获取应用程序
|
--根据客户端id和重定向地址获取应用程序
|
||||||
function _M.getApplicationByClientId(client_id, redirect_uri)
|
function _M.getApplicationByClientId(client_id, redirect_uri)
|
||||||
--print("getApplicationByClientId client_id:", client_id, " redirect_uri:", redirect_uri)
|
--print("getApplicationByClientId client_id:", client_id, " redirect_uri:", redirect_uri)
|
||||||
return applicationModel:where('app_id', '=', client_id):where('redirect_uris', '=', redirect_uri):get()
|
if redirect_uri == nil then
|
||||||
|
return applicationModel:where('client_id', '=', client_id):get()
|
||||||
|
end
|
||||||
|
return applicationModel:where('client_id', '=', client_id):where('redirect_uri', '=', redirect_uri):get()
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M.getApplicationByUserid(user_id, client_id, client_secret)
|
function _M.getApplicationByUserid(user_id, client_id, client_secret)
|
||||||
|
|
|
||||||
|
|
@ -45,18 +45,18 @@ function _M:authorize()
|
||||||
local ok = validator.validateAuthorize(args)
|
local ok = validator.validateAuthorize(args)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
return ngx.exit(ngx.HTTP_BAD_REQUEST)
|
ngx.exit(ngx.HTTP_BAD_REQUEST)
|
||||||
end
|
end
|
||||||
-- 校验 response_type 必须为 "code"(授权码模式)
|
-- 校验 response_type 必须为 "code"(授权码模式)
|
||||||
if args.response_type ~= "code" then
|
if args.response_type ~= "code" then
|
||||||
return ngx.exit(ngx.HTTP_BAD_REQUEST)
|
ngx.exit(ngx.HTTP_BAD_REQUEST)
|
||||||
end
|
end
|
||||||
-- 1、校验客户端id和redirect_uri是否存在数据库
|
-- 1、校验客户端id和redirect_uri是否存在数据库
|
||||||
local client_id = args.client_id
|
local client_id = args.client_id
|
||||||
local redirect_uri = args.redirect_uri
|
local redirect_uri = args.redirect_uri
|
||||||
local code, res = oauthDao.getApplicationBy(client_id)
|
local code, res = oauthDao.getApplicationBy(client_id)
|
||||||
if code ~= 0 or not res then
|
if code ~= 0 or not res then
|
||||||
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
|
ngx.exit(ngx.HTTP_UNAUTHORIZED)
|
||||||
end
|
end
|
||||||
--判断redirect_uri是否在重定向组里面
|
--判断redirect_uri是否在重定向组里面
|
||||||
local redirect_uris = res[1].redirect_uri
|
local redirect_uris = res[1].redirect_uri
|
||||||
|
|
@ -75,7 +75,7 @@ function _M:authorize()
|
||||||
--local login_url = "/login?redirect=" .. ngx.escape_uri(ngx.var.request_uri)
|
--local login_url = "/login?redirect=" .. ngx.escape_uri(ngx.var.request_uri)
|
||||||
--print("authorize login_url:", login_url)
|
--print("authorize login_url:", login_url)
|
||||||
--ngx.redirect(login_url)
|
--ngx.redirect(login_url)
|
||||||
resp:response(ngx.HTTP_MOVED_TEMPORARILY, login_url)
|
resp:response(status.USER_NOT_LOGIN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- 4. 生成授权码(随机字符串,确保唯一性)(用户ID、客户端ID、scope、生成时间)
|
-- 4. 生成授权码(随机字符串,确保唯一性)(用户ID、客户端ID、scope、生成时间)
|
||||||
|
|
|
||||||
|
|
@ -38,20 +38,19 @@ if not ok then
|
||||||
end
|
end
|
||||||
|
|
||||||
function enabled(res, desc)
|
function enabled(res, desc)
|
||||||
local str = " " .. desc .. " "
|
local str = " " .. desc .. " "
|
||||||
str = str .. string.rep(".", 37 - string.len(str))
|
str = str .. string.rep(".", 37 - string.len(str))
|
||||||
if res then
|
if res then
|
||||||
print(str .. " Enabled")
|
ngx.say(str .. " Enabled")
|
||||||
else
|
else
|
||||||
print(str .. " Disabled")
|
ngx.say(str .. " Disabled")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print("Lua-GD version: " .. gd.VERSION)
|
ngx.say("Lua-GD version: " .. gd.VERSION)
|
||||||
print("Lua-GD features:")
|
ngx.say("Lua-GD features:")
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
local gd = require("gd")
|
|
||||||
local iSeed = os.time() + os.clock() * 10000
|
local iSeed = os.time() + os.clock() * 10000
|
||||||
math.randomseed(iSeed)
|
math.randomseed(iSeed)
|
||||||
|
|
||||||
|
|
@ -83,7 +82,10 @@ print("")
|
||||||
io.write(im:pngStr())
|
io.write(im:pngStr())
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
--[[
|
local uuid = require("util.uuid")
|
||||||
|
local uid = uuid.generateUuid()
|
||||||
|
ngx.say("uuid:"..uid)
|
||||||
|
|
||||||
local genpic = require("util.generatechaptcha")
|
local genpic = require("util.generatechaptcha")
|
||||||
local filename, fp = genpic.getChaptcha()
|
local filename, fp = genpic.getChaptcha()
|
||||||
--redis中添加picgid为key,string为value的记录
|
--redis中添加picgid为key,string为value的记录
|
||||||
|
|
@ -95,9 +97,8 @@ ngx.header.picgid = filename
|
||||||
--页面返回pic
|
--页面返回pic
|
||||||
ngx.say(fp)
|
ngx.say(fp)
|
||||||
--nginx退出
|
--nginx退出
|
||||||
ngx.exit(200)
|
--ngx.exit(200)
|
||||||
--]]
|
--do return end
|
||||||
do return end
|
|
||||||
|
|
||||||
--local openssl = require("openssl")
|
--local openssl = require("openssl")
|
||||||
--
|
--
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,9 @@ function _M.getChaptcha()
|
||||||
end
|
end
|
||||||
|
|
||||||
--图片基本info
|
--图片基本info
|
||||||
|
|
||||||
local uid = uuid.generateUuid()
|
local uid = uuid.generateUuid()
|
||||||
--picgid
|
--picgid
|
||||||
local filename = "1"..uuid..".png"
|
local filename = "1"..uid..".png"
|
||||||
--图片78x26
|
--图片78x26
|
||||||
local xsize = 78
|
local xsize = 78
|
||||||
local ysize = 26
|
local ysize = 26
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user