-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
598 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of hyperf-ext/auth. | ||
* | ||
* @link https://github.com/hyperf-ext/auth | ||
* @contact eric@zhu.email | ||
* @license https://github.com/hyperf-ext/auth/blob/master/LICENSE | ||
*/ | ||
namespace HyperfExt\Auth\Contracts; | ||
|
||
interface StatelessGuardInterface extends GuardInterface | ||
{ | ||
/** | ||
* Attempt to authenticate the user using the given credentials and return the token. | ||
* | ||
* @return bool|mixed | ||
*/ | ||
public function attempt(array $credentials = [], bool $login = true); | ||
|
||
/** | ||
* Log a user into the application without sessions or cookies. | ||
*/ | ||
public function once(array $credentials = []): bool; | ||
|
||
/** | ||
* Log a user into the application, create a token for the user. | ||
* | ||
* @return mixed | ||
*/ | ||
public function login(AuthenticatableInterface $user); | ||
|
||
/** | ||
* Log the given user ID into the application. | ||
* | ||
* @param mixed $id | ||
* | ||
* @return false|mixed | ||
*/ | ||
public function loginUsingId($id); | ||
|
||
/** | ||
* Log the given user ID into the application without sessions or cookies. | ||
* | ||
* @param mixed $id | ||
*/ | ||
public function onceUsingId($id): bool; | ||
|
||
/** | ||
* Log the user out of the application, thus invalidating the token. | ||
*/ | ||
public function logout(bool $forceForever = false); | ||
|
||
/** | ||
* Refresh the token. | ||
* | ||
* @return mixed | ||
*/ | ||
public function refresh(bool $forceForever = false); | ||
|
||
/** | ||
* Invalidate the token. | ||
* | ||
* @return mixed | ||
*/ | ||
public function invalidate(bool $forceForever = false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of hyperf-ext/auth. | ||
* | ||
* @link https://github.com/hyperf-ext/auth | ||
* @contact eric@zhu.email | ||
* @license https://github.com/hyperf-ext/auth/blob/master/LICENSE | ||
*/ | ||
namespace HyperfExt\Auth; | ||
|
||
use HyperfExt\Auth\Contracts\AuthenticatableInterface; | ||
use HyperfExt\Auth\Events\Attempting; | ||
use HyperfExt\Auth\Events\Authenticated; | ||
use HyperfExt\Auth\Events\CurrentDeviceLogout; | ||
use HyperfExt\Auth\Events\Failed; | ||
use HyperfExt\Auth\Events\Login; | ||
use HyperfExt\Auth\Events\Logout; | ||
use HyperfExt\Auth\Events\OtherDeviceLogout; | ||
use HyperfExt\Auth\Events\Validated; | ||
|
||
trait EventHelpers | ||
{ | ||
/** | ||
* Fire the attempt event with the arguments. | ||
*/ | ||
protected function dispatchAttemptingEvent(array $credentials, bool $remember = false): void | ||
{ | ||
$this->eventDispatcher->dispatch(new Attempting( | ||
$this->name, | ||
$credentials, | ||
$remember | ||
)); | ||
} | ||
|
||
/** | ||
* Fires the validated event if the dispatcher is set. | ||
*/ | ||
protected function dispatchValidatedEvent(AuthenticatableInterface $user) | ||
{ | ||
$this->eventDispatcher->dispatch(new Validated( | ||
$this->name, | ||
$user | ||
)); | ||
} | ||
|
||
/** | ||
* Fire the login event if the dispatcher is set. | ||
*/ | ||
protected function dispatchLoginEvent(AuthenticatableInterface $user, bool $remember = false): void | ||
{ | ||
$this->eventDispatcher->dispatch(new Login( | ||
$this->name, | ||
$user, | ||
$remember | ||
)); | ||
} | ||
|
||
/** | ||
* Fire the authenticated event if the dispatcher is set. | ||
*/ | ||
protected function dispatchAuthenticatedEvent(AuthenticatableInterface $user): void | ||
{ | ||
$this->eventDispatcher->dispatch(new Authenticated( | ||
$this->name, | ||
$user | ||
)); | ||
} | ||
|
||
/** | ||
* Fire the logout event if the dispatcher is set. | ||
*/ | ||
protected function dispatchLogoutEvent(AuthenticatableInterface $user): void | ||
{ | ||
$this->eventDispatcher->dispatch(new Logout( | ||
$this->name, | ||
$user | ||
)); | ||
} | ||
|
||
/** | ||
* Fire the current device logout event if the dispatcher is set. | ||
*/ | ||
protected function dispatchCurrentDeviceLogoutEvent(AuthenticatableInterface $user): void | ||
{ | ||
$this->eventDispatcher->dispatch(new CurrentDeviceLogout( | ||
$this->name, | ||
$user | ||
)); | ||
} | ||
|
||
/** | ||
* Fire the other device logout event if the dispatcher is set. | ||
*/ | ||
protected function dispatchOtherDeviceLogoutEvent(AuthenticatableInterface $user): void | ||
{ | ||
$this->eventDispatcher->dispatch(new OtherDeviceLogout( | ||
$this->name, | ||
$user | ||
)); | ||
} | ||
|
||
/** | ||
* Fire the failed authentication attempt event with the given arguments. | ||
*/ | ||
protected function dispatchFailedEvent(?AuthenticatableInterface $user, array $credentials): void | ||
{ | ||
$this->eventDispatcher->dispatch(new Failed( | ||
$this->name, | ||
$user, | ||
$credentials | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.