Skip to content

Commit f5e0165

Browse files
committed
Merge branch 'feature/client-registrations-panel' into prep-release
2 parents 6d5bfcd + 8181115 commit f5e0165

5 files changed

Lines changed: 136 additions & 106 deletions

File tree

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: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,117 @@ 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+
155+
public function saveClientRegistration($origin, $clientData) {
156+
$originHash = md5($origin);
157+
$existingRegistration = $this->getClientRegistration($originHash);
158+
if ($existingRegistration && isset($existingRegistration['redirect_uris'])) {
159+
foreach ($existingRegistration['redirect_uris'] as $uri) {
160+
$clientData['redirect_uris'][] = $uri;
161+
}
162+
$clientData['redirect_uris'] = array_unique($clientData['redirect_uris']);
163+
}
164+
if (!$existingRegistration) {
165+
$clientData['client_secret'] = md5(random_bytes(32));
166+
}
167+
$clientData['client_name'] = $origin;
168+
$this->config->setAppValue('solid', "client-" . $originHash, json_encode($clientData));
169+
$this->config->setAppValue('solid', "client-" . $origin, json_encode($clientData));
170+
$this->saveClientConfig($originHash, $clientData);
171+
return $originHash;
172+
}
173+
174+
public function removeClientRegistration($clientId) {
175+
$this->config->deleteAppValue('solid', "client-" . $clientId);
176+
}
177+
178+
public function getClientRegistration($clientId) {
179+
$data = $this->config->getAppValue('solid', "client-" . $clientId, "{}");
180+
return json_decode($data, true);
181+
}
69182
}

solid/lib/ServerConfig.php

Lines changed: 0 additions & 103 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,34 +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_id'] = $originHash;
130-
$clientData['client_name'] = $origin;
131-
$clientData['client_secret'] = md5(random_bytes(32));
132-
$this->config->setAppValue('solid', "client-" . $originHash, json_encode($clientData));
133-
134-
$this->config->setAppValue('solid', "client-" . $origin, json_encode($clientData));
135-
return $clientData;
136-
}
137-
138-
public function removeClientRegistration($clientId) {
139-
$this->config->deleteAppValue('solid', "client-" . $clientId);
140-
}
141-
142-
public function getClientRegistration($clientId) {
143-
$data = $this->config->getAppValue('solid', "client-" . $clientId, "{}");
144-
return json_decode($data, true);
145-
}
146-
14744
public function getProfileData($userId) {
14845
return $this->config->getUserValue($userId, "solid", "profileData", "");
14946
}

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)