Add LinkedIn OAuth flow
- linkedin_auth API: generates auth URL with CSRF state stored in session - linkedin_callback: exchanges code for tokens, writes to project's config.json - index.php: route /linkedin/callback before auth check - Connect button wired up in JS; reads LINKEDIN_CLIENT_ID/SECRET from server env Server setup required: SetEnv LINKEDIN_CLIENT_ID ... SetEnv LINKEDIN_CLIENT_SECRET ... Redirect URI to register in LinkedIn app: https://<host>/linkedin/callback Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3d7b620b6c
commit
158a5b0775
5 changed files with 126 additions and 3 deletions
27
web/api/linkedin_auth.php
Normal file
27
web/api/linkedin_auth.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$pid = (int)($_GET['project_id'] ?? 0);
|
||||
if (!$pid) { http_response_code(400); echo json_encode(['error' => 'project_id required']); exit; }
|
||||
|
||||
$stmt = $db->prepare('SELECT * FROM projects WHERE id = ? AND is_active = 1');
|
||||
$stmt->execute([$pid]);
|
||||
if (!$stmt->fetch()) { http_response_code(404); echo json_encode(['error' => 'Project not found']); exit; }
|
||||
|
||||
$client_id = getenv('LINKEDIN_CLIENT_ID');
|
||||
if (!$client_id) { echo json_encode(['error' => 'LINKEDIN_CLIENT_ID not set in server environment']); exit; }
|
||||
|
||||
$state = bin2hex(random_bytes(16));
|
||||
$_SESSION['linkedin_oauth'] = ['state' => $state, 'project_id' => $pid];
|
||||
|
||||
$redirect_uri = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/linkedin/callback';
|
||||
|
||||
$url = 'https://www.linkedin.com/oauth/v2/authorization?' . http_build_query([
|
||||
'response_type' => 'code',
|
||||
'client_id' => $client_id,
|
||||
'redirect_uri' => $redirect_uri,
|
||||
'state' => $state,
|
||||
'scope' => 'w_organization_social openid profile',
|
||||
]);
|
||||
|
||||
echo json_encode(['url' => $url]);
|
||||
Loading…
Add table
Add a link
Reference in a new issue