Skip to content

Commit ec83d6d

Browse files
author
ebarajas
committed
Add telekom-digioss#9 to handle breaking change
1 parent 27b550f commit ec83d6d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/handler.lua

+20-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local validate_realm_roles = require("kong.plugins.jwt-keycloak.validators.roles
1111
local validate_client_roles = require("kong.plugins.jwt-keycloak.validators.roles").validate_client_roles
1212

1313
local re_gmatch = ngx.re.gmatch
14+
local decode_base64 = ngx.decode_base64
1415

1516
local JwtKeycloakHandler = {
1617
VERSION = "1.2.1"
@@ -27,6 +28,24 @@ kong.log.debug('JWT_KEYCLOAK_PRIORITY: ' .. priority)
2728

2829
JwtKeycloakHandler.PRIORITY = priority
2930

31+
-------------------------------------------------------------------------------
32+
-- custom helper function of the extended plugin "jwt-keycloak"
33+
-- --> this is contained in jwt_parser, but has a breaking change in 3.5
34+
-- https://github.com/telekom-digioss/kong-plugin-jwt-keycloak/pull/9
35+
-------------------------------------------------------------------------------
36+
local function custom_base64_decode(input)
37+
local remainder = #input % 4
38+
if remainder > 0 then
39+
local padlen = 4 - remainder
40+
input = input .. rep("=", padlen)
41+
end
42+
43+
input = input:gsub("-", "+"):gsub("_", "/")
44+
return decode_base64(input)
45+
end
46+
47+
48+
3049
function table_to_string(tbl)
3150
local result = ""
3251
for k, v in pairs(tbl) do
@@ -239,7 +258,7 @@ local function get_keys(well_known_endpoint)
239258

240259
local decoded_keys = {}
241260
for i, key in ipairs(keys) do
242-
decoded_keys[i] = jwt_decoder:base64_decode(key)
261+
decoded_keys[i] = custom_base64_decode(key)
243262
end
244263

245264
kong.log.debug('Number of keys retrieved: ' .. table.getn(decoded_keys))

0 commit comments

Comments
 (0)