Skip to content

Commit 5214c52

Browse files
authored
Merge pull request #58 from pdsinterop/release/v0.6
Cleanup for v0.6 release.
2 parents 028a437 + 396d93f commit 5214c52

File tree

9 files changed

+169
-135
lines changed

9 files changed

+169
-135
lines changed

Dockerfile

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,51 @@
11
FROM php:7.3-apache
2-
RUN apt-get update && \
3-
apt-get install -y \
2+
3+
# ==============================================================================
4+
# Set up the machine
5+
# ------------------------------------------------------------------------------
6+
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
7+
8+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
9+
10+
RUN export DEBIAN_FRONTEND=noninteractive \
11+
&& apt-get update && \
12+
apt-get install -y --no-install-recommends \
413
git \
514
libzip-dev \
6-
zlib1g-dev
7-
WORKDIR /tls
8-
RUN openssl req -new -x509 -days 365 -nodes \
9-
-out server.cert \
10-
-keyout server.key \
11-
-subj "/C=RO/ST=Bucharest/L=Bucharest/O=IT/CN=www.example.ro"
12-
RUN docker-php-ext-install mysqli pdo pdo_mysql zip mbstring bcmath
13-
RUN a2enmod rewrite
14-
RUN a2enmod ssl
15-
RUN a2enmod headers
16-
WORKDIR /install
17-
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
18-
RUN php composer-setup.php
19-
RUN php -r "unlink('composer-setup.php');"
20-
ADD . /app
21-
WORKDIR /app
22-
RUN php /install/composer.phar require lcobucci/jwt:3.3.3
23-
RUN php /install/composer.phar update
24-
RUN php /install/composer.phar install
15+
zlib1g-dev \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
RUN mkdir /tls && openssl req -new -x509 -days 365 -nodes \
19+
-out /tls/server.cert \
20+
-keyout /tls/server.key \
21+
-subj "/C=NL/ST=Overijssel/L=Enschede/O=PDS Interop/OU=IT/CN=pdsinterop.org"
22+
23+
RUN docker-php-ext-install \
24+
bcmath \
25+
mbstring \
26+
mysqli \
27+
pdo \
28+
pdo_mysql \
29+
zip
30+
31+
RUN a2enmod headers rewrite ssl
32+
2533
COPY site.conf /etc/apache2/sites-enabled/site.conf
26-
RUN chown -R www-data:www-data /app
34+
35+
WORKDIR /app
36+
2737
EXPOSE 443
38+
# ==============================================================================
39+
40+
41+
# ==============================================================================
42+
# Add the source code
43+
# ------------------------------------------------------------------------------
44+
ARG PROJECT_PATH
45+
RUN : "${PROJECT_PATH:=$PWD}"
46+
47+
COPY "${PROJECT_PATH}" /app/
48+
49+
RUN composer install --no-dev --prefer-dist
50+
RUN chown -R www-data:www-data /app
51+
# ==============================================================================

src/Controller/AuthorizeController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ final public function __invoke(ServerRequestInterface $request, array $args): Re
6868
$response = $this->tokenGenerator->addIdTokenToResponse($response, $clientId, $this->getProfilePage(), $_SESSION['nonce'], $this->config->getPrivateKey());
6969
return $response;
7070
}
71-
}
71+
}

src/Controller/CorsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class CorsController extends ServerController
99
{
1010
final public function __invoke(ServerRequestInterface $request, array $args): ResponseInterface
11-
{
11+
{
1212
return $this->getResponse()->withHeader("Access-Control-Allow-Headers", "*");
1313
}
1414
}

src/Controller/OpenidController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ final public function __invoke(ServerRequestInterface $request, array $args): Re
1313
$server = new \Pdsinterop\Solid\Auth\Server($this->authServerFactory, $this->authServerConfig, $response);
1414
return $server->respondToOpenIdMetadataRequest();
1515
}
16-
}
16+
}

