|
6 | 6 | require_once(__DIR__ . "/../../vendor/autoload.php"); |
7 | 7 |
|
8 | 8 | use Pdsinterop\PhpSolid\Middleware; |
9 | | - use Pdsinterop\PhpSolid\StorageServer; |
10 | | - use Pdsinterop\PhpSolid\ClientRegistration; |
11 | | - use Pdsinterop\PhpSolid\SolidNotifications; |
12 | | - use Pdsinterop\Solid\Auth\WAC; |
13 | | - use Pdsinterop\Solid\Resources\Server as ResourceServer; |
14 | | - use Laminas\Diactoros\ServerRequestFactory; |
15 | | - use Laminas\Diactoros\Response; |
| 9 | + use Pdsinterop\PhpSolid\Api\SolidStorage; |
16 | 10 |
|
17 | | - $request = explode("?", $_SERVER['REQUEST_URI'], 2)[0]; |
18 | 11 | $method = $_SERVER['REQUEST_METHOD']; |
19 | 12 |
|
20 | 13 | Middleware::cors(); |
|
25 | 18 | echo "OK"; |
26 | 19 | return; |
27 | 20 | break; |
| 21 | + default: |
| 22 | + SolidStorage::respondToStorage(); |
| 23 | + break; |
28 | 24 | } |
29 | | - |
30 | | - $requestFactory = new ServerRequestFactory(); |
31 | | - $rawRequest = $requestFactory->fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); |
32 | | - $response = new Response(); |
33 | | - |
34 | | - StorageServer::initializeStorage(); |
35 | | - $filesystem = StorageServer::getFileSystem(); |
36 | | - |
37 | | - $resourceServer = new ResourceServer($filesystem, $response, null); |
38 | | - $solidNotifications = new SolidNotifications(); |
39 | | - $resourceServer->setNotifications($solidNotifications); |
40 | | - |
41 | | - $wac = new WAC($filesystem); |
42 | | - |
43 | | - $baseUrl = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME']; |
44 | | - |
45 | | - $resourceServer->setBaseUrl($baseUrl); |
46 | | - $wac->setBaseUrl($baseUrl); |
47 | | - |
48 | | - $webId = StorageServer::getWebId($rawRequest); |
49 | | - |
50 | | - if (!isset($webId)) { |
51 | | - $response = $resourceServer->getResponse() |
52 | | - ->withStatus(409, "Invalid token"); |
53 | | - StorageServer::respond($response); |
54 | | - exit(); |
55 | | - } |
56 | | - |
57 | | - $origin = $rawRequest->getHeaderLine("Origin"); |
58 | | - |
59 | | - // FIXME: Read allowed clients from the profile instead; |
60 | | - $owner = StorageServer::getOwner(); |
61 | | - |
62 | | - $allowedClients = $owner['allowedClients'] ?? []; |
63 | | - $allowedOrigins = []; |
64 | | - foreach ($allowedClients as $clientId) { |
65 | | - $clientRegistration = ClientRegistration::getRegistration($clientId); |
66 | | - if (isset($clientRegistration['client_name'])) { |
67 | | - $allowedOrigins[] = $clientRegistration['client_name']; |
68 | | - } |
69 | | - if (isset($clientRegistration['origin'])) { |
70 | | - $allowedOrigins[] = $clientRegistration['origin']; |
71 | | - } |
72 | | - } |
73 | | - if ($origin =="") { |
74 | | - $allowedOrigins[] = "app://unset"; // FIXME: this should not be here. |
75 | | - $origin = "app://unset"; |
76 | | - } |
77 | | - |
78 | | - if (!$wac->isAllowed($rawRequest, $webId, $origin, $allowedOrigins)) { |
79 | | - $response = new Response(); |
80 | | - $response = $response->withStatus(403, "Access denied!"); |
81 | | - StorageServer::respond($response); |
82 | | - exit(); |
83 | | - } |
84 | | - |
85 | | - $response = $resourceServer->respondToRequest($rawRequest); |
86 | | - $response = $wac->addWACHeaders($rawRequest, $response, $webId); |
87 | | - StorageServer::respond($response); |
0 commit comments