@@ -30,7 +30,7 @@ Token introspection policy check access token.
30
30
" proxy" : {
31
31
" policy_chain" : [
32
32
{
33
- " name" : " apicast.policy.token_introspection" ,
33
+ " name" : " apicast.policy.token_introspection" ,
34
34
" configuration" : {
35
35
" auth_type" : " client_id+client_secret" ,
36
36
" client_id" : " app" ,
@@ -80,7 +80,7 @@ Token introspection policy return "403 Unauthorized" if access token is already
80
80
" proxy" : {
81
81
" policy_chain" : [
82
82
{
83
- " name" : " apicast.policy.token_introspection" ,
83
+ " name" : " apicast.policy.token_introspection" ,
84
84
" configuration" : {
85
85
" auth_type" : " client_id+client_secret" ,
86
86
" client_id" : " app" ,
@@ -133,7 +133,7 @@ Token introspection policy return "403 Unauthorized" if IdP response error statu
133
133
" proxy" : {
134
134
" policy_chain" : [
135
135
{
136
- " name" : " apicast.policy.token_introspection" ,
136
+ " name" : " apicast.policy.token_introspection" ,
137
137
" configuration" : {
138
138
" auth_type" : " client_id+client_secret" ,
139
139
" client_id" : " app" ,
@@ -164,6 +164,7 @@ Authorization: Bearer testaccesstoken
164
164
-- - error_code: 403
165
165
-- - no_error_log
166
166
[error]
167
+
167
168
=== TEST 4 : Token introspection request is failed with bad response value
168
169
Token introspection policy return " 403 Unauthorized" if IdP response invalid contents type.
169
170
-- - backend
@@ -271,7 +272,7 @@ Authorization: Bearer testaccesstoken
271
272
[error]
272
273
273
274
=== TEST 6 : Token introspection request success with oidc issuer endpoint
274
- Token introspection policy retrieves client_id and client_secret and
275
+ Token introspection policy retrieves client_id and client_secret and
275
276
introspection endpoint from the oidc_issuer_endpoint of the service configuration.
276
277
-- - backend
277
278
location / token/ introspection {
@@ -293,7 +294,10 @@ introspection endpoint from the oidc_issuer_endpoint of the service configuratio
293
294
" oidc" : [
294
295
{
295
296
" issuer" : " https://example.com/auth/realms/apicast" ,
296
- " config" : { " id_token_signing_alg_values_supported" : [ " RS256" ] },
297
+ " config" : {
298
+ " id_token_signing_alg_values_supported" : [ " RS256" ],
299
+ " introspection_endpoint" : " http://test_backend:$ TEST_NGINX_SERVER_PORT /token/introspection"
300
+ },
297
301
" keys" : { " somekid" : { " pem" : " -----BEGIN PUBLIC KEY-----\n MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALClz96cDQ965ENYMfZzG+Acu25lpx2K\n NpAALBQ+catCA59us7+uLY5rjQR6SOgZpCz5PJiKNAdRPDJMXSmXqM0CAwEAAQ==\n -----END PUBLIC KEY-----" , " alg" : " RS256" } }
298
302
}
299
303
],
@@ -347,7 +351,7 @@ yay, api backend
347
351
oauth failed with
348
352
349
353
=== TEST 7 : Token introspection request fails with app_key
350
- Token introspection policy retrieves client_id and client_secret and
354
+ Token introspection policy retrieves client_id and client_secret and
351
355
introspection endpoint from the oidc_issuer_endpoint of the service configuration.
352
356
When authentication_method = 1 , the request fails.
353
357
-- - backend
@@ -400,11 +404,104 @@ Authentication failed
400
404
[error]
401
405
oauth failed with
402
406
407
+ === TEST 8 : Token introspection request success with oidc issuer endpoint loaded from the IDP
408
+ Token introspection policy retrieves client_id and client_secret and
409
+ introspection endpoint from the oidc_issuer_endpoint of the service configuration.
410
+ -- - env eval
411
+ ( ' APICAST_CONFIGURATION_LOADER' => ' lazy' )
412
+ -- - backend
413
+ location = /issuer /endpoint/. well-known/ openid-configuration {
414
+ content_by_lua_block {
415
+ local base = " http://" .. ngx. var. host .. ' :' .. ngx. var. server_port
416
+ ngx. header. content_type = ' application/json;charset=utf-8'
417
+ ngx. say (require (' cjson' ). encode {
418
+ issuer = ' https://example.com/auth/realms/apicast' ,
419
+ id_token_signing_alg_values_supported = { ' RS256' },
420
+ jwks_uri = base .. ' /jwks' ,
421
+ introspection_endpoint = base .. ' /token/introspection' ,
422
+ })
423
+ }
424
+ }
403
425
426
+ location = /jwks {
427
+ content_by_lua_block {
428
+ ngx. header. content_type = ' application/json;charset=utf-8'
429
+ ngx. say ([[
430
+ { " keys" : [
431
+ { " kty" : " RSA" ," kid" : " somekid" ,
432
+ " n" : " sKXP3pwND3rkQ1gx9nMb4By7bmWnHYo2kAAsFD5xq0IDn26zv64tjmuNBHpI6BmkLPk8mIo0B1E8MkxdKZeozQ" ," e" : " AQAB" ,
433
+ " alg" : " RS256" }
434
+ ] }
435
+ ]])
436
+ }
437
+ }
404
438
405
- === TEST 8 : Token introspection request success with oidc issuer endpoint loaded from the IDP
439
+ location = /token/ introspection {
440
+ content_by_lua_block {
441
+ local credential = ngx. decode_base64(require (' ngx.re' ). split (ngx. req. get_headers()[' Authorization' ], ' ' , ' oj' )[2 ])
442
+ require (' luassert' ). are. equal(' app:appsec' , credential)
443
+ ngx. say (' {"active": true}' )
444
+ }
445
+ }
446
+
447
+ location = /transactions /oauth_authrep. xml {
448
+ content_by_lua_block { ngx. exit(200 ) }
449
+ }
450
+
451
+ -- - configuration
452
+ {
453
+ " services" : [
454
+ {
455
+ " backend_version" : " oauth" ,
456
+ " proxy" : {
457
+ " authentication_method" : " oidc" ,
458
+ " oidc_issuer_endpoint" : " http://app:appsec@ test_backend :$ TEST_NGINX_SERVER_PORT /issuer/endpoint" ,
459
+ " api_backend" : " http://test:$ TEST_NGINX_SERVER_PORT /" ,
460
+ " proxy_rules" : [
461
+ { " pattern" : " /" , " http_method" : " GET" , " metric_system_name" : " hits" , " delta" : 1 }
462
+ ],
463
+ " policy_chain" : [
464
+ {
465
+ " name" : " apicast.policy.token_introspection" ,
466
+ " configuration" : {
467
+ " auth_type" : " use_3scale_oidc_issuer_endpoint"
468
+ }
469
+ },
470
+ { " name" : " apicast.policy.apicast" }
471
+ ]
472
+ }
473
+ }
474
+ ]
475
+ }
476
+ -- - upstream
477
+ location / echo {
478
+ content_by_lua_block {
479
+ ngx. say (' yay, api backend' );
480
+ }
481
+ }
482
+ -- - request
483
+ GET / echo
484
+ -- - more_headers eval
485
+ use Crypt::JWT qw(encode_jwt);
486
+ my $ jwt = encode_jwt(payload => {
487
+ aud => ' the_token_audience' ,
488
+ sub => ' someone' ,
489
+ iss => ' https://example.com/auth/realms/apicast' ,
490
+ exp => time + 3600 }, key => \$::rsa, alg => ' RS256' , extra_headers => { kid => ' somekid' });
491
+ " Authorization: Bearer $ jwt"
492
+ -- - error_code: 200
493
+ -- - response_body
494
+ yay, api backend
495
+ -- - no_error_log
496
+ [error]
497
+ oauth failed with
498
+
499
+ === TEST 9 : Token introspection request success with oidc issuer endpoint returning deprecated introspection attribute
406
500
Token introspection policy retrieves client_id and client_secret and
407
501
introspection endpoint from the oidc_issuer_endpoint of the service configuration.
502
+ But the service configuration returns deprecated " token_introspection_endpoint" attribute
503
+ instead of " introspection_endpoint" attribute. This is for backward compatibility.
504
+
408
505
-- - env eval
409
506
( ' APICAST_CONFIGURATION_LOADER' => ' lazy' )
410
507
-- - backend
@@ -416,6 +513,7 @@ location = /issuer/endpoint/.well-known/openid-configuration {
416
513
issuer = ' https://example.com/auth/realms/apicast' ,
417
514
id_token_signing_alg_values_supported = { ' RS256' },
418
515
jwks_uri = base .. ' /jwks' ,
516
+ token_introspection_endpoint = base .. ' /token/introspection' ,
419
517
})
420
518
}
421
519
}
@@ -492,3 +590,79 @@ yay, api backend
492
590
-- - no_error_log
493
591
[error]
494
592
oauth failed with
593
+
594
+ === TEST 10 : Token introspection request success with oidc issuer endpoint
595
+ Token introspection policy retrieves introspection endpoint from the oidc_issuer_endpoint
596
+ of the service configuration. However, the introspection endpoint is not in the response
597
+ -- - env eval
598
+ ( ' APICAST_CONFIGURATION_LOADER' => ' lazy' )
599
+ -- - backend
600
+ location = /issuer /endpoint/. well-known/ openid-configuration {
601
+ content_by_lua_block {
602
+ local base = " http://" .. ngx. var. host .. ' :' .. ngx. var. server_port
603
+ ngx. header. content_type = ' application/json;charset=utf-8'
604
+ ngx. say (require (' cjson' ). encode {
605
+ issuer = ' https://example.com/auth/realms/apicast' ,
606
+ id_token_signing_alg_values_supported = { ' RS256' },
607
+ jwks_uri = base .. ' /jwks' ,
608
+ })
609
+ }
610
+ }
611
+
612
+ location = /jwks {
613
+ content_by_lua_block {
614
+ ngx. header. content_type = ' application/json;charset=utf-8'
615
+ ngx. say ([[
616
+ { " keys" : [
617
+ { " kty" : " RSA" ," kid" : " somekid" ,
618
+ " n" : " sKXP3pwND3rkQ1gx9nMb4By7bmWnHYo2kAAsFD5xq0IDn26zv64tjmuNBHpI6BmkLPk8mIo0B1E8MkxdKZeozQ" ," e" : " AQAB" ,
619
+ " alg" : " RS256" }
620
+ ] }
621
+ ]])
622
+ }
623
+ }
624
+
625
+ --- configuration
626
+ {
627
+ " services" : [
628
+ {
629
+ " backend_version" : " oauth" ,
630
+ " proxy" : {
631
+ " authentication_method" : " oidc" ,
632
+ " oidc_issuer_endpoint" : " http://app:appsec@ test_backend :$ TEST_NGINX_SERVER_PORT /issuer/endpoint" ,
633
+ " api_backend" : " http://test:$ TEST_NGINX_SERVER_PORT /" ,
634
+ " proxy_rules" : [
635
+ { " pattern" : " /" , " http_method" : " GET" , " metric_system_name" : " hits" , " delta" : 1 }
636
+ ],
637
+ " policy_chain" : [
638
+ {
639
+ " name" : " apicast.policy.token_introspection" ,
640
+ " configuration" : {
641
+ " auth_type" : " use_3scale_oidc_issuer_endpoint"
642
+ }
643
+ },
644
+ { " name" : " apicast.policy.apicast" }
645
+ ]
646
+ }
647
+ }
648
+ ]
649
+ }
650
+ --- upstream
651
+ location /echo {
652
+ content_by_lua_block {
653
+ ngx. say (' yay, api backend' );
654
+ }
655
+ }
656
+ -- - request
657
+ GET / echo
658
+ -- - more_headers eval
659
+ use Crypt::JWT qw(encode_jwt);
660
+ my $ jwt = encode_jwt(payload => {
661
+ aud => ' the_token_audience' ,
662
+ sub => ' someone' ,
663
+ iss => ' https://example.com/auth/realms/apicast' ,
664
+ exp => time + 3600 }, key => \$::rsa, alg => ' RS256' , extra_headers => { kid => ' somekid' });
665
+ " Authorization: Bearer $ jwt"
666
+ -- - error_code: 403
667
+ -- - no_error_log
668
+ [error]
0 commit comments