Skip to content

Commit 11a9f26

Browse files
committed
restructure code a little to make testing easier
Signed-off-by: Stefan Bodewig <[email protected]>
1 parent 8c63805 commit 11a9f26

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Diff for: lib/resty/openidc.lua

+8-7
Original file line numberDiff line numberDiff line change
@@ -1117,24 +1117,25 @@ local function openidc_access_token(opts, session, try_to_renew)
11171117
session.data.refresh_token = json.refresh_token
11181118
end
11191119

1120-
if store_in_session(opts, 'enc_id_token') then
1121-
if json.id_token ~= nil then
1120+
if json.id_token and
1121+
(store_in_session(opts, 'enc_id_token') or store_in_session(opts, 'id_token')) then
1122+
1123+
ngx.log(ngx.DEBUG, "id_token refreshed: ", json.id_token)
1124+
if store_in_session(opts, 'enc_id_token') then
11221125
session.data.enc_id_token = json.id_token
11231126
end
1124-
end
1125-
1126-
if store_in_session(opts, 'id_token') then
1127-
if json.id_token ~= nil then
1127+
if store_in_session(opts, 'id_token') then
11281128
local id_token, err = openidc_load_and_validate_jwt_id_token(opts, json.id_token, session)
11291129
if err then
1130+
ngx.log(ngx.ERR, "invalid id token, discaring refreshed id token")
11301131
session:save()
11311132
return nil, err
11321133
end
11331134
session.data.id_token = id_token
11341135
end
11351136
end
11361137

1137-
-- save the session with the new access_token and optionally the new refresh_token
1138+
-- save the session with the new access_token and optionally the new refresh_token and id_token
11381139
session:save()
11391140

11401141
return session.data.access_token, err

0 commit comments

Comments
 (0)