Skip to content

Commit c0a8497

Browse files
Testes para OidcAuthEventHandler.php. Ainda com erros.
1 parent 9db7fc7 commit c0a8497

File tree

14 files changed

+207
-511
lines changed

14 files changed

+207
-511
lines changed

config/module.config.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?php
22

3-
use Zend\Router\Http\Literal;
3+
use Zend\Mvc\OIDC\Factory\OidcAuthEventListenerFactory;
4+
use Zend\Mvc\OIDC\Listener\OidcAuthListener;
45

56
return [
67
'listeners' => [
7-
"Zend\Mvc\OIDC\Listener\OidcAuthListener"
8+
OidcAuthListener::class
89
],
910
'service_manager' => [
1011
'factories' => [
11-
"Zend\Mvc\OIDC\Listener\OidcAuthListener" => \Zend\Mvc\OIDC\Factory\OidcAuthEventListenerFactory::class
12+
OidcAuthListener::class => OidcAuthEventListenerFactory::class
1213
]
1314
]
1415
];

src/Auth/Authorizator.php

Lines changed: 0 additions & 193 deletions
This file was deleted.

src/Common/Model/Token.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Exception;
77
use Lcobucci\JWT\Claim;
88
use Lcobucci\JWT\Parser;
9+
use Lcobucci\JWT\Signer\Key;
910
use Lcobucci\JWT\Signer\Rsa\Sha256;
1011
use Lcobucci\JWT\ValidationData;
1112
use Zend\Mvc\OIDC\Common\Configuration;
@@ -124,6 +125,7 @@ private function setValidationData(DateTime $moment, Configuration $configuratio
124125
private function verifySignature(string $publicKey): bool
125126
{
126127
$signer = new Sha256();
127-
return $this->jwt->verify($signer, $publicKey);
128+
$key = new Key($publicKey);
129+
return $this->jwt->verify($signer, $key);
128130
}
129131
}

src/Factory/OidcAuthEventListenerFactory.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,17 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
3636
{
3737
$configurationDiscoveryService = new ConfigurationDiscoveryService(new HttpClient());
3838
$certKeyService = new CertKeyService($configurationDiscoveryService, new HttpClient());
39+
$configurationParser = new ConfigurationParser();
3940

4041
$moduleConfig = $container->get('config');
4142
$applicationConfig = $container->get('ApplicationConfig');
4243
$oidcAuthEventHandler = new OidcAuthEventHandler(
4344
$applicationConfig,
4445
$moduleConfig,
45-
new ConfigurationParser(),
46+
$configurationParser,
4647
$certKeyService
4748
);
4849

4950
return new OidcAuthListener($oidcAuthEventHandler);
50-
51-
//$globalConfiguration = $container->get('ApplicationConfig');
52-
53-
//return new $requestedName($globalConfiguration);
5451
}
5552
}

src/Listener/OidcAuthEventHandler.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Zend\Mvc\OIDC\Listener;
44

5+
use Exception;
56
use Zend\Http\Request;
67
use Zend\Mvc\MvcEvent;
78
use Zend\Mvc\OIDC\Common\Configuration;
@@ -87,6 +88,7 @@ public function __construct(
8788
* @throws InvalidAuthorizationTokenException
8889
* @throws JwkRecoveryException
8990
* @throws OidcConfigurationDiscoveryException
91+
* @throws Exception
9092
*/
9193
public function handle(MvcEvent $mvcEvent)
9294
{
@@ -145,13 +147,10 @@ private function isAuthorized(array $authorizeConfig): void
145147
private function getAuthorizationToken(Request $request): string
146148
{
147149
$headers = $request->getHeaders('Authorization', null);
148-
$token = '';
149150

150151
if (!is_null($headers)) {
151-
$token = $headers->toString();
152-
$token = str_replace('Authorization: Bearer', null, $token);
153-
154-
return $token;
152+
$tokenFromHeader = $headers->toString();
153+
return str_replace('Authorization: Bearer', null, $tokenFromHeader);
155154
}
156155

157156
throw new BasicAuthorizationException('Authorization exception.');

src/Listener/OidcAuthListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public function __construct(OidcAuthEventHandler $authEventHandler)
2828
*/
2929
public function attach(EventManagerInterface $events, $priority = 1)
3030
{
31-
$authEventHandler = $this->authEventHandler;
32-
$callback = function (MvcEvent $mvcEvent) use($authEventHandler) {
33-
$authEventHandler->handle($mvcEvent);
31+
$eventHandler = $this->authEventHandler;
32+
$callback = function (MvcEvent $mvcEvent) use($eventHandler) {
33+
$eventHandler->handle($mvcEvent);
3434
};
3535

3636
$this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, $callback, 1000);

src/Module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
class Module
1111
{
12-
public function getConfig()
12+
public function getConfig(): array
1313
{
1414
return include __DIR__ . '/../config/module.config.php';
1515
}

0 commit comments

Comments
 (0)