Skip to content

Commit

Permalink
make plugin_id to be foreign key
Browse files Browse the repository at this point in the history
  • Loading branch information
vm-001 committed May 8, 2023
1 parent b82859a commit a86239d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions kong/plugins/oauth2/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ local function authorize(conf)
scope = scopes,
challenge = challenge,
challenge_method = challenge_method,
plugin_id = kong.plugin.get_id(),
plugin = { id = kong.plugin.get_id() },
}, {
ttl = 300
})
Expand Down Expand Up @@ -645,9 +645,9 @@ local function issue_token(conf)
end

if not response_params[ERROR] and conf.global_credentials then
-- verify only if plugin_id is present to avoid existing codes being fails
if auth_code.plugin_id and
(kong.plugin.get_id() ~= auth_code.plugin_id) then
-- verify only if plugin is present to avoid existing codes being fails
if auth_code.plugin and
(kong.plugin.get_id() ~= auth_code.plugin.id) then
response_params = {
[ERROR] = "invalid_request",
error_description = "Invalid " .. CODE
Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/oauth2/daos.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ local oauth2_authorization_codes = {
{ scope = { type = "string" }, },
{ challenge = { type = "string", required = false }},
{ challenge_method = { type = "string", required = false, one_of = { "S256" } }},
{ plugin_id = { type = "string", required = false } },
{ plugin = { type = "foreign", reference = "plugins", default = ngx.null, on_delete = "cascade", }, },
},
}

Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/oauth2/migrations/007_320_to_330.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ return {
up = [[
DO $$
BEGIN
ALTER TABLE IF EXISTS ONLY "oauth2_authorization_codes" ADD "plugin_id" uuid;
ALTER TABLE IF EXISTS ONLY "oauth2_authorization_codes" ADD "plugin_id" UUID REFERENCES "plugins" ("id") ON DELETE CASCADE;
EXCEPTION WHEN DUPLICATE_COLUMN THEN
-- Do nothing, accept existing state
END$$;
Expand Down
2 changes: 1 addition & 1 deletion spec/03-plugins/25-oauth2/03-access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2821,7 +2821,7 @@ describe("Plugin: oauth2 [#" .. strategy .. "]", function()
local code = provision_code("oauth2_16.com")
local db_code, err = db.oauth2_authorization_codes:select_by_code(code)
assert.is_nil(err)
db_code.plugin_id = ngx.null
db_code.plugin = ngx.null
local _, _, err = db.oauth2_authorization_codes:update({ id = db_code.id }, db_code)
assert.is_nil(err)
local res = assert(proxy_ssl_client:send {
Expand Down

0 comments on commit a86239d

Please sign in to comment.