query('to', ''); abort_unless(UseConsoleSession::isConsoleUrl($to), 404); $token = Str::random(40); Cache::put(self::cacheKey($token), ['user' => (int) $request->user()?->getAuthIdentifier(), 'to' => $to], self::SECONDS); return redirect()->route('console.handoff.accept', $token); } /** * In the console's own session: signs in with the key once. */ public function accept(Request $request, string $token, CheckLoginAllowed $checkLoginAllowed): RedirectResponse { /** @var array{user: int, to: string}|null $handoff */ $handoff = Cache::pull(self::cacheKey($token)); if ($handoff === null || ! $checkLoginAllowed->execute($handoff['user'])) { return redirect()->route('console.login'); } if (Auth::check()) { Auth::logout(); $request->session()->invalidate(); $request->session()->regenerateToken(); } Auth::loginUsingId($handoff['user']); $request->session()->regenerate(); return redirect()->to($handoff['to']); } private static function cacheKey(string $token): string { return 'console-handoff|'.hash('sha256', $token); } }