44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Passport;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
use Laravel\Passport\Bridge\ClientRepository as BaseClientRepository;
|
|
|
|
/**
|
|
* Extiende la validación de client_secret de Passport para aceptar, además
|
|
* del secret actual, el secret anterior si todavía no venció su periodo de
|
|
* gracia (ver App\Support\ClientSecretRotation). Sin esto, rotar un secret
|
|
* cortaría cualquier integración desplegada que todavía no se actualizó.
|
|
*
|
|
* Se bindea en AppServiceProvider::register() en vez del ClientRepository
|
|
* de base — Passport lo resuelve vía el contenedor (no como singleton
|
|
* explícito), así que un bind alcanza para reemplazarlo en todos lados
|
|
* donde se arma el AuthorizationServer.
|
|
*/
|
|
class ClientRepository extends BaseClientRepository
|
|
{
|
|
public function validateClient(string $clientIdentifier, ?string $clientSecret, ?string $grantType): bool
|
|
{
|
|
if (parent::validateClient($clientIdentifier, $clientSecret, $grantType)) {
|
|
return true;
|
|
}
|
|
|
|
if (empty($clientSecret)) {
|
|
return false;
|
|
}
|
|
|
|
$record = $this->clients->findActive($clientIdentifier);
|
|
|
|
if (! $record || ! $record->previous_secret || ! $record->previous_secret_expires_at) {
|
|
return false;
|
|
}
|
|
|
|
if (Carbon::parse($record->previous_secret_expires_at)->isPast()) {
|
|
return false;
|
|
}
|
|
|
|
return $this->hasher->check($clientSecret, $record->previous_secret);
|
|
}
|
|
}
|