Skip to content

Commit bca2062

Browse files
committed
[oidc] always get issuer/iss from the OIDC Discovery endpoint
So later when the token is verified it can be exact match. Before the URL could be different due to some reverse proxies or credentials embedded in the URL.
1 parent 5d80f9e commit bca2062

File tree

6 files changed

+23
-21
lines changed

6 files changed

+23
-21
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010

1111
- Set default errlog level when `APICAST_LOG_LEVEL` is empty [PR #868](https://github.com/3scale/apicast/pull/868)
1212
- Correct JWT validation according to [RFC 7523 Section 3](https://tools.ietf.org/html/rfc7523#section-3). Like not required `nbf` claim. [THREESCALE-583](https://issues.jboss.org/browse/THREESCALE-583)
13+
- Mismatch in OIDC issuer when loading configuration through a configuration file [PR #872](https://github.com/3scale/apicast/pull/872)
1314

1415
## [3.3.0-beta2] - 2018-09-03
1516

gateway/src/apicast/configuration_loader/oidc.lua

+1-8
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,10 @@ end
1919

2020
_M.discovery = require('resty.oidc.discovery').new()
2121

22-
local function load_oidc(issuer)
23-
local config = _M.discovery:openid_configuration(issuer)
24-
local keys = _M.discovery:jwks(config)
25-
26-
return { issuer = issuer, config = config, keys = keys }
27-
end
28-
2922
local function load_service(service)
3023
if not service or not service.proxy then return nil end
3124

32-
return load_oidc(service.proxy.oidc_issuer_endpoint)
25+
return _M.discovery:call(service.proxy.oidc_issuer_endpoint)
3326
end
3427

3528
function _M.call(...)

gateway/src/apicast/configuration_loader/remote_v2.lua

+1-9
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,7 @@ function _M:services()
238238
end
239239

240240
function _M:oidc_issuer_configuration(service)
241-
local config = oidc_discovery.openid_configuration(self, service.oidc.issuer)
242-
243-
if config then
244-
return {
245-
config = config,
246-
issuer = config.issuer,
247-
keys = oidc_discovery.jwks(self, config)
248-
}
249-
end
241+
return oidc_discovery.call(self, service.oidc.issuer)
250242
end
251243

252244
function _M:config(service, environment, version)

gateway/src/resty/oidc/discovery.lua

+16
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,20 @@ function _M:jwks(configuration)
107107
end
108108
end
109109

110+
--- Fetch whole OIDC configuration through OIDC Discovery.
111+
-- @tparam string issuer URL to the Issuer (without the .well-known/openid-configuration)
112+
-- @treturn table
113+
function _M:call(issuer)
114+
local http_client = self.http_client
115+
116+
if not http_client then
117+
return nil, 'not initialized'
118+
end
119+
120+
local config, err = _M.openid_configuration(self, issuer)
121+
if not config then return nil, err end
122+
123+
return { config = config, issuer = config.issuer, keys = _M.jwks(self, config) }
124+
end
125+
110126
return _M

spec/configuration_loader/oidc_spec.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('OIDC Configuration loader', function()
3131
it('gets openid configuration', function()
3232
local config = {
3333
services = {
34-
{ id = 21, proxy = { oidc_issuer_endpoint = 'https://example.com' } },
34+
{ id = 21, proxy = { oidc_issuer_endpoint = 'https://user:pass@example.com' } },
3535
}
3636
}
3737

@@ -40,7 +40,7 @@ describe('OIDC Configuration loader', function()
4040
.respond_with{
4141
status = 200,
4242
headers = { content_type = 'application/json' },
43-
body = [[{"jwks_uri":"http://example.com/jwks"}]],
43+
body = [[{"jwks_uri":"http://example.com/jwks","issuer":"https://example.com"}]],
4444
}
4545

4646
test_backend
@@ -52,7 +52,7 @@ describe('OIDC Configuration loader', function()
5252
}
5353
local oidc = loader.call(cjson.encode(config))
5454

55-
assert.same([[{"services":[{"id":21,"proxy":{"oidc_issuer_endpoint":"https:\/\/example.com"}}],"oidc":[{"issuer":"https:\/\/example.com","config":{"jwks_uri":"http:\/\/example.com\/jwks"},"keys":{}}]}]], oidc)
55+
assert.same([[{"services":[{"id":21,"proxy":{"oidc_issuer_endpoint":"https:\/\/user:pass@example.com"}}],"oidc":[{"issuer":"https:\/\/example.com","config":{"jwks_uri":"http:\/\/example.com\/jwks","issuer":"https:\/\/example.com"},"keys":{}}]}]], oidc)
5656
end)
5757
end)
5858
end)

spec/configuration_loader/remote_v2_spec.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('Configuration Remote Loader V2', function()
177177
environment = 'sandbox',
178178
content = {
179179
id = 42, backend_version = 1,
180-
proxy = { oidc_issuer_endpoint = 'http://idp.example.com/auth/realms/foo/' }
180+
proxy = { oidc_issuer_endpoint = 'http://user:pass@idp.example.com/auth/realms/foo/' }
181181
}
182182
}
183183
}

0 commit comments

Comments
 (0)