mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 08:42:38 -04:00
Keep the description, permissions, scopes, and expiry. Move the row actions into a dropdown menu and measure the dropdown panel after it is shown, so menus at the right edge stay on screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Support\Str;
|
|
use Laravel\Sanctum\PersonalAccessToken as SanctumPersonalAccessToken;
|
|
|
|
class PersonalAccessToken extends SanctumPersonalAccessToken
|
|
{
|
|
protected $fillable = [
|
|
'name',
|
|
'token',
|
|
'abilities',
|
|
'expires_at',
|
|
'api_token_expiration_warning_sent_at',
|
|
'team_id',
|
|
'scopes',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'api_token_expiration_warning_sent_at' => 'datetime',
|
|
'scopes' => 'array',
|
|
];
|
|
}
|
|
|
|
public static function generateSecret(): string
|
|
{
|
|
return sprintf(
|
|
'%s%s%s',
|
|
config('sanctum.token_prefix', ''),
|
|
$tokenEntropy = Str::random(40),
|
|
hash('crc32b', $tokenEntropy)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Replace the secret and keep the abilities, scopes, and expiry. The old secret stops working at once.
|
|
*
|
|
* @return string the new plain-text token
|
|
*/
|
|
public function roll(): string
|
|
{
|
|
$secret = self::generateSecret();
|
|
$this->forceFill(['token' => hash('sha256', $secret), 'last_used_at' => null])->save();
|
|
|
|
return $this->getKey().'|'.$secret;
|
|
}
|
|
}
|