Skip to content
Merged
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
4 changes: 2 additions & 2 deletions solid/css/settings-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
display: block;
}
#solid-admin input {
width: 480px;
width: 500px;
}
#solid-admin textarea {
width: 480px;
width: 500px;
height: 240px;
font-size: 12px;
font-family: monospace;
Expand Down
113 changes: 113 additions & 0 deletions solid/lib/BaseServerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,117 @@ private function generateKeySet() {
);
return $result;
}

/**
* @param string $clientId
* @return array|null
*/
public function getClientConfigById($clientId) {
$clients = (array)$this->config->getAppValue('solid','clients');
if (array_key_exists($clientId, $clients)) {
return $clients[$clientId];
}
return null;
}

/**
* @return array|null
*/
public function getClients() {
$configKeys = (array)$this->config->getAppKeys('solid');
$clients = [];
foreach ($configKeys as $key) {
if (preg_match("/^client-([a-z0-9]+)$/", $key, $matches)) {
$clientRegistration = json_decode($this->config->getAppValue('solid', $key, '{}'), true);
$clients[] = [
"clientId" => $matches[1],
"clientName" => $clientRegistration['client_name']
];
}
}
return $clients;
}

/**
* @param array $clientConfig
* @return string
*/
public function saveClientConfig($clientId, $clientConfig) {
$clients = (array)$this->config->getAppValue('solid', 'clients');
$clients[$clientId] = $clientConfig;
$this->config->setAppValue('solid','clients', $clients);
return $clientId;
}

/**
* @param string $clientId
* @param array $scopes
*/
public function addScopesToClient($clientId, $scopes) {
$clientScopes = $this->getClientScopes($clientId);
$clientScopes = array_unique(array_merge($clientScopes, $scopes));
$this->setClientScopes($clientId, $clientScopes);
}

/**
* @param string $clientId
* @param array $scopes
*/
public function setClientScopes($clientId, $scopes) {
$clientScopes = (array)$this->config->getAppValue('solid', 'clientScopes');
$clientScopes[$clientId] = $scopes;
$this->config->setAppValue('solid', 'clientScopes', $clientScopes);
}

/**
* @param string $clientId
* @return array
*/
public function getClientScopes($clientId) {
$clientScopes = (array)$this->config->getAppValue('solid', 'clientScopes');
if (array_key_exists($clientId, $clientScopes)) {
return $clientScopes[$clientId];
}
return [];
}

/**
* @param string $clientId
*/
public function removeClientConfig($clientId) {
$clients = (array)$this->config->getAppValue('solid', 'clients');
unset($clients[$clientId]);
$this->config->setAppValue('solid','clients', $clients);
$scopes = (array)$this->config->getAppValue('solid', 'clientScopes');
unset($scopes[$clientId]);
$this->config->setAppValue('solid', 'clientScopes', $scopes);
}

public function saveClientRegistration($origin, $clientData) {
$originHash = md5($origin);
$existingRegistration = $this->getClientRegistration($originHash);
if ($existingRegistration && isset($existingRegistration['redirect_uris'])) {
foreach ($existingRegistration['redirect_uris'] as $uri) {
$clientData['redirect_uris'][] = $uri;
}
$clientData['redirect_uris'] = array_unique($clientData['redirect_uris']);
}
if (!$existingRegistration) {
$clientData['client_secret'] = md5(random_bytes(32));
}
$clientData['client_name'] = $origin;
$this->config->setAppValue('solid', "client-" . $originHash, json_encode($clientData));
$this->config->setAppValue('solid', "client-" . $origin, json_encode($clientData));
$this->saveClientConfig($originHash, $clientData);
return $originHash;
}

public function removeClientRegistration($clientId) {
$this->config->deleteAppValue('solid', "client-" . $clientId);
}

public function getClientRegistration($clientId) {
$data = $this->config->getAppValue('solid', "client-" . $clientId, "{}");
return json_decode($data, true);
}
}
102 changes: 0 additions & 102 deletions solid/lib/ServerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,81 +26,6 @@ public function __construct(IConfig $config, IUrlGenerator $urlGenerator, IUserM
parent::__construct($config);
}

/**
* @param string $clientId
* @return array|null
*/
public function getClientConfigById($clientId) {
$clients = (array)$this->config->getAppValue('solid','clients');
if (array_key_exists($clientId, $clients)) {
return $clients[$clientId];
}
return null;
}

