Skip to content

Commit 073e532

Browse files
authored
Merge pull request #63 from pdsinterop/fix/controllers
Fixes for controllers
2 parents 59e80f9 + c255b56 commit 073e532

4 files changed

Lines changed: 38 additions & 29 deletions

File tree

solid/lib/Controller/AppController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private function getUserApps($userId) {
3434
$userApps = [];
3535
if ($this->userManager->userExists($userId)) {
3636
$allowedClients = $this->config->getAllowedClients($userId);
37-
foreach ($userClients as $clientId) {
37+
foreach ($allowedClients as $clientId) {
3838
$registration = $this->config->getClientRegistration($clientId);
3939
$userApps[] = $registration['client_name'];
4040
}
@@ -52,7 +52,7 @@ private function getAppsList() {
5252
foreach ($appsList as $key => $app) {
5353
$parsedOrigin = parse_url($app['launchUrl']);
5454
$origin = $parsedOrigin['host'];
55-
if (in_array($userApps, $origin)) {
55+
if (in_array($origin, $userApps, true)) {
5656
$appsList[$key]['registered'] = 1;
5757
} else {
5858
$appsList[$key]['registered'] = 0;

solid/lib/Controller/PageController.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ public function index() {
4646
private function getUserProfile($userId) {
4747
if ($this->userManager->userExists($userId)) {
4848
$user = $this->userManager->get($userId);
49-
$profile = array(
50-
'id' => $userId,
51-
'displayName' => $user->getDisplayName(),
52-
'profileUri' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.profile.handleGet", array("userId" => $userId, "path" => "/card"))) . "#me",
53-
'solidNavigation' => array(
54-
"profile" => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.page.profile", array("userId" => $this->userId))),
55-
"launcher" => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.app.appLauncher", array())),
56-
)
57-
);
58-
return $profile;
49+
if ($user !== null) {
50+
$profile = array(
51+
'id' => $userId,
52+
'displayName' => $user->getDisplayName(),
53+
'profileUri' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.profile.handleGet", array("userId" => $userId, "path" => "/card"))) . "#me",
54+
'solidNavigation' => array(
55+
"profile" => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.page.profile", array("userId" => $this->userId))),
56+
"launcher" => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.app.appLauncher", array())),
57+
)
58+
);
59+
return $profile;
60+
}
5961
}
6062
return false;
6163
}

solid/lib/Controller/ProfileController.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -267,18 +267,20 @@ private function getUserProfile($userId) {
267267
}
268268
}
269269
}
270-
$profile = array(
271-
'id' => $userId,
272-
'displayName' => $user->getDisplayName(),
273-
'profileUri' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.profile.handleGet", array("userId" => $userId, "path" => "/card"))) . "#me",
274-
'friends' => $friends,
275-
'inbox' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.storage.handleGet", array("userId" => $userId, "path" => "/inbox/"))),
276-
'preferences' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.storage.handleGet", array("userId" => $userId, "path" => "/settings/preferences.ttl"))),
277-
'privateTypeIndex' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.storage.handleGet", array("userId" => $userId, "path" => "/settings/privateTypeIndex.ttl"))),
278-
'publicTypeIndex' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.storage.handleGet", array("userId" => $userId, "path" => "/settings/publicTypeIndex.ttl"))),
279-
'storage' => $this->getStorageUrl($userId)
280-
);
281-
return $profile;
270+
if ($user !== null) {
271+
$profile = array(
272+
'id' => $userId,
273+
'displayName' => $user->getDisplayName(),
274+
'profileUri' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.profile.handleGet", array("userId" => $userId, "path" => "/card"))) . "#me",
275+
'friends' => $friends,
276+
'inbox' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.storage.handleGet", array("userId" => $userId, "path" => "/inbox/"))),
277+
'preferences' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.storage.handleGet", array("userId" => $userId, "path" => "/settings/preferences.ttl"))),
278+
'privateTypeIndex' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.storage.handleGet", array("userId" => $userId, "path" => "/settings/privateTypeIndex.ttl"))),
279+
'publicTypeIndex' => $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.storage.handleGet", array("userId" => $userId, "path" => "/settings/publicTypeIndex.ttl"))),
280+
'storage' => $this->getStorageUrl($userId)
281+
);
282+
return $profile;
283+
}
282284
}
283285
return false;
284286
}
@@ -331,4 +333,4 @@ private function generateTurtleProfile($userId) {
331333
$combinedProfile = $graph->serialise("turtle");
332334
return $combinedProfile;
333335
}
334-
}
336+
}

solid/lib/Controller/ServerController.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private function createAuthServerConfig() {
8686
$client = $this->getClient($clientId);
8787
$keys = $this->getKeys();
8888
try {
89-
$config = (new \Pdsinterop\Solid\Auth\Factory\ConfigFactory(
89+
return (new \Pdsinterop\Solid\Auth\Factory\ConfigFactory(
9090
$client,
9191
$keys['encryptionKey'],
9292
$keys['privateKey'],
@@ -95,8 +95,8 @@ private function createAuthServerConfig() {
9595
))->create();
9696
} catch(\Throwable $e) {
9797
// var_dump($e);
98+
return null;
9899
}
99-
return $config;
100100
}
101101

102102
/**
@@ -154,6 +154,11 @@ public function authorize() {
154154
$getVars['scope'] = "openid" ;
155155

156156
if (!isset($getVars['redirect_uri'])) {
157+
if (!isset($token)) {
158+
$result = new JSONResponse('Bad request, does not contain valid token');
159+
$result->setStatus(400);
160+
return $result->addHeader('Access-Control-Allow-Origin', '*');
161+
}
157162
try {
158163
$getVars['redirect_uri'] = $token->getClaim("redirect_uri");
159164
} catch(\Exception $e) {
@@ -248,7 +253,7 @@ public function token() {
248253

249254
$response = new \Laminas\Diactoros\Response();
250255
$server = new \Pdsinterop\Solid\Auth\Server($this->authServerFactory, $this->authServerConfig, $response);
251-
$response = $server->respondToAccessTokenRequest($request, $user, $approval);
256+
$response = $server->respondToAccessTokenRequest($request);
252257

253258
// FIXME: not sure if decoding this here is the way to go.
254259
// FIXME: because this is a public page, the nonce from the session is not available here.
@@ -286,7 +291,7 @@ public function register() {
286291
$clientData = file_get_contents('php://input');
287292
$clientData = json_decode($clientData, true);
288293
if (!$clientData['redirect_uris']) {
289-
return new JSONReponse("Missing redirect URIs");
294+
return new JSONResponse("Missing redirect URIs");
290295
}
291296
$clientData['client_id_issued_at'] = time();
292297
$parsedOrigin = parse_url($clientData['redirect_uris'][0]);

0 commit comments

Comments
 (0)