From ae5c460cf3ee84667beffecbcaa45d1434b2c43e Mon Sep 17 00:00:00 2001 From: damikael Date: Tue, 18 Jun 2024 17:42:02 +0000 Subject: [PATCH] feat: add FetchEntityStatementEndpoint --- .../FetchEntityStatementEndpoint.php | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 lib/Federation/FetchEntityStatementEndpoint.php diff --git a/lib/Federation/FetchEntityStatementEndpoint.php b/lib/Federation/FetchEntityStatementEndpoint.php new file mode 100644 index 0000000..fcd05fd --- /dev/null +++ b/lib/Federation/FetchEntityStatementEndpoint.php @@ -0,0 +1,72 @@ +sa_config = $sa_config; + $this->rp_config = null; + $this->rps_config = $rps_config; + } + + // TODO merge into lib/federation/EntityStatement + public function process() + { + try { + $iss = $_GET['iss'] ?? null; + $sub = $_GET['sub'] ?? null; + $output = $_GET['output'] ?? null; + + if($iss!=null && $iss!=$this->sa_config['client_id']) { + throw new \Exception('iss MUST be equal to: ' . $this->iss); + } + + if($sub==null) { + $this->rp_config = $this->sa_config; + + } else { + foreach($this->rps_config as $rp_config) { + if($rp_config['client_id'] == $sub) { + $this->rp_config = $rp_config; + break; + } + } + + if($this->rp_config==null) throw new \Exception("sub not found"); + } + + $entity_statement = EntityStatement::makeRPEntityStatementFromConfig($this->sa_config, $this->rp_config, $output=='json'); + + $mediaType = $output=='json'? 'application/json' : 'application/entity-statement+jwt'; + header('Content-Type: ' . $mediaType); + echo $entity_statement; + + } catch(\Exception $e) { + // API error + http_response_code(400); + echo "ERROR: " . $e->getMessage(); + } + } +} \ No newline at end of file