Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(plugins/oauth): use encode_base64url in resty.core #12069

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions kong/plugins/oauth2/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local error = error
local split = utils.split
local strip = utils.strip
local string_find = string.find
local string_gsub = string.gsub
--local string_gsub = string.gsub
local string_byte = string.byte
local check_https = utils.check_https
local encode_args = utils.encode_args
Expand All @@ -25,7 +25,6 @@ local table_contains = utils.table_contains
local ngx_decode_args = ngx.decode_args
local ngx_re_gmatch = ngx.re.gmatch
local ngx_decode_base64 = ngx.decode_base64
local ngx_encode_base64 = ngx.encode_base64


local _M = {}
Expand Down Expand Up @@ -60,22 +59,26 @@ local AUTHENTICATED_USERID = "authenticated_userid"
local base64url_encode
local base64url_decode
do
local BASE64URL_ENCODE_CHARS = "[+/]"
local BASE64URL_ENCODE_SUBST = {
["+"] = "-",
["/"] = "_",
}
local rep = string.rep
local b64 = require "ngx.base64"

base64url_encode = function(value)
value = ngx_encode_base64(value, true)
if not value then
return nil
local encode_base64url = b64.encode_base64url
local decode_base64url = b64.decode_base64url

base64url_encode = encode_base64url

base64url_decode = function(input)
local remainder = #input % 4

if remainder > 0 then
local padlen = 4 - remainder
input = input .. rep("=", padlen)
end

return string_gsub(value, BASE64URL_ENCODE_CHARS, BASE64URL_ENCODE_SUBST)
return decode_base64url(input)
end


--[[
local BASE64URL_DECODE_CHARS = "[-_]"
local BASE64URL_DECODE_SUBST = {
["-"] = "+",
Expand All @@ -86,6 +89,7 @@ do
value = string_gsub(value, BASE64URL_DECODE_CHARS, BASE64URL_DECODE_SUBST)
return ngx_decode_base64(value)
end
--]]
end


Expand Down
Loading