trypost/app/Http/Controllers/Auth/XController.php

42 lines
1.1 KiB
PHP
Raw Normal View History

2026-01-15 01:13:44 +00:00
<?php
namespace App\Http\Controllers\Auth;
use App\Enums\SocialPlatform;
use App\Models\Workspace;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class XController extends SocialController
{
2026-01-15 17:24:39 +00:00
protected string $driver = 'x';
2026-01-15 01:13:44 +00:00
protected SocialPlatform $platform = SocialPlatform::X;
protected array $scopes = [
'tweet.read',
'tweet.write',
'users.read',
2026-01-15 17:24:39 +00:00
'media.write',
2026-01-15 01:13:44 +00:00
'offline.access',
];
public function connect(Request $request, Workspace $workspace): Response
{
$this->ensurePlatformEnabled();
2026-01-15 17:24:39 +00:00
$this->authorize('manageAccounts', $workspace);
2026-01-15 01:13:44 +00:00
if ($workspace->hasConnectedPlatform($this->platform->value)) {
2026-01-15 17:24:39 +00:00
return back()->with('error', 'This platform is already connected.');
2026-01-15 01:13:44 +00:00
}
return $this->redirectToProvider($workspace, $this->driver, $this->scopes);
}
public function callback(Request $request): RedirectResponse
{
return $this->handleCallback($request, $this->platform, $this->driver);
}
}