Skip to content

Commit 9ec1c81

Browse files
use HTTP_HOSt from server params
1 parent c913ac4 commit 9ec1c81

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/Controller/OpenidController.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,27 @@
88
class OpenidController extends AbstractController
99
{
1010
private $keys;
11-
private $openIdConfiguration;
12-
private $authServerConfig;
13-
private $authServerFactory;
1411

1512
public function __construct(){
1613
// parent::__construct();
1714
require_once(__DIR__.'/../../vendor/autoload.php');
1815

1916
$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();
2417
}
2518
private function linkToRoute($route) {
26-
return '/some/route';
19+
return "/$route";
2720
}
28-
private function getBaseUrl() {
29-
return 'http://localhost/';
21+
private function getBaseUrl($httpHost) {
22+
return "http://$httpHost";
3023
}
31-
private function getAbsoluteUrl($relativeUrl) {
32-
return 'http://localhost/some/route';
24+
private function getAbsoluteUrl($relativeUrl, $baseUrl) {
25+
return "$baseUrl$relativeUrl";
3326
}
34-
private function getOpenIdConfiguration() {
27+
private function getOpenIdConfiguration($baseUrl) {
3528
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")),
29+
'issuer' => $baseUrl,
30+
'authorization_endpoint' => $this->getAbsoluteUrl($this->linkToRoute("authorize"), $baseUrl),
31+
'jwks_uri' => $this->getAbsoluteUrl($this->linkToRoute("jwks"), $baseUrl),
3932
"response_types_supported" => array("code","code token","code id_token","id_token code","id_token","id_token token","code id_token token","none"),
4033
"token_types_supported" => array("legacyPop","dpop"),
4134
"response_modes_supported" => array("query","fragment"),
@@ -51,12 +44,12 @@ private function getOpenIdConfiguration() {
5144
"request_parameter_supported" => true,
5245
"request_uri_parameter_supported" => false,
5346
"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"))
47+
"check_session_iframe" => $this->getAbsoluteUrl($this->linkToRoute("session"), $baseUrl),
48+
"end_session_endpoint" => $this->getAbsoluteUrl($this->linkToRoute("logout"), $baseUrl),
49+
"token_endpoint" => $this->getAbsoluteUrl($this->linkToRoute("token"), $baseUrl),
50+
"userinfo_endpoint" => $this->getAbsoluteUrl($this->linkToRoute("userinfo"), $baseUrl),
51+
"registration_endpoint" => $this->getAbsoluteUrl($this->linkToRoute("register"), $baseUrl),
52+
// "sharing_endpoint" => $this->getAbsoluteUrl($this->linkToRoute("sharing"), $baseUrl)
6053
);
6154
}
6255
private function getKeys() {
@@ -104,7 +97,7 @@ private function getKeys() {
10497
private function getClientId() {
10598
return "CoolApp";
10699
}
107-
private function getClient($clientId) {
100+
private function getClient($clientId, $baseUrl) {
108101
if (!$clientId) {
109102
$clientId = $this->getClientId(); // FIXME: only continue if a clientId is set;
110103
}
@@ -114,7 +107,7 @@ private function getClient($clientId) {
114107

115108
// FIXME: use the redirect URIs as indicated by the client;
116109
$clientRedirectUris = array(
117-
$this->getAbsoluteURL($this->linkToRoute("solid.server.token")),
110+
$this->getAbsoluteURL($this->linkToRoute("token"), $baseUrl),
118111
'https://solid.community/.well-known/solid/login',
119112
'http://localhost:3001/redirect'
120113
);
@@ -131,10 +124,10 @@ private function getClient($clientId) {
131124
}
132125
}
133126

134-
private function createConfig() {
127+
private function createConfig($baseUrl) {
135128
// if (isset($_GET['client_id'])) {
136129
$clientId = $_GET['client_id'];
137-
$client = $this->getClient($clientId);
130+
$client = $this->getClient($clientId, $baseUrl);
138131
// }
139132
try {
140133
$config = (new \Pdsinterop\Solid\Auth\Factory\ConfigFactory(
@@ -152,6 +145,13 @@ private function createConfig() {
152145

153146
final public function __invoke(ServerRequestInterface $request, array $args): ResponseInterface
154147
{
148+
$httpHost = $request->getServerParams()['HTTP_HOST'];
149+
$baseUrl = $this->getBaseUrl($httpHost);
150+
$this->openIdConfiguration = $this->getOpenIdConfiguration($baseUrl);
151+
152+
$this->authServerConfig = $this->createConfig($baseUrl);
153+
$this->authServerFactory = (new \Pdsinterop\Solid\Auth\Factory\AuthorizationServerFactory($this->authServerConfig))->create();
154+
155155
$response = $this->getResponse();
156156
$server = new \Pdsinterop\Solid\Auth\Server($this->authServerFactory, $this->authServerConfig, $response);
157157
return $server->respondToOpenIdMetadataRequest();

0 commit comments

Comments
 (0)