Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authorization attributes #20

Open
jasny opened this issue Aug 29, 2024 · 0 comments
Open

Authorization attributes #20

jasny opened this issue Aug 29, 2024 · 0 comments

Comments

@jasny
Copy link
Owner

jasny commented Aug 29, 2024

use Jasny\Auth\AuthMiddleware;
use Jasny\Auth\AttributesHandler;

$fn =  static function (ServerRequestInterface $request) {
  return new ReflectionMethod($request->getAttribute('route.controller'), $request->getAttribute('route.action'));
};

$middleware = new AuthMiddleware($auth, $fn, $responseFactory);
$router->add($middleware);

If the callback for AuthMiddleware returns a reflection object, the attributes will be obtained and verified.

use Jasny\Auth\Attributes\Roles;

#[Roles('admin')]
class AdminController
{
}
use Jasny\Auth\Attributes\Roles;
use Jasny\Auth\Attributes\Context;

#[Controller('clients')]
class ClientController
{
  #[Post('/:id')]
  #[Roles('manager')]
  public edit(
    #[Context] string $clientId,
  ) {
    // ...
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant