new funcionality
This commit is contained in:
28
app/Support/TokenRevocation.php
Normal file
28
app/Support/TokenRevocation.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Events\TokenRevoked;
|
||||
use Laravel\Passport\Token;
|
||||
|
||||
/**
|
||||
* Único punto de revocación de un token OAuth — usado por el self-service
|
||||
* (AuthorizedAppController, ClientController), por el admin (UserSessions) y
|
||||
* por la revocación en cascada al revocar un client. Centralizarlo acá
|
||||
* garantiza que el evento TokenRevoked (que dispara los webhooks salientes)
|
||||
* se dispare siempre, sin importar desde dónde se originó la revocación.
|
||||
*/
|
||||
class TokenRevocation
|
||||
{
|
||||
public static function revoke(Token $token): void
|
||||
{
|
||||
if ($token->revoked) {
|
||||
return;
|
||||
}
|
||||
|
||||
$token->revoke();
|
||||
$token->refreshToken?->revoke();
|
||||
|
||||
TokenRevoked::dispatch($token);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user