@@ -83,6 +83,7 @@ local DEFAULT_FAKE_ACCESS_TOKEN_SIGNATURE = "false"
8383local DEFAULT_FAKE_ID_TOKEN_SIGNATURE = " false"
8484local DEFAULT_BREAK_ID_TOKEN_SIGNATURE = " false"
8585local DEFAULT_NONE_ALG_ID_TOKEN_SIGNATURE = " false"
86+ local DEFAULT_REFRESH_RESPONSE_CONTAINS_ID_TOKEN = " true"
8687
8788local DEFAULT_UNAUTH_ACTION = " nil"
8889
@@ -192,8 +193,13 @@ JWT_VERIFY_SECRET]=]
192193 local auth = ngx.req.get_headers()["Authorization"]
193194 ngx.log(ngx.ERR, "token authorization header: " .. (auth and auth or ""))
194195 ngx.header.content_type = 'application/json;charset=UTF-8'
195- local id_token = ID_TOKEN
196196 local args = ngx.req.get_post_args()
197+ local id_token
198+ if args.grant_type == "authorization_code" then
199+ id_token = ID_TOKEN
200+ else
201+ id_token = REFRESH_ID_TOKEN
202+ end
197203 local access_token = "a_token"
198204 local refresh_token = "r_token"
199205 if args.grant_type == "authorization_code" then
@@ -226,8 +232,10 @@ JWT_VERIFY_SECRET]=]
226232 access_token = access_token,
227233 expires_in = TOKEN_RESPONSE_EXPIRES_IN,
228234 refresh_token = TOKEN_RESPONSE_CONTAINS_REFRESH_TOKEN and refresh_token or nil,
229- id_token = jwt_token
230235 }
236+ if args.grant_type == "authorization_code" or REFRESH_RESPONSE_CONTAINS_ID_TOKEN then
237+ token_response.id_token = jwt_token
238+ end
231239 delay(TOKEN_DELAY_RESPONSE)
232240 ngx.say(cjson.encode(token_response))
233241 }
@@ -348,6 +356,7 @@ local function write_config(out, custom_config)
348356 custom_config = custom_config or {}
349357 local oidc_config = merge (merge ({}, DEFAULT_OIDC_CONFIG ), custom_config [" oidc_opts" ] or {})
350358 local id_token = merge (merge ({}, DEFAULT_ID_TOKEN ), custom_config [" id_token" ] or {})
359+ local refresh_id_token = merge ({}, id_token )
351360 local verify_opts = merge (merge ({}, DEFAULT_VERIFY_OPTS ), custom_config [" verify_opts" ] or {})
352361 local access_token = merge (merge ({}, DEFAULT_ACCESS_TOKEN ), custom_config [" access_token" ] or {})
353362 local token_header = merge (merge ({}, DEFAULT_TOKEN_HEADER ), custom_config [" token_header" ] or {})
@@ -360,10 +369,14 @@ local function write_config(out, custom_config)
360369 local token_response_contains_refresh_token = custom_config [" token_response_contains_refresh_token" ]
361370 or DEFAULT_TOKEN_RESPONSE_CONTAINS_REFRESH_TOKEN
362371 local refreshing_token_fails = custom_config [" refreshing_token_fails" ] or DEFAULT_REFRESHING_TOKEN_FAILS
372+ local refresh_response_contains_id_token = custom_config [" refresh_response_contains_id_token" ] or DEFAULT_REFRESH_RESPONSE_CONTAINS_ID_TOKEN
363373 local access_token_opts = merge (merge ({}, DEFAULT_OIDC_CONFIG ), custom_config [" access_token_opts" ] or {})
364374 for _ , k in ipairs (custom_config [" remove_id_token_claims" ] or {}) do
365375 id_token [k ] = nil
366376 end
377+ for _ , k in ipairs (custom_config [" remove_refresh_id_token_claims" ] or {}) do
378+ refresh_id_token [k ] = nil
379+ end
367380 for _ , k in ipairs (custom_config [" remove_access_token_claims" ] or {}) do
368381 access_token [k ] = nil
369382 end
@@ -383,6 +396,7 @@ local function write_config(out, custom_config)
383396 :gsub (" TOKEN_RESPONSE_EXPIRES_IN" , token_response_expires_in )
384397 :gsub (" TOKEN_RESPONSE_CONTAINS_REFRESH_TOKEN" , token_response_contains_refresh_token )
385398 :gsub (" REFRESHING_TOKEN_FAILS" , refreshing_token_fails )
399+ :gsub (" REFRESH_RESPONSE_CONTAINS_ID_TOKEN" , refresh_response_contains_id_token )
386400 :gsub (" ACCESS_TOKEN_OPTS" , serpent .block (access_token_opts , {comment = false }))
387401 :gsub (" JWK_DELAY_RESPONSE" , ((custom_config [" delay_response" ] or {}).jwk or DEFAULT_DELAY_RESPONSE ))
388402 :gsub (" TOKEN_DELAY_RESPONSE" , ((custom_config [" delay_response" ] or {}).token or DEFAULT_DELAY_RESPONSE ))
@@ -395,6 +409,7 @@ local function write_config(out, custom_config)
395409 :gsub (" FAKE_ID_TOKEN_SIGNATURE" , custom_config [" fake_id_token_signature" ] or DEFAULT_FAKE_ID_TOKEN_SIGNATURE )
396410 :gsub (" BREAK_ID_TOKEN_SIGNATURE" , custom_config [" break_id_token_signature" ] or DEFAULT_BREAK_ID_TOKEN_SIGNATURE )
397411 :gsub (" NONE_ALG_ID_TOKEN_SIGNATURE" , custom_config [" none_alg_id_token_signature" ] or DEFAULT_NONE_ALG_ID_TOKEN_SIGNATURE )
412+ :gsub (" REFRESH_ID_TOKEN" , serpent .block (refresh_id_token , {comment = false }))
398413 :gsub (" ID_TOKEN" , serpent .block (id_token , {comment = false }))
399414 :gsub (" ACCESS_TOKEN" , serpent .block (access_token , {comment = false }))
400415 :gsub (" UNAUTH_ACTION" , custom_config [" unauth_action" ] and (' "' .. custom_config [" unauth_action" ] .. ' "' ) or DEFAULT_UNAUTH_ACTION )
0 commit comments