Skip to content

Commit

Permalink
Add request to security callback
Browse files Browse the repository at this point in the history
  • Loading branch information
hkarlstrom committed Apr 25, 2023
1 parent b8918da commit 8dd2f83
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/OpenApiValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -157,15 +157,15 @@ 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;
$callback = $this->options['validateSecurity'];
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;
}
}
Expand Down

0 comments on commit 8dd2f83

Please sign in to comment.