simple-sso/src/ssso_base64.lua

23 lines
534 B
Lua
Raw Normal View History

local b64 = require("ngx.base64") -- only contains URL-variants
if not b64["decode_base64"] then
b64.decode_base64 = function(base64)
base64 = base64:gsub("%+", "-")
base64 = base64:gsub("/", "_")
return b64.decode_base64url(base64)
end
end
if not b64["encode_base64"] then
b64.encode_base64 = function(plaintext)
2021-09-02 22:58:01 +02:00
local plain, err = b64.encode_base64url(plaintext)
if not plain then
return nil, err
end
plain = plain:gsub("_", "/")
2021-09-02 22:58:01 +02:00
return plain:gsub("%-", "+"), nil
end
end
return b64