/**
* @return array|null
*/
public function getClients() {
$clients = (array)$this->config->getAppKeys('solid');
return $clients;
}

/**
* @param array $clientConfig
* @return string
*/
public function saveClientConfig($clientConfig) {
$clients = (array)$this->config->getAppValue('solid', 'clients');
$clientId = uuidv4();
$clients[$clientId] = $clientConfig;
$this->config->setAppValue('solid','clients', $clients);
return $clientId;
}

/**
* @param string $clientId
* @param array $scopes
*/
public function addScopesToClient($clientId, $scopes) {
$clientScopes = $this->getClientScopes($clientId);
$clientScopes = array_unique(array_merge($clientScopes, $scopes));
$this->setClientScopes($clientId, $clientScopes);
}

/**
* @param string $clientId
* @param array $scopes
*/
public function setClientScopes($clientId, $scopes) {
$clientScopes = (array)$this->config->getAppValue('solid', 'clientScopes');
$clientScopes[$clientId] = $scopes;
$this->config->setAppValue('solid', 'clientScopes', $clientScopes);
}

/**
* @param string $clientId
* @return array
*/
public function getClientScopes($clientId) {
$clientScopes = (array)$this->config->getAppValue('solid', 'clientScopes');
if (array_key_exists($clientId, $clientScopes)) {
return $clientScopes[$clientId];
}
return [];
}

/**
* @param string $clientId
*/
public function removeClientConfig($clientId) {
$clients = (array)$this->config->getAppValue('solid', 'clients');
unset($clients[$clientId]);
$this->config->setAppValue('solid','clients', $clients);
$scopes = (array)$this->config->getAppValue('solid', 'clientScopes');
unset($scopes[$clientId]);
$this->config->setAppValue('solid', 'clientScopes', $scopes);
}
public function getAllowedClients($userId) {
return json_decode($this->config->getUserValue($userId, 'solid', "allowedClients", "[]"), true);
}
Expand All @@ -116,33 +41,6 @@ public function removeAllowedClient($userId, $clientId) {
$this->config->setUserValue($userId, "solid", "allowedClients", json_encode($allowedClients));
}

public function saveClientRegistration($origin, $clientData) {
$originHash = md5($origin);
$existingRegistration = $this->getClientRegistration($originHash);
if ($existingRegistration && isset($existingRegistration['redirect_uris'])) {
foreach ($existingRegistration['redirect_uris'] as $uri) {
$clientData['redirect_uris'][] = $uri;
}
$clientData['redirect_uris'] = array_unique($clientData['redirect_uris']);
}

$clientData['client_name'] = $origin;
$clientData['client_secret'] = md5(random_bytes(32));
$this->config->setAppValue('solid', "client-" . $originHash, json_encode($clientData));

$this->config->setAppValue('solid', "client-" . $origin, json_encode($clientData));
return $originHash;
}

public function removeClientRegistration($clientId) {
$this->config->deleteAppValue('solid', "client-" . $clientId);
}

public function getClientRegistration($clientId) {
$data = $this->config->getAppValue('solid', "client-" . $clientId, "{}");
return json_decode($data, true);
}

public function getProfileData($userId) {
return $this->config->getUserValue($userId, "solid", "profileData", "");
}
Expand Down
5 changes: 4 additions & 1 deletion solid/lib/Settings/SolidAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ public function __construct(IConfig $config, IL10N $l) {
* @return TemplateResponse
*/
public function getForm() {
$allClients = $this->serverConfig->getClients();

$parameters = [
'privateKey' => $this->serverConfig->getPrivateKey(),
'encryptionKey' => $this->serverConfig->getEncryptionKey()
'encryptionKey' => $this->serverConfig->getEncryptionKey(),
'clients' => $allClients
];

return new TemplateResponse('solid', 'admin', $parameters, '');
Expand Down
17 changes: 17 additions & 0 deletions solid/templates/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,21 @@
<textarea id="solid-encryption-key" type="text"><?php p($_['encryptionKey']); ?></textarea>
</label>
</p>
<h2 class="inlineblock"><?php p($l->t('Solid Client Registrations')); ?></h2>
<table class="grid">
<thead>
<tr>
<th>Client ID</th>
<th>Client name</th>
</tr>
</thead>
<tbody>
<?php foreach ($_['clients'] as $client => $registration) { ?>
<tr>
<td><?php p($registration['clientId']); ?></td>
<td><?php p($registration['clientName']); ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
Loading