Skip to content

Commit a48d395

Browse files
authored
Merge pull request #212 from pdsinterop/feature/user-backend
Feature/user backend
2 parents 3ad37fa + 16f8048 commit a48d395

File tree

4 files changed

+77
-9
lines changed

4 files changed

+77
-9
lines changed

solid/appinfo/info.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ When you do this, the Solid App can store data in your Nextcloud account through
1616
<author mail="[email protected]" >Auke van Slooten</author>
1717
<namespace>Solid</namespace>
1818
<category>integration</category>
19+
<types>
20+
<authentication/>
21+
</types>
1922
<bugs>https://github.com/pdsinterop/solid-nextcloud/issues</bugs>
2023
<dependencies>
2124
<nextcloud min-version="28" max-version="30"/>

solid/lib/AppInfo/Application.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,31 @@
1010
use OCA\Solid\Service\SolidWebhookService;
1111
use OCA\Solid\Db\SolidWebhookMapper;
1212
use OCA\Solid\Middleware\SolidCorsMiddleware;
13+
use OCA\Solid\ClientAuth;
1314

1415
use OCP\AppFramework\App;
1516
use OCP\AppFramework\Bootstrap\IBootContext;
1617
use OCP\AppFramework\Bootstrap\IBootstrap;
1718
use OCP\AppFramework\Bootstrap\IRegistrationContext;
1819
use OCP\IDBConnection;
20+
use OCP\IRequest;
21+
use OCP\Server;
1922

2023
class Application extends App implements IBootstrap {
2124
public const APP_ID = 'solid';
22-
public static $userSubDomainsEnabled;
25+
public static $userSubDomainsEnabled;
2326

2427
/**
2528
* @param array $urlParams
2629
*/
2730
public function __construct(array $urlParams = []) {
31+
$request = \OCP\Server::get(\OCP\IRequest::class);
32+
$rawPathInfo = $request->getRawPathInfo();
33+
34+
if ($rawPathInfo == '/apps/solid/token') {
35+
$backend = new \OCA\Solid\ClientAuth();
36+
\OC::$server->getUserManager()->registerBackend($backend);
37+
}
2838
parent::__construct(self::APP_ID, $urlParams);
2939
}
3040

solid/lib/ClientAuth.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/*
3+
IMPORTANT WARNING!
4+
5+
This class is a user backend that accepts 'all'.
6+
Any user, and password is currently accepted as true.
7+
8+
The reason this is here is that Solid clients will use basic
9+
authentication to do a POST request to the token endpoint,
10+
where the actual authorization happens.
11+
12+
The security for this user backend lies in the fact that it
13+
is only activated for the token endpoint in the Solid app.
14+
15+
In /lib/AppInfo/Application.php there is a check for the
16+
token endpoint before this thing activates.
17+
18+
It is completely unsuitable as an actual user backend in the
19+
normal sense of the word.
20+
21+
It is here to allow the token requests with basic
22+
authentication requests to pass to us.
23+
*/
24+
25+
namespace OCA\Solid;
26+
27+
use OCP\User\Backend\ABackend;
28+
use OCP\User\Backend\ICheckPasswordBackend;
29+
30+
/**
31+
* @package OCA\Solid
32+
*/
33+
class ClientAuth extends ABackend implements ICheckPasswordBackend {
34+
public function __construct() {
35+
}
36+
37+
public function checkPassword(string $username, string $password) {
38+
return true;
39+
}
40+
41+
public function getBackendName() {
42+
return "Solid";
43+
}
44+
public function deleteUser($uid) {
45+
return false;
46+
}
47+
public function getUsers($search = "", $limit = null, $offset = null, $callback = null) {
48+
return [];
49+
}
50+
public function userExists($uid) {
51+
return true;
52+
}
53+
public function getDisplayName($uid) {
54+
return "Solid client";
55+
}
56+
public function getDisplayNames($search = "", $limit = null, $offset = null) {
57+
return [];
58+
}
59+
public function hasUserListings() {
60+
return false;
61+
}
62+
}

solid/lib/Controller/ServerController.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,7 @@ public function register() {
385385
$clientData = $this->config->saveClientRegistration($origin, $clientData);
386386
$registration = array(
387387
'client_id' => $clientData['client_id'],
388-
/*
389-
FIXME: returning client_secret will trigger calls with basic auth to us. To get this to work, we need this patch:
390-
// File /var/www/vhosts/solid-nextcloud/site/www/lib/base.php not changed so no update needed
391-
// ($request->getRawPathInfo() !== '/apps/oauth2/api/v1/token') &&
392-
// ($request->getRawPathInfo() !== '/apps/solid/token')
393-
*/
394-
// 'client_secret' => $clientData['client_secret'], // FIXME: Returning this means we need to patch Nextcloud to accept tokens on calls to
395-
388+
'client_secret' => $clientData['client_secret'],
396389
'registration_client_uri' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.server.registeredClient", array("clientId" => $clientData['client_id']))),
397390
'client_id_issued_at' => $clientData['client_id_issued_at'],
398391
'redirect_uris' => $clientData['redirect_uris'],

0 commit comments

Comments
 (0)