Skip to content

Commit b6ef259

Browse files
Use php-solid-auth to generate /.well-known/openid-configuration
1 parent e6b94d6 commit b6ef259

File tree

2 files changed

+149
-7
lines changed

2 files changed

+149
-7
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
"config": {
88
"bin-dir": "./bin",
99
"platform": {
10-
"php": "7.1.33",
10+
"php": "7.3.11",
1111
"ext-dom": "0.0.0",
1212
"ext-mbstring": "0.0.0"
1313
},
1414
"sort-packages": true
1515
},
1616
"description": "Standalone Solid Server written in PHP by PDS Interop.",
1717
"license": "MIT",
18-
"name": "pdsinterop/solid-server",
18+
"name": "pdsinterop/php-solid-server",
1919
"require": {
2020
"php": "~7.1",
2121
"ext-json": "*",
@@ -29,6 +29,7 @@
2929
"league/oauth2-server": "^8.0",
3030
"league/route": "^4.5",
3131
"pdsinterop/flysystem-rdf": "^0.1",
32+
"pdsinterop/solid-auth": "dev-feature/implicit-grant",
3233
"php-http/httplug": "^2.1",
3334
"phptal/phptal": "^1.4"
3435
},

src/Controller/OpenidController.php

Lines changed: 146 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,154 @@
66
use Psr\Http\Message\ServerRequestInterface;
77

