@@ -337,7 +337,7 @@ token validate successfully by jwks
337
337
"openid-connect": {
338
338
"client_id": "dummy",
339
339
"client_secret": "dummy",
340
- "discovery": "http://127.0.0.1:8089 /realms/University/.well-known/openid-configuration",
340
+ "discovery": "http://127.0.0.1:8080 /realms/University/.well-known/openid-configuration",
341
341
"redirect_uri": "http://localhost:3000",
342
342
"ssl_verify": false,
343
343
"timeout": 10,
@@ -368,23 +368,6 @@ passed
368
368
369
369
370
370
=== TEST 8: Obtain valid token and access route with it. Use valid_issuer from discovery endpoint.
371
- --- http_config
372
- server {
373
- listen 8089;
374
-
375
- location /realms/University/.well-known/openid-configuration {
376
- content_by_lua_block {
377
- ngx.say([[
378
- {
379
- "issuer": "http://127.0.0.1:8089/realms/University",
380
- "jwks_uri": "http://127.0.0.1:8089/realms/University/protocol/openid-connect/certs",
381
- "response_types_supported": ["id_token"],
382
- "subject_types_supported": ["public"],
383
- "id_token_signing_alg_values_supported": ["RS256"]
384
- }]])
385
- }
386
- }
387
- }
388
371
--- config
389
372
location /t {
390
373
content_by_lua_block {
@@ -407,20 +390,39 @@ passed
407
390
return
408
391
end
409
392
393
+ -- Check if response code was ok.
394
+ if res.status == 200 then
395
+ -- Get access token from JSON response body.
396
+ local body = json_decode(res.body)
397
+ local accessToken = body["access_token"]
410
398
411
- -- Get access token from JSON response body.
412
- local body = json_decode(res.body)
413
- local accessToken = body["access_token"]
399
+ -- Access route using access token. Should work.
400
+ uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
401
+ local res, err = httpc:request_uri(uri, {
402
+ method = "GET",
403
+ headers = {
404
+ ["Authorization"] = "Bearer " .. body["access_token"]
405
+ }
406
+ })
414
407
415
- -- Access route using access token. Should work.
416
- uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
417
- local res, err = httpc:request_uri(uri, {
418
- method = "GET",
419
- headers = {
420
- ["Authorization"] = "Bearer " .. body["access_token"]
421
- }
422
- })
408
+ if res.status == 200 then
409
+ -- Route accessed successfully.
410
+ ngx.say(true)
411
+ else
412
+ -- Couldn't access route.
413
+ ngx.say(false)
414
+ end
415
+ else
416
+ -- Response from Keycloak not ok.
417
+ ngx.say(false)
418
+ end
423
419
}
424
420
}
421
+ --- response_body
422
+ true
423
+ --- grep_error_log eval
424
+ qr/token validate successfully by \w+/
425
+ --- grep_error_log_out
426
+ token validate successfully by jwks
425
427
--- error_log
426
- valid_issuers not provided, using issuer from discovery doc: http://127.0.0.1:8089 /realms/University
428
+ valid_issuers not provided, using issuer from discovery doc: http://127.0.0.1:8080 /realms/University
0 commit comments