src/Controller/ResourceController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ final public function __invoke(Request $request, array $args) : Response
6262
return $this->WAC->addWACHeaders($request, $response, $webId);
6363
}
6464

65-
private function generateDefaultAcl() {
65+
private function generateDefaultAcl() {
6666
$defaultProfile = <<< EOF
6767
# Root ACL resource for the user account
6868
@prefix acl: <http://www.w3.org/ns/auth/acl#>.

src/Controller/ServerController.php

Lines changed: 102 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ abstract class ServerController extends AbstractController
1717
public function __construct()
1818
{
1919
$this->config = new \Pdsinterop\Solid\ServerConfig(__DIR__.'/../../config/');
20-
21-
$this->authServerConfig = $this->createAuthServerConfig();
22-
$this->authServerFactory = (new \Pdsinterop\Solid\Auth\Factory\AuthorizationServerFactory($this->authServerConfig))->create();
20+
21+
$this->authServerConfig = $this->createAuthServerConfig();
22+
$this->authServerFactory = (new \Pdsinterop\Solid\Auth\Factory\AuthorizationServerFactory($this->authServerConfig))->create();
2323
$this->tokenGenerator = (new \Pdsinterop\Solid\Auth\TokenGenerator($this->authServerConfig));
2424
$this->baseUrl = isset($_ENV['SERVER_ROOT']) ? $_ENV['SERVER_ROOT'] : "https://localhost";
2525
}
@@ -39,98 +39,107 @@ public function getOpenIdEndpoints() {
3939
];
4040
}
4141

42-
public function getKeys() {
43-
$encryptionKey = $this->config->getEncryptionKey();
44-
$privateKey = $this->config->getPrivateKey();
45-
$key = openssl_pkey_get_private($privateKey);
46-
$publicKey = openssl_pkey_get_details($key)['key'];
47-
return [
48-
"encryptionKey" => $encryptionKey,
49-
"privateKey" => $privateKey,
50-
"publicKey" => $publicKey
51-
];
52-
}
42+
public function getKeys()
43+
{
44+
$encryptionKey = $this->config->getEncryptionKey();
45+
$privateKey = $this->config->getPrivateKey();
46+
$key = openssl_pkey_get_private($privateKey);
47+
$publicKey = openssl_pkey_get_details($key)['key'];
5348

54-
public function createAuthServerConfig() {
55-
$clientId = $_GET['client_id']; // FIXME: No request object here to get the client Id from.
56-
$client = $this->getClient($clientId);
57-
$keys = $this->getKeys();
58-
try {
59-
$config = (new \Pdsinterop\Solid\Auth\Factory\ConfigFactory(
60-
$client,
61-
$keys['encryptionKey'],
62-
$keys['privateKey'],
63-
$keys['publicKey'],
64-
$this->getOpenIdEndpoints()
65-
))->create();
66-
} catch(\Throwable $e) {
67-
// var_dump($e);
68-
}
69-
return $config;
70-
}
49+
return [
50+
"encryptionKey" => $encryptionKey,
51+
"privateKey" => $privateKey,
52+
"publicKey" => $publicKey,
53+
];
54+
}
7155

72-
public function getClient($clientId) {
73-
$clientRegistration = $this->config->getClientRegistration($clientId);
74-
75-
if ($clientId && sizeof($clientRegistration)) {
76-
return new \Pdsinterop\Solid\Auth\Config\Client(
77-
$clientId,
78-
$clientRegistration['client_secret'],
79-
$clientRegistration['redirect_uris'],
80-
$clientRegistration['client_name']
81-
);
82-
} else {
83-
return new \Pdsinterop\Solid\Auth\Config\Client('','',array(),'');
84-
}
85-
}
56+
public function createAuthServerConfig()
57+
{
58+
$clientId = $_GET['client_id']; // FIXME: No request object here to get the client Id from.
59+
$client = $this->getClient($clientId);
60+
$keys = $this->getKeys();
61+
try {
62+
$config = (new ConfigFactory(
63+
$client,
64+
$keys['encryptionKey'],
65+
$keys['privateKey'],
66+
$keys['publicKey'],
67+
$this->getOpenIdEndpoints()
68+
))->create();
69+
} catch (Throwable $e) {
70+
// var_dump($e);
71+
}
8672

87-
public function createConfig($baseUrl) {
88-
// if (isset($_GET['client_id'])) {
89-
$clientId = $_GET['client_id'];
90-
$client = $this->getClient($clientId, $baseUrl);
91-
// }
92-
try {
93-
$config = (new \Pdsinterop\Solid\Auth\Factory\ConfigFactory(
94-
$client,
95-
$this->keys['encryptionKey'],
96-
$this->keys['privateKey'],
97-
$this->keys['publicKey'],
98-
$this->openIdConfiguration
99-
))->create();
100-
} catch(\Throwable $e) {
101-
var_dump($e);
102-
}
103-
return $config;
104-
}
105-
106-
public function checkApproval($clientId) {
107-
$allowedClients = $this->config->getAllowedClients($this->userId);
108-
if ($clientId == md5("tester")) { // FIXME: Double check that this is not a security issue; It is only here to help the test suite;
109-
return \Pdsinterop\Solid\Auth\Enum\Authorization::APPROVED;
110-
}
111-
if (in_array($clientId, $allowedClients)) {
112-
return \Pdsinterop\Solid\Auth\Enum\Authorization::APPROVED;
113-
} else {
114-
return \Pdsinterop\Solid\Auth\Enum\Authorization::DENIED;
115-
}
116-
}
117-
118-
public function getProfilePage() {
119-
return $this->baseUrl . "/profile/card#me"; // FIXME: would be better to base this on the available routes if possible.
120-
}
121-
122-
public function getResponseType() {
73+
return $config;
74+
}
75+
76+
public function getClient($clientId)
77+
{
78+
$clientRegistration = $this->config->getClientRegistration($clientId);
79+
80+
if ($clientId && count($clientRegistration)) {
81+
$client = new Client(
82+
$clientId,
83+
$clientRegistration['client_secret'],
84+
$clientRegistration['redirect_uris'],
85+
$clientRegistration['client_name']
86+
);
87+
} else {
88+
$client = new Client('', '', [], '');
89+
}
90+
91+
return $client;
92+
}
93+
94+
public function createConfig()
95+
{
96+
// if (isset($_GET['client_id'])) {
97+
$clientId = $_GET['client_id'];
98+
$client = $this->getClient($clientId);
99+
100+
// }
101+
return (new ConfigFactory(
102+
$client,
103+
$this->keys['encryptionKey'],
104+
$this->keys['privateKey'],
105+
$this->keys['publicKey'],
106+
$this->openIdConfiguration
107+
))->create();
108+
}
109+
public function checkApproval($clientId)
110+
{
111+
$approval = Authorization::DENIED;
112+
113+
$allowedClients = $this->config->getAllowedClients($this->userId);
114+
115+
if (
116+
$clientId === md5("tester") // FIXME: Double check that this is not a security issue; It is only here to help the test suite;
117+
|| in_array($clientId, $allowedClients, true)
118+
) {
119+
$approval = Authorization::APPROVED;
120+
}
121+
122+
return $approval;
123+
}
124+
public function getProfilePage() : string
125+
{
126+
return $this->baseUrl . "/profile/card#me"; // FIXME: would be better to base this on the available routes if possible.
127+
}
128+
129+
public function getResponseType() : string
130+
{
123131
$responseTypes = explode(" ", $_GET['response_type'] ?? '');
124-
foreach ($responseTypes as $responseType) {
125-
switch ($responseType) {
126-
case "token":
127-
return "token";
128-
break;
129-
case "code":
130-
return "code";
131-
break;
132-
}
133-
}
134-
return "token"; // default to token response type;
135-
}
132+
foreach ($responseTypes as $responseType) {
133+
switch ($responseType) {
134+
case "token":
135+
return "token";
136+
break;
137+
case "code":
138+
return "code";
139+
break;
140+
}
141+
}
142+
143+
return "token"; // default to token response type;
144+
}
136145
}

