Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket Notifications #106

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions run-solid-test-suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ set -e
function setup {
docker network create testnet
docker build -t solid-nextcloud .
docker build -t pubsub-server https://github.com/pdsinterop/php-solid-pubsub-server.git#main
docker build -t pubsub-server https://github.com/pdsinterop/php-solid-pubsub-server.git#feature-secure-webhook-to-ws
docker pull michielbdejong/nextcloud-cookie
docker pull solidtestsuite/webid-provider-tests:v2.1.0
docker tag solidtestsuite/webid-provider-tests:v2.1.0 webid-provider-tests
docker pull solidtestsuite/solid-crud-tests:v7.0.5
docker tag solidtestsuite/solid-crud-tests:v7.0.5 solid-crud-tests
docker pull solidtestsuite/solid-crud-tests:v7.0.6
docker tag solidtestsuite/solid-crud-tests:v7.0.6 solid-crud-tests
docker pull solidtestsuite/web-access-control-tests:v7.1.0
docker tag solidtestsuite/web-access-control-tests:v7.1.0 web-access-control-tests
}
Expand All @@ -21,6 +21,7 @@ function teardown {

function startPubSub {
docker run -d --name pubsub --network=testnet pubsub-server
docker exec -it pubsub php server/serverWh2Ws.php &
}

function startSolidNextcloud {
Expand Down
2 changes: 1 addition & 1 deletion solid/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
['name' => 'solidWebhook#register', 'url' => '/webhook/register', 'verb' => 'POST'],
['name' => 'solidWebhook#unregister', 'url' => '/webhook/unregister', 'verb' => 'POST'],

['name' => 'solidWebsocket#register', 'url' => '/websocket/register', 'verb' => 'POST'],
['name' => 'solidWebhook#registerWs', 'url' => '/websocket/register', 'verb' => 'POST'],

['name' => 'app#appLauncher', 'url' => '/', 'verb' => 'GET'],
]
Expand Down
12 changes: 6 additions & 6 deletions solid/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions solid/lib/Controller/SolidWebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@ public function listWebhooks(): DataResponse {
return new DataResponse($this->webhookService->findAll($this->webId));
}

/**
* @PublicPage
* @NoAdminRequired
* @NoCSRFRequired
*/
public function registerWs(string $topic): DataResponse {
$toSub = "http://pubsub:8081";
$toPub = "http://pubsub:8082";
// FIXME: is this secure enough?
// https://www.php.net/manual/en/function.random-bytes.php says it
// generates "cryptographically secure pseudo-random bytes"
$token = bin2hex(random_bytes(20));
$target = "$toPub/$token";
if ($this->checkReadAccess($topic)) {
$webhook = $this->webhookService->create($this->webId, $topic, $target);
return new DataResponse([
"@context" => "https://www.w3.org/ns/solid/notification/v1",
"type" => "WebSocketSubscription2021",
"source" => "$toSub/$token"
]);
} else {
return new DataResponse("Error: denied access", 401);
}
}

/**
* @PublicPage
* @NoAdminRequired
Expand Down