Skip to content

Commit 65e4794

Browse files
committed
#345 handle the userinfo response as JWT
1 parent 734a3f4 commit 65e4794

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

lib/resty/openidc.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,17 @@ function openidc.call_userinfo_endpoint(opts, access_token)
623623

624624
log(DEBUG, "userinfo response: ", res.body)
625625

626+
-- handle if the response type is a jwt/signed payload
627+
local responseType = string.lower(res.headers["Content-Type"])
628+
if string.find(responseType, "application/jwt") then
629+
local json, err = openidc.jwt_verify(res.body, opts)
630+
if err then
631+
err = "userinfo jwt could not be verified: " .. err
632+
return nil, err
633+
end
634+
return json
635+
end
636+
626637
-- parse the response from the user info endpoint
627638
return openidc_parse_json_response(res)
628639
end

tests/spec/test_support.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,15 @@ http {
326326
}
327327
}
328328
329+
location /user-info-signed {
330+
content_by_lua_block {
331+
local auth = ngx.req.get_headers()["Authorization"]
332+
ngx.header.content_type = 'application/jwt;charset=UTF-8'
333+
local signed_userinfo = test_globals.create_jwt(USERINFO)
334+
ngx.print(signed_userinfo)
335+
}
336+
}
337+
329338
location /introspection {
330339
content_by_lua_block {
331340
ngx.req.read_body()

tests/spec/userinfo_spec.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,26 @@ describe("when userinfo endpoint doesn't return proper JSON", function()
169169
assert.error_log_contains("JSON decoding failed")
170170
end)
171171
end)
172+
173+
describe("when userinfo endpoint returns a JWT", function()
174+
test_support.start_server({
175+
oidc_opts = {
176+
discovery = {
177+
userinfo_endpoint = "http://127.0.0.1/user-info-signed",
178+
token_endpoint_auth_methods_supported = { "private_key_jwt" },
179+
},
180+
token_endpoint_auth_method = "private_key_jwt",
181+
client_rsa_private_key = test_support.load("/spec/private_rsa_key.pem"),
182+
public_key = test_support.load("/spec/public_rsa_key.pem"),
183+
},
184+
})
185+
teardown(test_support.stop_server)
186+
local _, status = test_support.login()
187+
it("login succeeds", function()
188+
assert.are.equals(302, status)
189+
end)
190+
it("an error has not been logged", function()
191+
assert.is_not.error_log_contains("JSON decoding failed")
192+
assert.is_not.error_log_contains("userinfo jwt could not be verified")
193+
end)
194+
end)

0 commit comments

Comments
 (0)