# HG changeset patch # User Matthew Wild # Date 1678095617 0 # Node ID c72e3b0914e8db35a8574c274fc636e1177aaa90 # Parent 31c62df82aa8bf9f4cca697bc7e55e9867c6a4db mod_http_oauth: Factor out issuer URL calculation to a helper function diff -r 31c62df82aa8 -r c72e3b0914e8 mod_http_oauth2/mod_http_oauth2.lua --- a/mod_http_oauth2/mod_http_oauth2.lua Sun Mar 05 12:38:20 2023 +0100 +++ b/mod_http_oauth2/mod_http_oauth2.lua Mon Mar 06 09:40:17 2023 +0000 @@ -66,6 +66,10 @@ return code and code_expires_in(code) + 1 or 900; end) +local function get_issuer() + return (module:http_url(nil, "/"):gsub("/$", "")); +end + local function oauth_error(err_name, err_desc) return errors.new({ type = "modify"; @@ -159,7 +163,7 @@ local query = http.formdecode(redirect.query or ""); if type(query) ~= "table" then query = {}; end table.insert(query, { name = "code", value = code }); - table.insert(query, { name = "iss", value = module:http_url(nil, "/"):gsub("/$", "") }); + table.insert(query, { name = "iss", value = get_issuer() }); if params.state then table.insert(query, { name = "state", value = params.state }); end @@ -474,7 +478,7 @@ ["GET"] = { headers = { content_type = "application/json" }; body = json.encode { - issuer = module:http_url(nil, "/"):gsub("/$", ""); + issuer = get_issuer(); authorization_endpoint = handle_authorization_request and module:http_url() .. "/authorize" or nil; token_endpoint = handle_token_grant and module:http_url() .. "/token" or nil; jwks_uri = nil; -- TODO?