Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed problem on HashManger and added passport:purge command (thanks …
…dusterio)
- Loading branch information
Showing
3 changed files
with
88 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Nomadnt\LumenPassport\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\Carbon; | ||
|
||
use Nomadnt\LumenPassport\Passport; | ||
|
||
class PurgeCommand extends Command | ||
{ | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'passport:purge'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Delete expired refresh tokens and their associated tokens from the database'; | ||
|
||
/** | ||
* Create a new passport purge command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$date = Carbon::now(); | ||
|
||
$count = DB::table('oauth_refresh_tokens')->where('expires_at', '<', $date)->delete(); | ||
|
||
if(Passport::$refreshTokensExpireAt AND Passport::$tokensExpireAt){ | ||
$date->subDays(Passport::$refreshTokensExpireAt->diffinDays(Passport::$tokensExpireAt)); | ||
// We assume it's safe to delete tokens that cannot be refreshed anyway | ||
$count += DB::table('oauth_access_tokens')->where('expires_at', '<', $date)->delete(); | ||
} | ||
|
||
$this->info("Successfully deleted expired tokens: {$count}"); | ||
} | ||
} |
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