55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\Admin;
|
||
|
||
use App\Http\Controllers\Controller;
|
||
use App\Services\LinkedInService;
|
||
use Illuminate\Http\Request;
|
||
|
||
class LinkedInController extends Controller
|
||
{
|
||
protected LinkedInService $linkedInService;
|
||
|
||
public function __construct(LinkedInService $linkedInService)
|
||
{
|
||
$this->linkedInService = $linkedInService;
|
||
}
|
||
|
||
/**
|
||
* Redirect admin to LinkedIn OAuth consent screen
|
||
*/
|
||
public function connect(Request $request)
|
||
{
|
||
$url = $this->linkedInService->getAuthorizationUrl();
|
||
return redirect()->away($url);
|
||
}
|
||
|
||
/**
|
||
* Handle OAuth Callback from LinkedIn
|
||
*/
|
||
public function callback(Request $request)
|
||
{
|
||
if ($request->has('error')) {
|
||
$errorDescription = $request->input('error_description', 'Yetkilendirme iptal edildi.');
|
||
return redirect('/admin/linked-in-settings')
|
||
->with('error', 'LinkedIn bağlantı hatası: ' . $errorDescription);
|
||
}
|
||
|
||
$code = $request->input('code');
|
||
if (!$code) {
|
||
return redirect('/admin/linked-in-settings')
|
||
->with('error', 'LinkedIn yetkilendirme kodu (code) alınamadı.');
|
||
}
|
||
|
||
$result = $this->linkedInService->handleCallback($code);
|
||
|
||
if ($result['success']) {
|
||
return redirect('/admin/linked-in-settings')
|
||
->with('success', $result['message']);
|
||
}
|
||
|
||
return redirect('/admin/linked-in-settings')
|
||
->with('error', $result['message']);
|
||
}
|
||
}
|