From 42ede606a8c85737c550e5ae30a9727e59b88c44 Mon Sep 17 00:00:00 2001 From: Ruslan Talpa Date: Wed, 27 Jan 2021 11:49:42 +0200 Subject: [PATCH 1/4] use custom config prefix This change allows to have multiple oauth2 provider configurations (each with it's own prefix) and still have single locations handling the auth flow where the right config prefix is decided at runtime based on some parameter --- lib/ngx-oauth/config.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ngx-oauth/config.lua b/lib/ngx-oauth/config.lua index 33d19d6..c9f67e3 100644 --- a/lib/ngx-oauth/config.lua +++ b/lib/ngx-oauth/config.lua @@ -10,6 +10,7 @@ local map = util.map local par = util.partial local starts_with = util.starts_with +local oauth_config_prefix = ngx.var['oauth_config_prefix'] or 'oauth_' local DEFAULTS = { client_id = '', client_secret = '', @@ -30,7 +31,7 @@ local OAAS_ENDPOINT_VARS = {'authorization_url', 'token_url', 'userinfo_url'} local load_from_ngx = par(map, function(default_value, key) - return util.default(ngx.var['oauth_'..key], default_value) + return util.default(ngx.var[oauth_config_prefix..key], default_value) end, DEFAULTS) local function validate (conf) From 0f4915a3ae62d6fa4725d3465dfa1d34e8a449af Mon Sep 17 00:00:00 2001 From: Ruslan Talpa Date: Wed, 27 Jan 2021 11:57:56 +0200 Subject: [PATCH 2/4] Point rock file to current git --- ngx-oauth-dev-0.rockspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ngx-oauth-dev-0.rockspec b/ngx-oauth-dev-0.rockspec index f4f19f7..5ece0d4 100644 --- a/ngx-oauth-dev-0.rockspec +++ b/ngx-oauth-dev-0.rockspec @@ -4,7 +4,7 @@ package = 'ngx-oauth' version = 'dev-0' source = { - url = 'git://github.com/jirutka/ngx-oauth.git', + url = 'git://github.com/subzerocloud/ngx-oauth.git', branch = 'master' } From ad7ec9e530cc9e80583634d1f891a0ee9065bf6f Mon Sep 17 00:00:00 2001 From: Ruslan Talpa Date: Thu, 28 Jan 2021 10:23:17 +0200 Subject: [PATCH 3/4] Update ngx-oauth-dev-0.rockspec --- ngx-oauth-dev-0.rockspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ngx-oauth-dev-0.rockspec b/ngx-oauth-dev-0.rockspec index 5ece0d4..f4f19f7 100644 --- a/ngx-oauth-dev-0.rockspec +++ b/ngx-oauth-dev-0.rockspec @@ -4,7 +4,7 @@ package = 'ngx-oauth' version = 'dev-0' source = { - url = 'git://github.com/subzerocloud/ngx-oauth.git', + url = 'git://github.com/jirutka/ngx-oauth.git', branch = 'master' } From 1a113c6c8190833e3185f282af50e10f4d6b3069 Mon Sep 17 00:00:00 2001 From: Ruslan Talpa Date: Thu, 28 Jan 2021 11:33:53 +0200 Subject: [PATCH 4/4] fix config prefix "caching" --- lib/ngx-oauth/config.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ngx-oauth/config.lua b/lib/ngx-oauth/config.lua index c9f67e3..63698f8 100644 --- a/lib/ngx-oauth/config.lua +++ b/lib/ngx-oauth/config.lua @@ -10,7 +10,7 @@ local map = util.map local par = util.partial local starts_with = util.starts_with -local oauth_config_prefix = ngx.var['oauth_config_prefix'] or 'oauth_' +local oauth_config_prefix = nil local DEFAULTS = { client_id = '', client_secret = '', @@ -72,6 +72,7 @@ local M = {} -- @treturn nil|string Validation error, or `false` if no validation -- error was found. function M.load () + oauth_config_prefix = ngx.var['oauth_config_prefix'] or 'oauth_' local conf = load_from_ngx() if not is_absolute_url(conf.redirect_uri) then