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 | * Create a new instance of the Authroization middleware. |
||
33 | * |
||
34 | * @param OAuth2\Server $server The configured OAuth2 server. |
||
|
|||
35 | * @param array $scopes Scopes required for authorization. $scopes can be given as an array of arrays. OR |
||
36 | * logic will use with each grouping. Example: |
||
37 | * Given ['superUser', ['basicUser', 'aPermission']], the request will be verified |
||
38 | * if the request token has 'superUser' scope OR 'basicUser' and 'aPermission' as |
||
39 | * its scope. |
||
40 | */ |
||
41 | public function __construct(OAuth2\Server $server, array $scopes = []) |
||
46 | |||
47 | /** |
||
48 | * Execute this middleware. |
||
49 | * |
||
50 | * @param ServerRequestInterface $request The PSR7 request. |
||
51 | * @param ResponseInterface $response The PSR7 response. |
||
52 | * @param callable $next The Next middleware. |
||
53 | * |
||
54 | * @return ResponseInterface |
||
55 | */ |
||
56 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
68 | |||
69 | /** |
||
70 | * Returns a callable function to be used as a authorization middleware with a specified scope. |
||
71 | * |
||
72 | * @param array $scopes Scopes require for authorization. |
||
73 | * |
||
74 | * @return Authorization |
||
75 | */ |
||
76 | public function withRequiredScope(array $scopes) |
||
82 | |||
83 | /** |
||
84 | * Helper method to ensure given scopes are formatted properly. |
||
85 | * |
||
86 | * @param array $scopes Scopes required for authorization. |
||
87 | * |
||
88 | * @return array The formatted scopes array. |
||
89 | */ |
||
90 | private function formatScopes(array $scopes) |
||
107 | } |
||
108 |