diff --git a/README.md b/README.md index 16b600d..35f66c9 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ If defined, the callback can return Psr\Http\Message\ResponseInterface if the op ```php $options = [ - 'validateSecurity' => function (\HKarlstrom\OpenApiReader\Objects\SecurityScheme $securityScheme, ?array $scopes) : ?\Psr\Http\Message\ResponseInterface { + 'validateSecurity' => function (ServerRequestInterface $request, \HKarlstrom\OpenApiReader\Objects\SecurityScheme $securityScheme, ?array $scopes) : ?\Psr\Http\Message\ResponseInterface { // if user is authorized return null; diff --git a/src/OpenApiValidation.php b/src/OpenApiValidation.php index 4ec6c03..1545405 100644 --- a/src/OpenApiValidation.php +++ b/src/OpenApiValidation.php @@ -113,7 +113,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface return $handler->handle($request); } - if (null !== $this->options['validateSecurity'] && $response = $this->validateSecurity($path, $method)) { + if (null !== $this->options['validateSecurity'] && $response = $this->validateSecurity($path, $method, $request)) { return $response; } if ($this->options['validateRequest'] @@ -157,7 +157,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface return $response; } - public function validateSecurity(string $path, string $method) : ?ResponseInterface + public function validateSecurity(string $path, string $method, ServerRequestInterface $request) : ?ResponseInterface { $security = $this->openapi->getOperationSecurity($path, $method); if (!count($security)) return null; @@ -165,7 +165,7 @@ public function validateSecurity(string $path, string $method) : ?ResponseInterf foreach ($security as $security_) { foreach ($security_ as $name => $scopes) { $securitySceme = $this->openapi->getSecurityScheme($name); - if ($response = $callback($this->openapi->getSecurityScheme($name), $scopes)) { + if ($response = $callback($request, $this->openapi->getSecurityScheme($name), $scopes)) { return $response; } }