Skip to content

Commit d22a7f2

Browse files
committed
Change ServerController to use the improved TokenGenerator class.
1 parent e1a26ac commit d22a7f2

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

solid/lib/Controller/ServerController.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ServerController extends Controller
4343
/* @var Pdsinterop\Solid\Auth\Factory\AuthorizationServerFactory */
4444
private $authServerFactory;
4545

46-
/* @var Pdsinterop\Solid\Auth\TokenGenerator */
46+
/* @var \Pdsinterop\Solid\Auth\TokenGenerator */
4747
private $tokenGenerator;
4848

4949
public function __construct(
@@ -73,7 +73,8 @@ public function __construct(
7373

7474
$this->tokenGenerator = new \Pdsinterop\Solid\Auth\TokenGenerator(
7575
$this->authServerConfig,
76-
$this->getDpopValidFor()
76+
$this->getDpopValidFor(),
77+
$this->getDpop()
7778
);
7879
}
7980

@@ -198,7 +199,13 @@ public function authorize() {
198199
$server = new \Pdsinterop\Solid\Auth\Server($this->authServerFactory, $this->authServerConfig, $response);
199200

200201
$response = $server->respondToAuthorizationRequest($request, $user, $approval);
201-
$response = $this->tokenGenerator->addIdTokenToResponse($response, $clientId, $this->getProfilePage(), $this->session->get("nonce"), $this->config->getPrivateKey());
202+
$response = $this->tokenGenerator->addIdTokenToResponse(
203+
$response,
204+
$clientId,
205+
$this->getProfilePage(),
206+
$this->session->get("nonce"),
207+
$this->config->getPrivateKey()
208+
);
202209

203210
return $this->respond($response); // ->addHeader('Access-Control-Allow-Origin', '*');
204211
}
@@ -256,26 +263,23 @@ public function token() {
256263
$code = $request->getParsedBody()['code'];
257264
$clientId = $request->getParsedBody()['client_id'];
258265

259-
$response = new \Laminas\Diactoros\Response();
260-
261-
$dpop = $this->getDpop();
262266
$httpDpop = $request->getServerParams()['HTTP_DPOP'];
263267

264-
try {
265-
$dpopKey = $dpop->getDPopKey($httpDpop, $request);
266-
} catch(\Pdsinterop\Solid\Auth\Exception\Exception $e) {
267-
$response = $response->withStatus(Http::STATUS_CONFLICT, "Invalid token " . $e->getMessage());
268-
return $this->respond($response);
269-
}
270-
271268
$response = new \Laminas\Diactoros\Response();
272269
$server = new \Pdsinterop\Solid\Auth\Server($this->authServerFactory, $this->authServerConfig, $response);
273270
$response = $server->respondToAccessTokenRequest($request);
274271

275272
// FIXME: not sure if decoding this here is the way to go.
276273
// FIXME: because this is a public page, the nonce from the session is not available here.
277274
$codeInfo = $this->tokenGenerator->getCodeInfo($code);
278-
$response = $this->tokenGenerator->addIdTokenToResponse($response, $clientId, $codeInfo['user_id'], ($_SESSION['nonce'] ?? ''), $this->config->getPrivateKey(), $dpopKey);
275+
$response = $this->tokenGenerator->addIdTokenToResponse(
276+
$response,
277+
$clientId,
278+
$codeInfo['user_id'],
279+
($_SESSION['nonce'] ?? ''),
280+
$this->config->getPrivateKey(),
281+
$httpDpop
282+
);
279283

280284
return $this->respond($response); // ->addHeader('Access-Control-Allow-Origin', '*');
281285
}

0 commit comments

Comments
 (0)