Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
}
},
"require": {
"php": ">=7.3",
"php": ">=8.0",
"ext-swoole": ">=4.5",
"hyperf-ext/hashing": "~2.2.0",
"hyperf/command": "~2.2.0",
"hyperf/config": "~2.2.0",
"hyperf/database": "~2.2.0",
"hyperf/db-connection": "~2.2.0",
"hyperf/di": "~2.2.0",
"hyperf/framework": "~2.2.0"
"hyperf-ext/hashing": "~3.0.0",
"hyperf/command": "~3.0.0",
"hyperf/config": "~3.0.0",
"hyperf/database": "~3.0.0",
"hyperf/db-connection": "~3.0.0",
"hyperf/di": "~3.0.0",
"hyperf/framework": "~3.0.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"hyperf/testing": "~2.2.0",
"hyperf/testing": "~3.0.0",
"phpstan/phpstan": "^0.12",
"swoole/ide-helper": "dev-master",
"mockery/mockery": "^1.0"
Expand Down
31 changes: 10 additions & 21 deletions src/Aspect/AuthAspect.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1);
declare (strict_types=1);
/**
* This file is part of hyperf-ext/auth.
*
Expand All @@ -18,38 +18,27 @@
use HyperfExt\Auth\Contracts\AuthenticatableInterface;
use HyperfExt\Auth\Exceptions\AuthenticationException;

/**
* @Aspect
*/
#[Aspect]
class AuthAspect extends AbstractAspect
{
public $annotations = [
Auth::class,
];

/**
* @Inject
* @var \HyperfExt\Auth\Contracts\AuthManagerInterface
*/
protected $auth;


public $annotations = [Auth::class];

#[Inject]
protected \\HyperfExt\Auth\Contracts\AuthManagerInterface $auth;

public function process(ProceedingJoinPoint $proceedingJoinPoint)
{
$annotation = $proceedingJoinPoint->getAnnotationMetadata();

$authAnnotation = $annotation->class[Auth::class] ?? $annotation->method[Auth::class];

$guards = empty($authAnnotation->guards) ? [null] : $authAnnotation->guards;
$passable = $authAnnotation->passable;

foreach ($guards as $name) {
$guard = $this->auth->guard($name);

if (! $guard->user() instanceof AuthenticatableInterface and ! $passable) {
if (!$guard->user() instanceof AuthenticatableInterface and !$passable) {
throw new AuthenticationException('Unauthenticated.', $guards);
}
}

return $proceedingJoinPoint->process();
}
}
}
2 changes: 1 addition & 1 deletion src/Guards/JwtGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use BadMethodCallException;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Utils\Traits\Macroable;
use Hyperf\Macroable\Macroable;
use HyperfExt\Auth\Contracts\AuthenticatableInterface;
use HyperfExt\Auth\Contracts\StatelessGuardInterface;
use HyperfExt\Auth\Contracts\UserProviderInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Guards/SessionGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Hyperf\Contract\SessionInterface;
use Hyperf\HttpMessage\Cookie\Cookie;
use Hyperf\Utils\Str;
use Hyperf\Utils\Traits\Macroable;
use Hyperf\Macroable\Macroable;
use HyperfExt\Auth\Contracts\AuthenticatableInterface;
use HyperfExt\Auth\Contracts\StatefulGuardInterface;
use HyperfExt\Auth\Contracts\SupportsBasicAuthInterface;
Expand Down