Skip to content

Commit 27bc51d

Browse files
authored
Merge pull request #12 from pdsinterop/feature/remote-client-document
add support for remote client document
2 parents d19f1e8 + 2892423 commit 27bc51d

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

lib/ClientRegistration.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
class ClientRegistration {
77
public static function getRegistration($clientId) {
8+
if (preg_match("/^http(s)?:/", $clientId)) {
9+
return self::getRemoteRegistration($clientId);
10+
}
11+
812
Db::connect();
913
$query = Db::$pdo->prepare(
1014
'SELECT clientData FROM clients WHERE clientId=:clientId'
@@ -18,7 +22,19 @@ public static function getRegistration($clientId) {
1822
}
1923
return false;
2024
}
21-
25+
26+
public static function getRemoteRegistration($url) {
27+
$clientDocument = file_get_contents($url);
28+
$clientRegistration = json_decode($clientDocument, true);
29+
if (!isset($clientRegistration['client_id'])) {
30+
throw new \Exception("No client ID found in client document");
31+
}
32+
if (!isset($clientRegistration['redirect_uris'])) {
33+
throw new \Exception("No redirect URIs found in client document");
34+
}
35+
return $clientRegistration;
36+
}
37+
2238
public static function saveClientRegistration($clientData) {
2339
Db::connect();
2440
if (!isset($clientData['client_name'])) {

lib/Routes/SolidIdp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static function respondToAuthorize() {
6868
$approval = true;
6969
} else {
7070
$clientRegistration = ClientRegistration::getRegistration($clientId);
71-
if (in_array($clientRegistration['origin'], TRUSTED_APPS)) {
71+
if (isset($clientRegistration['origin']) && in_array($clientRegistration['origin'], TRUSTED_APPS)) {
7272
$approval = true;
7373
}
7474
}

0 commit comments

Comments
 (0)