Skip to content

Commit

Permalink
feat: add /fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
damikael committed Jun 18, 2024
1 parent ae5c460 commit 1078ba5
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions www/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}
);

Expand Down Expand Up @@ -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'];
Expand Down

0 comments on commit 1078ba5

Please sign in to comment.