Skip to content

Commit 0b2cd62

Browse files
copy authorize code from solid-nextcloud
1 parent e724cab commit 0b2cd62

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

src/Controller/AuthorizeController.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,45 @@ class AuthorizeController extends AbstractController
1010
final public function __invoke(ServerRequestInterface $request, array $args): ResponseInterface
1111
{
1212
$httpHost = $request->getServerParams()['HTTP_HOST'];
13-
$response = $this->getResponse();
1413

15-
$response->getBody()->write("Hello $httpHost");
14+
// // Create a request
15+
// if (!$this->userManager->userExists($this->userId)) {
16+
// $result = new JSONResponse('Authorization required');
17+
// $result->setStatus(401);
18+
// return $result;
19+
// }
1620

17-
return $response;
21+
$parser = new \Lcobucci\JWT\Parser();
22+
$token = $parser->parse($_GET['request']);
23+
$_SESSION['token'] = $token;
24+
25+
$user = new \Pdsinterop\Solid\Auth\Entity\User();
26+
$user->setIdentifier('https://server/profile/card#me');
27+
28+
$getVars = $_GET;
29+
if (!isset($getVars['grant_type'])) {
30+
$getVars['grant_type'] = 'implicit';
31+
}
32+
$getVars['response_type'] = 'token';
33+
$getVars['scope'] = "openid";
34+
35+
if (!isset($getVars['redirect_uri'])) {
36+
$getVars['redirect_uri'] = 'https://solid.community/.well-known/solid/login';
37+
}
38+
$request = \Laminas\Diactoros\ServerRequestFactory::fromGlobals($_SERVER, $getVars, $_POST, $_COOKIE, $_FILES);
39+
$response = new \Laminas\Diactoros\Response();
40+
$server = new \Pdsinterop\Solid\Auth\Server($this->authServerFactory, $this->authServerConfig, $response);
41+
42+
// if (!$this->checkApproval()) {
43+
// $result = new JSONResponse('Approval required');
44+
// $result->setStatus(302);
45+
// $result->addHeader("Location", $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("solid.server.sharing")));
46+
// return $result;
47+
// }
48+
49+
// FIXME: check if the user has approved - if not, show approval screen;
50+
$approval = \Pdsinterop\Solid\Auth\Enum\Authorization::APPROVED;
51+
// $approval = false;
52+
return $server->respondToAuthorizationRequest($request, $user, $approval);
1853
}
1954
}

0 commit comments

Comments
 (0)