修改oauth2.0中authorize认证接口错误问题,增加生成验证码图标测试

This commit is contained in:
wanglei 2025-11-21 11:30:30 +08:00
parent 836d908f4c
commit 7c22e73f66
5 changed files with 24 additions and 27 deletions

View File

@ -13,12 +13,6 @@ local routes = {
--------------------------------------------
------------ OIDC OAuth2.0认证相关路由配置 ---
--------------------------------------------
--OP端点配置
{
paths = { "/yum/v1/.well-known/openid-configuration" },
methods = { "GET", "POST" },
handler = oauthService.openidConfig,
},
--获取授权码
{
paths = { "/yum/v1/oauth/v2/authorize" },

View File

@ -100,7 +100,10 @@ end
--根据客户端id和重定向地址获取应用程序
function _M.getApplicationByClientId(client_id, 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
function _M.getApplicationByUserid(user_id, client_id, client_secret)

View File

@ -45,18 +45,18 @@ function _M:authorize()
local ok = validator.validateAuthorize(args)
--验证失败则返回
if not ok then
return ngx.exit(ngx.HTTP_BAD_REQUEST)
ngx.exit(ngx.HTTP_BAD_REQUEST)
end
-- 校验 response_type 必须为 "code"(授权码模式)
if args.response_type ~= "code" then
return ngx.exit(ngx.HTTP_BAD_REQUEST)
ngx.exit(ngx.HTTP_BAD_REQUEST)
end
-- 1、校验客户端id和redirect_uri是否存在数据库
local client_id = args.client_id
local redirect_uri = args.redirect_uri
local code, res = oauthDao.getApplicationBy(client_id)
if code ~= 0 or not res then
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
ngx.exit(ngx.HTTP_UNAUTHORIZED)
end
--判断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)
--print("authorize login_url:", login_url)
--ngx.redirect(login_url)
resp:response(ngx.HTTP_MOVED_TEMPORARILY, login_url)
resp:response(status.USER_NOT_LOGIN)
return
end
-- 4. 生成授权码随机字符串确保唯一性用户ID、客户端ID、scope、生成时间

View File

@ -38,20 +38,19 @@ if not ok then
end
function enabled(res, desc)
local str = " " .. desc .. " "
str = str .. string.rep(".", 37 - string.len(str))
if res then
print(str .. " Enabled")
else
print(str .. " Disabled")
end
local str = " " .. desc .. " "
str = str .. string.rep(".", 37 - string.len(str))
if res then
ngx.say(str .. " Enabled")
else
ngx.say(str .. " Disabled")
end
end
print("Lua-GD version: " .. gd.VERSION)
print("Lua-GD features:")
ngx.say("Lua-GD version: " .. gd.VERSION)
ngx.say("Lua-GD features:")
--[[
local gd = require("gd")
local iSeed = os.time() + os.clock() * 10000
math.randomseed(iSeed)
@ -83,7 +82,10 @@ print("")
io.write(im:pngStr())
--]]
--[[
local uuid = require("util.uuid")
local uid = uuid.generateUuid()
ngx.say("uuid:"..uid)
local genpic = require("util.generatechaptcha")
local filename, fp = genpic.getChaptcha()
--redis中添加picgid为key,string为value的记录
@ -95,9 +97,8 @@ ngx.header.picgid = filename
--页面返回pic
ngx.say(fp)
--nginx退出
ngx.exit(200)
--]]
do return end
--ngx.exit(200)
--do return end
--local openssl = require("openssl")
--

View File

@ -19,10 +19,9 @@ function _M.getChaptcha()
end
--图片基本info
local uid = uuid.generateUuid()
--picgid
local filename = "1"..uuid..".png"
local filename = "1"..uid..".png"
--图片78x26
local xsize = 78
local ysize = 26