Skip to content

Commit d476d39

Browse files
authored
Merge pull request #173 from pdsinterop/feature/custom-uri-schemas
Allow custom URI schemas to work
2 parents 371676a + 4c7b29d commit d476d39

9 files changed

Lines changed: 74 additions & 28 deletions

File tree

solid/appinfo/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
['name' => 'page#handleRevoke', 'url' => '/revoke/{clientId}', 'verb' => 'GET'],
1515
['name' => 'page#handleApproval', 'url' => '/sharing/{clientId}', 'verb' => 'POST'],
1616
['name' => 'page#dataJson', 'url' => '/@{userId}/data.json', 'verb' => 'GET' ],
17+
['name' => 'page#customscheme', 'url' => '/customscheme', 'verb' => 'GET'],
1718

1819
['name' => 'server#cors', 'url' => '/{path}', 'verb' => 'OPTIONS', 'requirements' => array('path' => '.+') ],
1920
['name' => 'server#authorize', 'url' => '/authorize', 'verb' => 'GET'],

solid/js/customscheme.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let newUrl = document.location.href.replace("customscheme", "authorize");
2+
document.location.href = newUrl;

solid/lib/Controller/CalendarController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(
5050

5151
private function getFileSystem($userId) {
5252
// Make sure the root folder has an acl file, as is required by the spec;
53-
// Generate a default file granting the owner full access.
53+
// Generate a default file granting the owner full access.
5454
$defaultAcl = $this->generateDefaultAcl($userId);
5555

5656
// Create the Nextcloud Calendar Adapter
@@ -61,7 +61,11 @@ private function getFileSystem($userId) {
6161
// Create Formats objects
6262
$formats = new \Pdsinterop\Rdf\Formats();
6363

64-
$serverUri = "https://" . $this->rawRequest->getServerParams()["SERVER_NAME"] . $this->rawRequest->getServerParams()["REQUEST_URI"]; // FIXME: doublecheck that this is the correct url;
64+
$serverParams = $this->rawRequest->getServerParams();
65+
$scheme = $serverParams['REQUEST_SCHEME'];
66+
$domain = $serverParams['SERVER_NAME'];
67+
$path = $serverParams['REQUEST_URI'];
68+
$serverUri = "{$scheme}://{$domain}{$path}"; // FIXME: doublecheck that this is the correct url;
6569

6670
// Create the RDF Adapter
6771
$rdfAdapter = new \Pdsinterop\Rdf\Flysystem\Adapter\Rdf(
@@ -122,8 +126,8 @@ private function getCalendarUrl($userId) {
122126
* @NoCSRFRequired
123127
*/
124128
public function handleRequest($userId, $path) {
125-
$this->calendarUserId = $userId;
126-
129+
$this->calendarUserId = $userId;
130+
127131
$this->rawRequest = \Laminas\Diactoros\ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
128132
$this->response = new \Laminas\Diactoros\Response();
129133

solid/lib/Controller/ContactsController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(
5151

5252
private function getFileSystem($userId) {
5353
// Make sure the root folder has an acl file, as is required by the spec;
54-
// Generate a default file granting the owner full access.
54+
// Generate a default file granting the owner full access.
5555
$defaultAcl = $this->generateDefaultAcl($userId);
5656

5757
// Create the Nextcloud Contacts Adapter
@@ -62,7 +62,11 @@ private function getFileSystem($userId) {
6262
// Create Formats objects
6363
$formats = new \Pdsinterop\Rdf\Formats();
6464

65-
$serverUri = "https://" . $this->rawRequest->getServerParams()["SERVER_NAME"] . $this->rawRequest->getServerParams()["REQUEST_URI"]; // FIXME: doublecheck that this is the correct url;
65+
$serverParams = $this->rawRequest->getServerParams();
66+
$scheme = $serverParams['REQUEST_SCHEME'];
67+
$domain = $serverParams['SERVER_NAME'];
68+
$path = $serverParams['REQUEST_URI'];
69+
$serverUri = "{$scheme}://{$domain}{$path}"; // FIXME: doublecheck that this is the correct url;
6670

6771
// Create the RDF Adapter
6872
$rdfAdapter = new \Pdsinterop\Rdf\Flysystem\Adapter\Rdf(
@@ -123,8 +127,8 @@ private function getContactsUrl($userId) {
123127
* @NoCSRFRequired
124128
*/
125129
public function handleRequest($userId, $path) {
126-
$this->contactsUserId = $userId;
127-
130+
$this->contactsUserId = $userId;
131+
128132
$this->rawRequest = \Laminas\Diactoros\ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
129133
$this->response = new \Laminas\Diactoros\Response();
130134

solid/lib/Controller/PageController.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,29 @@ public function approval($clientId) {
9595
"returnUrl" => $_GET['returnUrl'],
9696
);
9797
$templateResponse = new TemplateResponse('solid', 'sharing', $params);
98+
9899
$policy = new ContentSecurityPolicy();
99100
$policy->addAllowedStyleDomain("data:");
100101

101102
$parsedOrigin = parse_url($clientRegistration['redirect_uris'][0]);
102-
$origin = $parsedOrigin['scheme'] . "://" . $parsedOrigin['host'];
103+
$origin = $parsedOrigin['host'];
103104
if ($origin) {
104-
$policy->addAllowedFormActionDomain($origin);
105+
$policy->addAllowedFormActionDomain($parsedOrigin['scheme'] . "://" . $origin);
105106
$templateResponse->setContentSecurityPolicy($policy);
106107
}
107108
return $templateResponse;
108109
}
109110

111+
/**
112+
* @PublicPage
113+
* @NoAdminRequired
114+
* @NoCSRFRequired
115+
*/
116+
public function customscheme() {
117+
$templateResponse = new TemplateResponse('solid', 'customscheme');
118+
return $templateResponse;
119+
}
120+
110121
/**
111122
* @PublicPage
112123
* @NoAdminRequired

solid/lib/Controller/ProfileController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct(
5454

5555
private function getFileSystem($userId) {
5656
// Make sure the root folder has an acl file, as is required by the spec;
57-
// Generate a default file granting the owner full access.
57+
// Generate a default file granting the owner full access.
5858
$defaultAcl = $this->generateDefaultAcl($userId);
5959
$profile = $this->generateTurtleProfile($userId);
6060

@@ -65,7 +65,11 @@ private function getFileSystem($userId) {
6565
// Create Formats objects
6666
$formats = new \Pdsinterop\Rdf\Formats();
6767

68-
$serverUri = "https://" . $this->rawRequest->getServerParams()["SERVER_NAME"] . $this->rawRequest->getServerParams()["REQUEST_URI"]; // FIXME: doublecheck that this is the correct url;
68+
$serverParams = $this->rawRequest->getServerParams();
69+
$scheme = $serverParams['REQUEST_SCHEME'];
70+
$domain = $serverParams['SERVER_NAME'];
71+
$path = $serverParams['REQUEST_URI'];
72+
$serverUri = "{$scheme}://{$domain}{$path}"; // FIXME: doublecheck that this is the correct url;
6973

7074
// Create the RDF Adapter
7175
$rdfAdapter = new \Pdsinterop\Rdf\Flysystem\Adapter\Rdf(
@@ -139,8 +143,8 @@ private function getStorageUrl($userId) {
139143
* @NoCSRFRequired
140144
*/
141145
public function handleRequest($userId, $path) {
142-
$this->userId = $userId;
143-
146+
$this->userId = $userId;
147+
144148
$this->rawRequest = \Laminas\Diactoros\ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
145149
$this->response = new \Laminas\Diactoros\Response();
146150

solid/lib/Controller/ServerController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,20 @@ public function authorize() {
220220
return $result; // ->addHeader('Access-Control-Allow-Origin', '*');
221221
}
222222

223+
$parsedOrigin = parse_url($clientRegistration['redirect_uris'][0]);
224+
if (
225+
$parsedOrigin['scheme'] != "https" &&
226+
$parsedOrigin['scheme'] != "http" &&
227+
!isset($_GET['customscheme'])
228+
) {
229+
$result = new JSONResponse('Custom schema');
230+
$result->setStatus(302);
231+
$originalRequest = parse_url($_SERVER['REQUEST_URI']);
232+
$customSchemeUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.page.customscheme")) . ($originalRequest['query'] ? "?" . $originalRequest['query'] . "&customscheme=" . $parsedOrigin['scheme'] : '');
233+
$result->addHeader("Location", $customSchemeUrl);
234+
return $result;
235+
}
236+
223237
$user = new \Pdsinterop\Solid\Auth\Entity\User();
224238
$user->setIdentifier($this->getProfilePage());
225239

solid/lib/Controller/StorageController.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ private function getFileSystem() {
6363
// Create Formats objects
6464
$formats = new \Pdsinterop\Rdf\Formats();
6565

66-
$serverUri = "https://" . $this->rawRequest->getServerParams()["SERVER_NAME"] . $this->rawRequest->getServerParams()["REQUEST_URI"]; // FIXME: doublecheck that this is the correct url;
66+
$serverParams = $this->rawRequest->getServerParams();
67+
$scheme = $serverParams['REQUEST_SCHEME'];
68+
$domain = $serverParams['SERVER_NAME'];
69+
$path = $serverParams['REQUEST_URI'];
70+
$serverUri = "{$scheme}://{$domain}{$path}"; // FIXME: doublecheck that this is the correct url;
6771

6872
// Create the RDF Adapter
6973
$rdfAdapter = new \Pdsinterop\Rdf\Flysystem\Adapter\Rdf(
@@ -431,19 +435,19 @@ private function respond($response) {
431435
// $result->addHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
432436
// $result->addHeader('Access-Control-Allow-Origin', $origin);
433437

434-
$policy = new EmptyContentSecurityPolicy();
435-
$policy->addAllowedStyleDomain("*");
436-
$policy->addAllowedStyleDomain("data:");
437-
$policy->addAllowedScriptDomain("*");
438-
$policy->addAllowedImageDomain("*");
439-
$policy->addAllowedFontDomain("*");
440-
$policy->addAllowedConnectDomain("*");
441-
$policy->allowInlineStyle(true);
442-
// $policy->allowInlineScript(true); - removed, this function no longer exists in NC28
443-
$policy->allowEvalScript(true);
444-
$result->setContentSecurityPolicy($policy);
445-
446-
$result->setStatus($statusCode);
438+
$policy = new EmptyContentSecurityPolicy();
439+
$policy->addAllowedStyleDomain("*");
440+
$policy->addAllowedStyleDomain("data:");
441+
$policy->addAllowedScriptDomain("*");
442+
$policy->addAllowedImageDomain("*");
443+
$policy->addAllowedFontDomain("*");
444+
$policy->addAllowedConnectDomain("*");
445+
$policy->allowInlineStyle(true);
446+
// $policy->allowInlineScript(true); - removed, this function no longer exists in NC28
447+
$policy->allowEvalScript(true);
448+
$result->setContentSecurityPolicy($policy);
449+
450+
$result->setStatus($statusCode);
447451
return $result;
448452
}
449453
}

solid/templates/customscheme.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
script('solid', 'customscheme');

0 commit comments

Comments
 (0)