Skip to content

Commit

Permalink
fix: revision
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeProgrammer committed Mar 25, 2022
1 parent b75286d commit 44e9d82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions apisix/plugins/authz-casdoor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ local _M = {
schema = schema
}

local function fetch_access_token(ctx, conf, state_in_session)
local args = core.request.get_uri_args(ctx)
local function fetch_access_token(code, conf)
local client = http.new()
local url = conf.endpoint_addr .. "/api/login/oauth/access_token"

local res, err = client:request_uri(url, {
method = "POST",
body = ngx.encode_args({
code = args.code,
code = code,
grant_type = "authorization_code",
client_id = conf.client_id,
client_secret = conf.client_secret
Expand Down Expand Up @@ -123,8 +121,13 @@ function _M.access(conf, ctx)
core.log.error(err)
return 400, err
end
if not args.code then
err = "invalid code"
core.log.error(err)
return 400, err
end
local access_token, lifetime, err =
fetch_access_token(ctx, conf, state_in_session)
fetch_access_token(args.code, conf)
if err then
core.log.error(err)
return 503
Expand Down
6 changes: 3 additions & 3 deletions t/plugin/authz-casdoor.t
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ done
}
}]]
)
if code ~= 200 then
if code >= 300 then
ngx.say("failed to set up routing rule")
end
ngx.say("done")
Expand Down Expand Up @@ -194,7 +194,7 @@ done
}]]
)
if code ~= 200 then
if code >= 300 then
ngx.status = code
end
ngx.say(body)
Expand Down Expand Up @@ -284,7 +284,7 @@ done
if not res3 then
ngx.say(err3)
end
if res3.status ~= 200 then
if res3.status >= 300 then
log.error(res3.status,res3.headers["Location"])
end
ngx.say("done")
Expand Down

0 comments on commit 44e9d82

Please sign in to comment.