src/Controller/TokenController.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class TokenController extends ServerController
1212
{
1313
final public function __invoke(ServerRequestInterface $request, array $args): ResponseInterface
14-
{
14+
{
1515
$code = $request->getParsedBody()['code'];
1616
$clientId = $request->getParsedBody()['client_id'];
1717
$DPop = new DPop();
@@ -21,16 +21,25 @@ final public function __invoke(ServerRequestInterface $request, array $args): Re
2121
} catch(\Exception $e) {
2222
return $this->getResponse()->withStatus(409, "Invalid token");
2323
}
24-
25-
$response = new \Laminas\Diactoros\Response();
26-
$server = new \Pdsinterop\Solid\Auth\Server($this->authServerFactory, $this->authServerConfig, $response);
24+
25+
$server = new \Pdsinterop\Solid\Auth\Server(
26+
$this->authServerFactory,
27+
$this->authServerConfig,
28+
new \Laminas\Diactoros\Response()
29+
);
30+
2731
$response = $server->respondToAccessTokenRequest($request);
2832

2933
// FIXME: not sure if decoding this here is the way to go.
3034
// FIXME: because this is a public page, the nonce from the session is not available here.
3135
$codeInfo = $this->tokenGenerator->getCodeInfo($code);
32-
$response = $this->tokenGenerator->addIdTokenToResponse($response, $clientId, $codeInfo['user_id'], $_SESSION['nonce'], $this->config->getPrivateKey(), $dpopKey);
3336

34-
return $response;
37+
return $this->tokenGenerator->addIdTokenToResponse($response,
38+
$clientId,
39+
$codeInfo['user_id'],
40+
$_SESSION['nonce'],
41+
$this->config->getPrivateKey(),
42+
$dpopKey
43+
);
3544
}
3645
}

