jasny / jasny/auth

Authorization attributes

Open
#20 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
113
Forks
34
PR merge metrics
No merged PRs in 30d

Description

```php
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.

```php
use Jasny\Auth\Attributes\Roles;

#[Roles('admin')]
class AdminController
{
}
```

```php
use Jasny\Auth\Attributes\Roles;
use Jasny\Auth\Attributes\Context;

#[Controller('clients')]
class ClientController
{
#[Post('/:id')]
#[Roles('manager')]
public edit(
#[Context] string $clientId,
) {
// ...
}
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with AuthMiddleware and the callback that returns a ReflectionMethod, then inspect the Roles, Controller, Post, and Context attributes shown in the examples. Determine how authorization attributes should be obtained and verified; done means the demonstrated controller and method attributes are enforced through the middleware.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
authorization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.