Skip to content

Commit 2abc01c

Browse files
authored
Merge pull request #167 from pdsinterop/prep-release
Prep release 0.9.1
2 parents 6457465 + 52bc264 commit 2abc01c

File tree

10 files changed

+348
-495
lines changed

10 files changed

+348
-495
lines changed

.github/workflows/dependancy-security-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
strategy:
2222
matrix:
23-
php: ['8.1']
23+
php: ['8.2']
2424

2525
steps:
2626
- name: Checkout code

solid/appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ It supports the webid-oidc-dpop-pkce login flow to connect to a Solid App with y
1111
When you do this, the Solid App can store data in your Nextcloud account through the Solid protocol.
1212
1313
]]></description>
14-
<version>0.8.2</version>
14+
<version>0.9.1</version>
1515
<licence>agpl</licence>
1616
<author mail="auke@muze.nl" >Auke van Slooten</author>
1717
<namespace>Solid</namespace>

solid/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"lcobucci/jwt": "^4.1",
3232
"pdsinterop/flysystem-nextcloud": "^0.2",
3333
"pdsinterop/flysystem-rdf": "^0.5",
34-
"pdsinterop/solid-auth": "v0.10.3",
34+
"pdsinterop/solid-auth": "v0.11.0",
3535
"pdsinterop/solid-crud": "^0.7.3",
3636
"psr/log": "^1.1"
3737
},

solid/composer.lock

Lines changed: 198 additions & 383 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

solid/css/settings-admin.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
display: block;
55
}
66
#solid-admin input {
7-
width: 480px;
7+
width: 500px;
88
}
99
#solid-admin textarea {
10-
width: 480px;
10+
width: 500px;
1111
height: 240px;
1212
font-size: 12px;
1313
font-family: monospace;

solid/lib/BaseServerConfig.php

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,116 @@ private function generateKeySet() {
6666
);
6767
return $result;
6868
}
69+
70+
/**
71+
* @param string $clientId
72+
* @return array|null
73+
*/
74+
public function getClientConfigById($clientId) {
75+
$clients = (array)$this->config->getAppValue('solid','clients');
76+
if (array_key_exists($clientId, $clients)) {
77+
return $clients[$clientId];
78+
}
79+
return null;
80+
}
81+
82+
/**
83+
* @return array|null
84+
*/
85+
public function getClients() {
86+
$configKeys = (array)$this->config->getAppKeys('solid');
87+
$clients = [];
88+
foreach ($configKeys as $key) {
89+
if (preg_match("/^client-([a-z0-9]+)$/", $key, $matches)) {
90+
$clientRegistration = json_decode($this->config->getAppValue('solid', $key, '{}'), true);
91+
$clients[] = [
92+
"clientId" => $matches[1],
93+
"clientName" => $clientRegistration['client_name']
94+
];
95+
}
96+
}
97+
return $clients;
98+
}
99+
100+
/**
101+
* @param array $clientConfig
102+
* @return string
103+
*/
104+
public function saveClientConfig($clientId, $clientConfig) {
105+
$clients = (array)$this->config->getAppValue('solid', 'clients');
106+
$clients[$clientId] = $clientConfig;
107+
$this->config->setAppValue('solid','clients', $clients);
108+
return $clientId;
109+
}
110+
111+
/**
112+
* @param string $clientId
113+
* @param array $scopes
114+
*/
115+
public function addScopesToClient($clientId, $scopes) {
116+
$clientScopes = $this->getClientScopes($clientId);
117+
$clientScopes = array_unique(array_merge($clientScopes, $scopes));
118+
$this->setClientScopes($clientId, $clientScopes);
119+
}
120+
121+
/**
122+
* @param string $clientId
123+
* @param array $scopes
124+
*/
125+
public function setClientScopes($clientId, $scopes) {
126+
$clientScopes = (array)$this->config->getAppValue('solid', 'clientScopes');
127+
$clientScopes[$clientId] = $scopes;
128+
$this->config->setAppValue('solid', 'clientScopes', $clientScopes);
129+
}
130+
131+
/**
132+
* @param string $clientId
133+
* @return array
134+
*/
135+
public function getClientScopes($clientId) {
136+
$clientScopes = (array)$this->config->getAppValue('solid', 'clientScopes');
137+
if (array_key_exists($clientId, $clientScopes)) {
138+
return $clientScopes[$clientId];
139+
}
140+
return [];
141+
}
142+
143+
/**
144+
* @param string $clientId
145+
*/
146+
public function removeClientConfig($clientId) {
147+
$clients = (array)$this->config->getAppValue('solid', 'clients');
148+
unset($clients[$clientId]);
149+
$this->config->setAppValue('solid','clients', $clients);
150+
$scopes = (array)$this->config->getAppValue('solid', 'clientScopes');
151+
unset($scopes[$clientId]);
152+
$this->config->setAppValue('solid', 'clientScopes', $scopes);
153+
}
154+
public function saveClientRegistration($origin, $clientData) {
155+
$originHash = md5($origin);
156+
$existingRegistration = $this->getClientRegistration($originHash);
157+
if ($existingRegistration && isset($existingRegistration['redirect_uris'])) {
158+
foreach ($existingRegistration['redirect_uris'] as $uri) {
159+
$clientData['redirect_uris'][] = $uri;
160+
}
161+
$clientData['redirect_uris'] = array_unique($clientData['redirect_uris']);
162+
}
163+
164+
$clientData['client_id'] = $originHash;
165+
$clientData['client_name'] = $origin;
166+
$clientData['client_secret'] = md5(random_bytes(32));
167+
$this->config->setAppValue('solid', "client-" . $originHash, json_encode($clientData));
168+
169+
$this->config->setAppValue('solid', "client-" . $origin, json_encode($clientData));
170+
return $clientData;
171+
}
172+
173+
public function removeClientRegistration($clientId) {
174+
$this->config->deleteAppValue('solid', "client-" . $clientId);
175+
}
176+
177+
public function getClientRegistration($clientId) {
178+
$data = $this->config->getAppValue('solid', "client-" . $clientId, "{}");
179+
return json_decode($data, true);
180+
}
69181
}

solid/lib/Controller/ServerController.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,18 @@ public function register() {
343343
$origin .= ":" . $parsedOrigin['port'];
344344
}
345345

346-
$clientId = $this->config->saveClientRegistration($origin, $clientData);
346+
$clientData = $this->config->saveClientRegistration($origin, $clientData);
347347
$registration = array(
348-
'client_id' => $clientId,
349-
'registration_client_uri' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.server.registeredClient", array("clientId" => $clientId))),
348+
'client_id' => $clientData['client_id'],
349+
/*
350+
FIXME: returning client_secret will trigger calls with basic auth to us. To get this to work, we need this patch:
351+
// File /var/www/vhosts/solid-nextcloud/site/www/lib/base.php not changed so no update needed
352+
// ($request->getRawPathInfo() !== '/apps/oauth2/api/v1/token') &&
353+
// ($request->getRawPathInfo() !== '/apps/solid/token')
354+
*/
355+
// 'client_secret' => $clientData['client_secret'], // FIXME: Returning this means we need to patch Nextcloud to accept tokens on calls to
356+
357+
'registration_client_uri' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.server.registeredClient", array("clientId" => $clientData['client_id']))),
350358
'client_id_issued_at' => $clientData['client_id_issued_at'],
351359
'redirect_uris' => $clientData['redirect_uris'],
352360
);
@@ -413,7 +421,7 @@ private function getClient($clientId) {
413421
if ($clientId && count($clientRegistration)) {
414422
return new \Pdsinterop\Solid\Auth\Config\Client(
415423
$clientId,
416-
$clientRegistration['client_secret'],
424+
$clientRegistration['client_secret'] ?? '',
417425
$clientRegistration['redirect_uris'],
418426
$clientRegistration['client_name']
419427
);

solid/lib/ServerConfig.php

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -26,81 +26,6 @@ public function __construct(IConfig $config, IUrlGenerator $urlGenerator, IUserM
2626
parent::__construct($config);
2727
}
2828

29-
/**
30-
* @param string $clientId
31-
* @return array|null
32-
*/
33-
public function getClientConfigById($clientId) {
34-
$clients = (array)$this->config->getAppValue('solid','clients');
35-
if (array_key_exists($clientId, $clients)) {
36-
return $clients[$clientId];
37-
}
38-
return null;
39-
}
40-
41-
/**
42-
* @return array|null
43-
*/
44-
public function getClients() {
45-
$clients = (array)$this->config->getAppKeys('solid');
46-
return $clients;
47-
}
48-
49-
/**
50-
* @param array $clientConfig
51-
* @return string
52-
*/
53-
public function saveClientConfig($clientConfig) {
54-
$clients = (array)$this->config->getAppValue('solid', 'clients');
55-
$clientId = uuidv4();
56-
$clients[$clientId] = $clientConfig;
57-
$this->config->setAppValue('solid','clients', $clients);
58-
return $clientId;
59-
}
60-
61-
/**
62-
* @param string $clientId
63-
* @param array $scopes
64-
*/
65-
public function addScopesToClient($clientId, $scopes) {
66-
$clientScopes = $this->getClientScopes($clientId);
67-
$clientScopes = array_unique(array_merge($clientScopes, $scopes));
68-
$this->setClientScopes($clientId, $clientScopes);
69-
}
70-
71-
/**
72-
* @param string $clientId
73-
* @param array $scopes
74-
*/
75-
public function setClientScopes($clientId, $scopes) {
76-
$clientScopes = (array)$this->config->getAppValue('solid', 'clientScopes');
77-
$clientScopes[$clientId] = $scopes;
78-
$this->config->setAppValue('solid', 'clientScopes', $clientScopes);
79-
}
80-
81-
/**
82-
* @param string $clientId
83-
* @return array
84-
*/
85-
public function getClientScopes($clientId) {
86-
$clientScopes = (array)$this->config->getAppValue('solid', 'clientScopes');
87-
if (array_key_exists($clientId, $clientScopes)) {
88-
return $clientScopes[$clientId];
89-
}
90-
return [];
91-
}
92-
93-
/**
94-
* @param string $clientId
95-
*/
96-
public function removeClientConfig($clientId) {
97-
$clients = (array)$this->config->getAppValue('solid', 'clients');
98-
unset($clients[$clientId]);
99-
$this->config->setAppValue('solid','clients', $clients);
100-
$scopes = (array)$this->config->getAppValue('solid', 'clientScopes');
101-
unset($scopes[$clientId]);
102-
$this->config->setAppValue('solid', 'clientScopes', $scopes);
103-
}
10429
public function getAllowedClients($userId) {
10530
return json_decode($this->config->getUserValue($userId, 'solid', "allowedClients", "[]"), true);
10631
}
@@ -116,33 +41,6 @@ public function removeAllowedClient($userId, $clientId) {
11641
$this->config->setUserValue($userId, "solid", "allowedClients", json_encode($allowedClients));
11742
}
11843

119-
public function saveClientRegistration($origin, $clientData) {
120-
$originHash = md5($origin);
121-
$existingRegistration = $this->getClientRegistration($originHash);
122-
if ($existingRegistration && isset($existingRegistration['redirect_uris'])) {
123-
foreach ($existingRegistration['redirect_uris'] as $uri) {
124-
$clientData['redirect_uris'][] = $uri;
125-
}
126-
$clientData['redirect_uris'] = array_unique($clientData['redirect_uris']);
127-
}
128-
129-
$clientData['client_name'] = $origin;
130-
$clientData['client_secret'] = md5(random_bytes(32));
131-
$this->config->setAppValue('solid', "client-" . $originHash, json_encode($clientData));
132-
133-
$this->config->setAppValue('solid', "client-" . $origin, json_encode($clientData));
134-
return $originHash;
135-
}
136-
137-
public function removeClientRegistration($clientId) {
138-
$this->config->deleteAppValue('solid', "client-" . $clientId);
139-
}
140-
141-
public function getClientRegistration($clientId) {
142-
$data = $this->config->getAppValue('solid', "client-" . $clientId, "{}");
143-
return json_decode($data, true);
144-
}
145-
14644
public function getProfileData($userId) {
14745
return $this->config->getUserValue($userId, "solid", "profileData", "");
14846
}

solid/lib/Settings/SolidAdmin.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ public function __construct(IConfig $config, IL10N $l) {
2222
* @return TemplateResponse
2323
*/
2424
public function getForm() {
25+
$allClients = $this->serverConfig->getClients();
26+
2527
$parameters = [
2628
'privateKey' => $this->serverConfig->getPrivateKey(),
27-
'encryptionKey' => $this->serverConfig->getEncryptionKey()
29+
'encryptionKey' => $this->serverConfig->getEncryptionKey(),
30+
'clients' => $allClients
2831
];
2932

3033
return new TemplateResponse('solid', 'admin', $parameters, '');

solid/templates/admin.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,21 @@
1616
<textarea id="solid-encryption-key" type="text"><?php p($_['encryptionKey']); ?></textarea>
1717
</label>
1818
</p>
19+
<h2 class="inlineblock"><?php p($l->t('Solid Client Registrations')); ?></h2>
20+
<table class="grid">
21+
<thead>
22+
<tr>
23+
<th>Client ID</th>
24+
<th>Client name</th>
25+
</tr>
26+
</thead>
27+
<tbody>
28+
<?php foreach ($_['clients'] as $client => $registration) { ?>
29+
<tr>
30+
<td><?php p($registration['clientId']); ?></td>
31+
<td><?php p($registration['clientName']); ?></td>
32+
</tr>
33+
<?php } ?>
34+
</tbody>
35+
</table>
1936
</div>

0 commit comments

Comments
 (0)