1 | <?php |
||
15 | class Authorization implements MiddlewareInterface |
||
16 | { |
||
17 | /** |
||
18 | * OAuth2 Server |
||
19 | * |
||
20 | * @var OAuth2\Server |
||
21 | */ |
||
22 | private $server; |
||
23 | |||
24 | /** |
||
25 | * Array of scopes required for authorization. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | private $scopes; |
||
30 | |||
31 | /** |
||
32 | * Container for token. |
||
33 | * |
||
34 | * @var ArrayAccess |
||
35 | */ |
||
36 | private $container; |
||
37 | |||
38 | /** |
||
39 | * Create a new instance of the Authroization middleware. |
||
40 | * |
||
41 | * @param OAuth2\Server $server The configured OAuth2 server. |
||
42 | * @param ArrayAccess $container A container object in which to store the token from the request. |
||
43 | * @param array $scopes Scopes required for authorization. $scopes can be given as an array of arrays. OR |
||
44 | * logic will use with each grouping. Example: |
||
45 | * Given ['superUser', ['basicUser', 'aPermission']], the request will be verified |
||
46 | * if the request token has 'superUser' scope OR 'basicUser' and 'aPermission' as |
||
47 | * its scope. |
||
48 | */ |
||
49 | public function __construct(OAuth2\Server $server, ArrayAccess $container, array $scopes = []) |
||
55 | |||
56 | /** |
||
57 | * Execute this middleware. |
||
58 | * |
||
59 | * @param ServerRequestInterface $request The PSR7 request. |
||
60 | * @param ResponseInterface $response The PSR7 response. |
||
61 | * @param callable $next The Next middleware. |
||
62 | * |
||
63 | * @return Slim\Http\Response |
||
64 | */ |
||
65 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
87 | |||
88 | /** |
||
89 | * Returns a callable function to be used as a authorization middleware with a specified scope. |
||
90 | * |
||
91 | * @param array $scopes Scopes require for authorization. |
||
92 | * |
||
93 | * @return Authorization |
||
94 | */ |
||
95 | public function withRequiredScope(array $scopes) |
||
101 | } |
||
102 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.