From 1078ba53f109e77bd9fa7e38b802684b5542b6d9 Mon Sep 17 00:00:00 2001 From: damikael Date: Tue, 18 Jun 2024 17:42:50 +0000 Subject: [PATCH] feat: add /fetch --- www/index.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/www/index.php b/www/index.php index 99c7058..4677378 100644 --- a/www/index.php +++ b/www/index.php @@ -27,6 +27,7 @@ use SPID_CIE_OIDC_PHP\Core\Logger; use SPID_CIE_OIDC_PHP\Core\Util; use SPID_CIE_OIDC_PHP\Federation\Federation; +use SPID_CIE_OIDC_PHP\Federation\FetchEntityStatementEndpoint; use SPID_CIE_OIDC_PHP\Federation\EntityListingEndpoint; use SPID_CIE_OIDC_PHP\Federation\EntityStatement; use SPID_CIE_OIDC_PHP\Federation\ResolveEndpoint; @@ -139,6 +140,30 @@ function ($f3) { } ); +// GET /fetch +$f3->route( + 'GET /fetch', + function ($f3) { + if (!$f3->get("CONFIG")) $f3->error(400, "Configuration not found"); + if (!$f3->get("CONFIG")['sa']) $f3->error(400, "SA configuration not found"); + if (!$f3->get("CONFIG")['rp_proxy_clients']) $f3->error(400, "Clients configuration not found"); + + $sa_config = $f3->get("CONFIG")['sa']; + $rp_config = $f3->get("CONFIG")['rp_proxy_clients']; + + try { + $logger = $f3->get("LOGGER"); + $logger->log('OIDC FED /fetch', 'GET ' . $_SERVER['REQUEST_URI']); + + $handler = new FetchEntityStatementEndpoint($sa_config, $rp_config); + $handler->process(); + + } catch (\Exception $e) { + $f3->error(400, $e->getMessage()); + } + } +); + // GET /list $f3->route( 'GET /list', @@ -245,7 +270,7 @@ function ($f3) { $mediaType = $json ? 'application/json' : 'application/entity-statement+jwt'; header('Content-Type: ' . $mediaType); - echo EntityStatement::makeRPEntityStatementFromConfig($config, $json); + echo EntityStatement::makeRPEntityConfigurationFromConfig($config, $json); } ); @@ -326,7 +351,7 @@ function ($f3) { $acr = $config['requested_acr']; $user_attributes = $config['spid_user_attributes']; - $redirect_uri = $config['redirect_uri']; + $redirect_uri = $config['redirect_uri'] ?? $config['client_id'] . '/redirect'; $req_id = $rp_database->createRequest($ta_id, $op_id, $redirect_uri, $state, $acr, $user_attributes); $request = $rp_database->getRequest($req_id); $code_verifier = $request['code_verifier'];