Skip to content

Commit c5f097a

Browse files
authored
Merge pull request #96 from pdsinterop/well-known-solid
Add /.well-known/solid and websocket endpoint
2 parents 08dbdcb + 195f2dc commit c5f097a

7 files changed

Lines changed: 106 additions & 3 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
solid/bin
2+
solid/vendor

solid/appinfo/routes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
['name' => 'solidWebhook#listWebhooks', 'url' => '/webhook/list', 'verb' => 'GET'],
5555
['name' => 'solidWebhook#register', 'url' => '/webhook/register', 'verb' => 'POST'],
5656
['name' => 'solidWebhook#unregister', 'url' => '/webhook/unregister', 'verb' => 'POST'],
57-
57+
58+
['name' => 'solidWebsocket#register', 'url' => '/websocket/register', 'verb' => 'POST'],
59+
5860
['name' => 'app#appLauncher', 'url' => '/', 'verb' => 'GET'],
5961
]
6062
];

solid/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use OCA\Solid\Service\UserService;
1313
use OCA\Solid\WellKnown\OpenIdConfigurationHandler;
14+
use OCA\Solid\WellKnown\SolidHandler;
1415
use OCA\Solid\Middleware\SolidCorsMiddleware;
1516

1617
use OCP\AppFramework\App;
@@ -58,6 +59,7 @@ public function __construct(array $urlParams = []) {
5859

5960
public function register(IRegistrationContext $context): void {
6061
$context->registerWellKnownHandler(\OCA\Solid\WellKnown\OpenIdConfigurationHandler::class);
62+
$context->registerWellKnownHandler(\OCA\Solid\WellKnown\SolidHandler::class);
6163

6264
/**
6365
* Core class wrappers
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace OCA\Solid\Controller;
4+
5+
use OCP\AppFramework\Controller;
6+
use OCP\AppFramework\Http\DataResponse;
7+
8+
class SolidWebsocketController extends Controller
9+
{
10+
/**
11+
* @PublicPage
12+
* @NoAdminRequired
13+
* @NoCSRFRequired
14+
*/
15+
public function register(): DataResponse
16+
{
17+
$pubsub = getenv("PUBSUB_URL") ?: "http://pubsub:8080";
18+
return new DataResponse([
19+
"@context" => "https://www.w3.org/ns/solid/notification/v1",
20+
"type" => "WebSocketSubscription2021",
21+
"source" => $pubsub . "/?type=WebSocketSubscription2021"
22+
]);
23+
}
24+
}

solid/lib/Middleware/SolidCorsMiddleware.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,16 @@ public function afterController($controller, $methodName, Response $response) {
3636

3737
$pubsub = getenv("PUBSUB_URL") ?: "http://pubsub:8080";
3838
$response->addHeader('updates-via', $pubsub);
39+
$linkHeaders = '</.well-known/solid>; rel="http://www.w3.org/ns/solid#storageDescription"';
40+
$existingHeaders = $response->getHeaders();
41+
if (isset($existingHeaders['Link'])) { // careful - this dictionary key is case sensitive here
42+
$linkHeaders .= ', ' . $existingHeaders['Link'];
43+
}
44+
$response->addHeader('Link', $linkHeaders);
3945

46+
// Note that apart from these, the Link header with rel="acl" and the WAC-Allow header
47+
// are already added by these lines in vendor/pdsinterop/solid-auth:
48+
// https://github.com/pdsinterop/php-solid-auth/blob/e07c22d/src/WAC.php#L39-L40
4049
return $response;
4150
}
4251
}

solid/lib/Notifications/SolidNotifications.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public function __construct() {
1313
$this->notifications = [
1414
new SolidWebhook(),
1515
new SolidPubSub($pubsub)
16-
];
16+
];
1717
}
1818

1919
public function send($path, $type) {
2020
foreach ($this->notifications as $notification) {
2121
$notification->send($path, $type);
22+
}
2223
}
23-
}
2424
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
namespace OCA\Solid\WellKnown;
3+
4+
use OCP\IRequest;
5+
use OCP\IUserManager;
6+
use OCP\IURLGenerator;
7+
use OCP\IConfig;
8+
9+
use OCP\AppFramework\Http\JSONResponse;
10+
use OCP\Http\WellKnown\GenericResponse;
11+
use OCP\Http\WellKnown\IHandler;
12+
use OCP\Http\WellKnown\IRequestContext;
13+
use OCP\Http\WellKnown\IResponse;
14+
15+
class SolidHandler implements IHandler {
16+
/* @var IURLGenerator */
17+
private $urlGenerator;
18+
19+
public function __construct(IRequest $request, IURLGenerator $urlGenerator, IConfig $config, IUserManager $userManager)
20+
{
21+
require_once(__DIR__.'/../../vendor/autoload.php');
22+
$this->urlGenerator = $urlGenerator;
23+
}
24+
25+
public function handle(string $service, IRequestContext $context, ?IResponse $previousResponse): ?IResponse {
26+
if ($service !== 'solid') {
27+
return $previousResponse;
28+
}
29+
$webhooksRegisterEndpoint = $this->urlGenerator->linkToRoute('solid.solidWebhook.register');
30+
// FIXME: this shouldn't happen:
31+
if (strlen($webhooksRegisterEndpoint) == 0) {
32+
$webhooksRegisterEndpoint = $this->urlGenerator->linkToRoute('solid.app.appLauncher') . 'webhook/register';
33+
}
34+
35+
$websocketsRegisterEndpoint = $this->urlGenerator->linkToRoute('solid.solidWebsocket.register');
36+
// FIXME: this shouldn't happen:
37+
if (strlen($websocketsRegisterEndpoint) == 0) {
38+
$websocketsRegisterEndpoint = $this->urlGenerator->linkToRoute('solid.app.appLauncher') . 'websocket/register';
39+
}
40+
$body = [
41+
"@context" => [
42+
"https://www.w3.org/ns/solid/notification/v1"
43+
],
44+
"notificationChannel" => [
45+
[
46+
"id" => "websocketNotification",
47+
"type" => ["WebSocketSubscription2021"],
48+
"subscription" => $websocketsRegisterEndpoint,
49+
"feature" => []
50+
],
51+
[
52+
"id" => "webhookNotification",
53+
"type" => ["WebHookSubscription2022"],
54+
"subscription" => $webhooksRegisterEndpoint,
55+
"feature" => []
56+
]
57+
]
58+
];
59+
$result = new JSONResponse($body);
60+
$result->addHeader("Access-Control-Allow-Origin", "*");
61+
$result->setStatus(200);
62+
return new GenericResponse($result);
63+
}
64+
}

0 commit comments

Comments
 (0)