Skip to content

Commit 8dd2f83

Browse files
committed
Add request to security callback
1 parent b8918da commit 8dd2f83

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ If defined, the callback can return Psr\Http\Message\ResponseInterface if the op
9999

100100
```php
101101
$options = [
102-
'validateSecurity' => function (\HKarlstrom\OpenApiReader\Objects\SecurityScheme $securityScheme, ?array $scopes) : ?\Psr\Http\Message\ResponseInterface {
102+
'validateSecurity' => function (ServerRequestInterface $request, \HKarlstrom\OpenApiReader\Objects\SecurityScheme $securityScheme, ?array $scopes) : ?\Psr\Http\Message\ResponseInterface {
103103
// if user is authorized
104104
return null;
105105

src/OpenApiValidation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
113113
return $handler->handle($request);
114114
}
115115

116-
if (null !== $this->options['validateSecurity'] && $response = $this->validateSecurity($path, $method)) {
116+
if (null !== $this->options['validateSecurity'] && $response = $this->validateSecurity($path, $method, $request)) {
117117
return $response;
118118
}
119119
if ($this->options['validateRequest']
@@ -157,15 +157,15 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
157157
return $response;
158158
}
159159

160-
public function validateSecurity(string $path, string $method) : ?ResponseInterface
160+
public function validateSecurity(string $path, string $method, ServerRequestInterface $request) : ?ResponseInterface
161161
{
162162
$security = $this->openapi->getOperationSecurity($path, $method);
163163
if (!count($security)) return null;
164164
$callback = $this->options['validateSecurity'];
165165
foreach ($security as $security_) {
166166
foreach ($security_ as $name => $scopes) {
167167
$securitySceme = $this->openapi->getSecurityScheme($name);
168-
if ($response = $callback($this->openapi->getSecurityScheme($name), $scopes)) {
168+
if ($response = $callback($request, $this->openapi->getSecurityScheme($name), $scopes)) {
169169
return $response;
170170
}
171171
}

0 commit comments

Comments
 (0)