feat: agent token, auth.agent middleware, /mcp route with HadoServer skeleton
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
30
core/app/Models/AgentToken.php
Normal file
30
core/app/Models/AgentToken.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class AgentToken extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/** Выпускает (или перевыпускает) токен пользователя; возвращает открытый токен — показать один раз. */
|
||||
public static function issue(User $user): string
|
||||
{
|
||||
$token = 'hado_agent_'.bin2hex(random_bytes(32));
|
||||
static::updateOrCreate(['user_id' => $user->id], ['token_hash' => hash('sha256', $token)]);
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
public static function findByToken(string $token): ?self
|
||||
{
|
||||
return static::where('token_hash', hash('sha256', $token))->first();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user