88
class OpenidController extends AbstractController
9-
{
9+
{
10+
private $keys;
11+
private $openIdConfiguration;
12+
private $authServerConfig;
13+
private $authServerFactory;
14+
15+
public function __construct(){
16+
// parent::__construct();
17+
require_once(__DIR__.'/../../vendor/autoload.php');
18+
19+
$this->keys = $this->getKeys();
20+
$this->openIdConfiguration = $this->getOpenIdConfiguration();
21+
22+
$this->authServerConfig = $this->createConfig();
23+
$this->authServerFactory = (new \Pdsinterop\Solid\Auth\Factory\AuthorizationServerFactory($this->authServerConfig))->create();
24+
}
25+
private function linkToRoute($route) {
26+
return '/some/route';
27+
}
28+
private function getBaseUrl() {
29+
return 'http://localhost/';
30+
}
31+
private function getAbsoluteUrl($relativeUrl) {
32+
return 'http://localhost/some/route';
33+
}
34+
private function getOpenIdConfiguration() {
35+
return array(
36+
'issuer' => $this->getBaseUrl(),
37+
'authorization_endpoint' => $this->getAbsoluteUrl($this->linkToRoute("solid.server.authorize")),
38+
'jwks_uri' => $this->getAbsoluteUrl($this->linkToRoute("solid.server.jwks")),
39+
"response_types_supported" => array("code","code token","code id_token","id_token code","id_token","id_token token","code id_token token","none"),
40+
"token_types_supported" => array("legacyPop","dpop"),
41+
"response_modes_supported" => array("query","fragment"),
42+
"grant_types_supported" => array("authorization_code","implicit","refresh_token","client_credentials"),
43+
"subject_types_supported" => ["public"],
44+
"id_token_signing_alg_values_supported" => ["RS256"],
45+
"token_endpoint_auth_methods_supported" => "client_secret_basic",
46+
"token_endpoint_auth_signing_alg_values_supported" => ["RS256"],
47+
"display_values_supported" => [],
48+
"claim_types_supported" => ["normal"],
49+
"claims_supported" => [],
50+
"claims_parameter_supported" => false,
51+
"request_parameter_supported" => true,
52+
"request_uri_parameter_supported" => false,
53+
"require_request_uri_registration" => false,
54+
"check_session_iframe" => $this->getAbsoluteUrl($this->linkToRoute("solid.server.session")),
55+
"end_session_endpoint" => $this->getAbsoluteUrl($this->linkToRoute("solid.server.logout")),
56+
"token_endpoint" => $this->getAbsoluteUrl($this->linkToRoute("solid.server.token")),
57+
"userinfo_endpoint" => $this->getAbsoluteUrl($this->linkToRoute("solid.server.userinfo")),
58+
"registration_endpoint" => $this->getAbsoluteUrl($this->linkToRoute("solid.server.register")),
59+
// "sharing_endpoint" => $this->getAbsoluteUrl($this->linkToRoute("solid.server.sharing"))
60+
);
61+
}
62+
private function getKeys() {
63+
// FIXME: read these from the solid config in nextcloud;
64+
$encryptionKey = 'P76gcBVeXsVzrHiYp4IIwore5rQz4cotdZ2j9GV5V04=';
65+
$privateKey = <<<EOF
66+
-----BEGIN RSA PRIVATE KEY-----
67+
MIIEpAIBAAKCAQEAvqb0htUFZaZ+z5rn7cHWg0VzsSoVnusbtJvwWtHfD0T0s6Hb
68+
OqzE5h2fgdGbB49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OPy
84+
xFWWANgK/yWMTOGV7JFWpIocvz/22d/V+QqrHSdP4UxBi9oSIvF1I+FYXKZTtZNE
85+
wFWH8SXHKHhKyTgmvBjmal1xVFyJu0WzYX+TbjcykoI0IZFSw4ilxdw1L67G88yM
86+
1M7NLKtLuCpKgpOspZjOmCvTAoGAGji6KswYCt2SaNkmIx/jpUTInSR8xpnEtD7H
87+
QOmeEPKxmFwON/eKMIUXcaoRsNAEIvOxb4MT4YiLHJIIC0XuxxS6xF/XP0hBBloW
88+
s1jxC/cgLJixKa5uoNcHN1OxwMBQECgvo+GTDnwkWw4QA9kgwAOroxQ4EvMxrqHS
89+
O9Pvn4ECgYA7xr/3Sz8n+BhgOdABW0m91P144rK9QDYiaClSxAha1KiFunmAy3pB
90+
Uxdl4yTCTA9yKIH7X3bShDXnj+RmEZ+SkwzpPuKvAE8ZkZQuXv41anFrZYkR2PZy
91+
oYiERqXgH5yS/mkDeXRFx1nWsVxjoLWfd/Vi7Lr43cuYFy4UjqXZdg==
92+
-----END RSA PRIVATE KEY-----
93+
EOF;
94+
95+
$key = openssl_pkey_get_private($privateKey);
96+
$publicKey = openssl_pkey_get_details($key)['key'];
97+
98+
return array(
99+
"encryptionKey" => $encryptionKey,
100+
"privateKey" => $privateKey,
101+
"publicKey" => $publicKey
102+
);
103+
}
104+
private function getClientId() {
105+
return "CoolApp";
106+
}
107+
private function getClient($clientId) {
108+
if (!$clientId) {
109+
$clientId = $this->getClientId(); // FIXME: only continue if a clientId is set;
110+
}
111+
112+
if ($clientId) { // FIXME: and check that we know this client and get the client secret/client name for this client;
113+
$clientSecret = "super-secret-secret-squirrel";
114+
115+
// FIXME: use the redirect URIs as indicated by the client;
116+
$clientRedirectUris = array(
117+
$this->getAbsoluteURL($this->linkToRoute("solid.server.token")),
118+
'https://solid.community/.well-known/solid/login',
119+
'http://localhost:3001/redirect'
120+
);
121+
$clientName = "Nextcloud";
122+
123+
return new \Pdsinterop\Solid\Auth\Config\Client(
124+
$clientId,
125+
$clientSecret,
126+
$clientRedirectUris,
127+
$clientName
128+
);
129+
} else {
130+
return new \Pdsinterop\Solid\Auth\Config\Client('','',array(),'');
131+
}
132+
}
133+
134+
private function createConfig() {
135+
// if (isset($_GET['client_id'])) {
136+
$clientId = $_GET['client_id'];
137+
$client = $this->getClient($clientId);
138+
// }
139+
try {
140+
$config = (new \Pdsinterop\Solid\Auth\Factory\ConfigFactory(
141+
$client,
142+
$this->keys['encryptionKey'],
143+
$this->keys['privateKey'],
144+
$this->keys['publicKey'],
145+
$this->openIdConfiguration
146+
))->create();
147+
} catch(\Throwable $e) {
148+
var_dump($e);
149+
}
150+
return $config;
151+
}
152+
10153
final public function __invoke(ServerRequestInterface $request, array $args): ResponseInterface
11154
{
12155
$response = $this->getResponse();
13-
14-
$response->getBody()->write('<h1>Hello, Openid!</h1>');
15-
16-
return $response;
156+
$server = new \Pdsinterop\Solid\Auth\Server($this->authServerFactory, $this->authServerConfig, $response);
157+
return $server->respondToOpenIdMetadataRequest();
17158
}
18159
}

0 commit comments

Comments
 (0)