src/ServerConfig.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public function addAllowedClient($userId, $clientId) {
116116
$this->userConfig['allowedClients'] = array_unique($this->userConfig['allowedClients']);
117117
$this->saveUserConfig();
118118
}
119+
119120
public function removeAllowedClient($userId, $clientId) {
120121
$this->userConfig['allowedClients'] = array_diff($this->userConfig['allowedClients'], array($clientId));
121122
$this->saveUserConfig();

web/index.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@
5555
$container->add(ServerRequestInterface::class, Request::class);
5656
$container->add(ResponseInterface::class, Response::class);
5757

58-
/*
59-
$adapter = new \League\Flysystem\Adapter\Local(__DIR__ . '/../tests/fixtures');
60-
$filesystem = new \League\Flysystem\Filesystem($adapter);
61-
$graph = new \EasyRdf_Graph();
62-
$plugin = new \Pdsinterop\Rdf\Flysystem\Plugin\ReadRdf($graph);
63-
$filesystem->addPlugin($plugin);
64-
*/
65-
6658
$container->share(FilesystemInterface::class, function () use ($request) {
6759
// @FIXME: Filesystem root and the $adapter should be configurable.
6860
// Implement this with `$filesystem = \MJRider\FlysystemFactory\create(getenv('STORAGE_ENDPOINT'));`
@@ -129,7 +121,7 @@
129121
OpenidController::class,
130122
ProfileController::class,
131123
RegisterController::class,
132-
StorageController::class,
124+
StorageController::class,
133125
TokenController::class,
134126
];
135127

@@ -200,7 +192,6 @@
200192

201193
array_walk($methods, static function ($method) use (&$group) {
202194
$group->map($method, '/', AddSlashToPathController::class);
203-
// $group->map($method, '//', StorageController::class);
204195
$group->map($method, '{path:.*}', ResourceController::class);
205196
});
206197
});

0 commit comments

Comments
 (0)