?
| Current Path : /home/w/e/b/webyoo/www/nathan-ai/site/ |
| Current File : /home/w/e/b/webyoo/www/nathan-ai/site/oauth_callback.php |
<?php
/**
* oauth_callback.php — récupère ton jeton d'accès LinkedIn (à faire une seule fois, ~tous les 60 jours).
*
* ÉTAPES :
* 1) Dépose ce dossier sur ton serveur (ex. https://ledmark.fr/li/).
* 2) Dans ton app LinkedIn > Auth, ajoute cette URL exacte comme "Authorized redirect URL".
* 3) Ouvre dans ton navigateur : https://ledmark.fr/li/oauth_callback.php?login=1
* -> tu es redirigé vers LinkedIn, tu autorises, tu reviens ici.
* 4) La page t'affiche ton access_token : copie-le dans config.php.
*/
require __DIR__ . '/lib.php';
$c = cfg();
$scope = 'openid profile email w_member_social';
// Étape A : rediriger vers LinkedIn pour autorisation
if (isset($_GET['login'])) {
$state = bin2hex(random_bytes(8));
$url = 'https://www.linkedin.com/oauth/v2/authorization?' . http_build_query([
'response_type' => 'code',
'client_id' => $c['client_id'],
'redirect_uri' => $c['redirect_uri'],
'state' => $state,
'scope' => $scope,
]);
header('Location: ' . $url);
exit;
}
// Étape B : LinkedIn nous renvoie un "code" -> on l'échange contre un token
if (isset($_GET['code'])) {
$body = http_build_query([
'grant_type' => 'authorization_code',
'code' => $_GET['code'],
'redirect_uri' => $c['redirect_uri'],
'client_id' => $c['client_id'],
'client_secret' => $c['client_secret'],
]);
list($code, $resp) = http_request(
'POST',
'https://www.linkedin.com/oauth/v2/accessToken',
['Content-Type: application/x-www-form-urlencoded'],
$body
);
header('Content-Type: text/html; charset=utf-8');
if ($code === 200) {
$data = json_decode($resp, true);
$token = htmlspecialchars($data['access_token'] ?? '');
$exp = isset($data['expires_in']) ? round($data['expires_in']/86400) . ' jours' : '?';
echo "<h2>✅ Jeton obtenu</h2>";
echo "<p><b>Copie ceci dans config.php → 'access_token' :</b></p>";
echo "<textarea style='width:100%;height:120px'>$token</textarea>";
echo "<p>Expire dans : <b>$exp</b>. Reviens sur cette page (?login=1) pour le renouveler avant expiration.</p>";
echo "<p>Étape suivante : lance <code>php get_person_urn.php</code> pour récupérer ton author_urn.</p>";
} else {
echo "<h2>❌ Erreur ($code)</h2><pre>" . htmlspecialchars($resp) . "</pre>";
}
exit;
}
echo '<p>Va sur <a href="?login=1">?login=1</a> pour démarrer l\'autorisation LinkedIn.</p>';