diff --git a/auth/linkedin/callback.php b/auth/linkedin/callback.php new file mode 100644 index 0000000..25999fd --- /dev/null +++ b/auth/linkedin/callback.php @@ -0,0 +1,73 @@ + 'authorization_code', + 'code' => $code, + 'redirect_uri' => 'https://fengyuexingzi.top/auth/linkedin', + 'client_id' => '81cc4t9fuu9bpu', + 'client_secret' => 'GdY3ZO8LAHn8y4tX', + ); + + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); + curl_setopt($ch, CURLOPT_TRANSFERTEXT, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 5); + curl_setopt($ch, CURLOPT_HEADER, false); + $result = curl_exec($ch); + $info = curl_getinfo($ch); + curl_close($ch); + + $result = json_decode($result, true); + if (isset($result['access_token'])) { + + } +} + +// step 2: get user info by access token +function getInfo($url, $access_token) +{ + // 1. 判断 AccessToken 状态(过期,即将过期,正常,无效) + // 2.AccessToken 1)无效或过期,回到 step 1 重新请求; 2)即将过期, 调用刷新接口;3)正常使用 + + $data = [ + 'access_token' => "AQXMRNlQv7rqemb6KmBKMWurtL7I6KV381MUxXQIeW6YszIueblWCVatVrVACzO-L2wWI7VSgto_hvH_ET1E7aVUjAalRXvcEu4qsWx57YS1yVANEbpez3dQUupIRrqGOGnokRHR64nQyVFqTPaS9e2hPvO_miOtlBD3mzQjxLC1O2xxJrG4BIWohlNmMyxgvVXM2OZCurPG5rFyfoitB-rmI6JyvW4tUYRFoJLe5XzjfpUWoe0OUzWxo8y67xrY4tIBAILKGnMM2KDfHKyVJx9JDoVC7jCPHaWC9mSEWSSlunC5Q_xJuJb98MPwDUlrtXkvpJSC9yzbsODR_nnBr5coHEcIlA", + + ]; + + $info_url = "https://api.linkedin.com/v1/people/~?format=json"; + + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Authorization: ' . $access_token, + ]); + curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 5); + curl_setopt($ch, CURLOPT_HEADER, true); + $result = curl_exec($ch); + $info = curl_getinfo($ch); + $info['result'] = $result; + curl_close($ch); + + return $info; +} + +//$access_token = getAccessToken($_GET['code']); + +print_r($GLOBALS); \ No newline at end of file diff --git a/auth/linkedin/function.php b/auth/linkedin/function.php new file mode 100644 index 0000000..f5070ab --- /dev/null +++ b/auth/linkedin/function.php @@ -0,0 +1,23 @@ +'; + print_r(error_get_last()); + echo ''; +} + +function dump($data) +{ + echo '
'; + print_r($data); + echo ''; +} diff --git a/auth/linkedin/index.php b/auth/linkedin/index.php index 56bbc10..62ccf53 100644 --- a/auth/linkedin/index.php +++ b/auth/linkedin/index.php @@ -6,77 +6,35 @@ * Time: 15:17 */ -$code_url = "https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=81cc4t9fuu9bpu&redirect_uri=https%3A%2F%2Ffengyuexingzi.top%2Fauth%2Flinkedin&state=987654321&scope=r_basicprofile"; +require_once"./function.php"; -$data = [ - 'access_token' => "AQXMRNlQv7rqemb6KmBKMWurtL7I6KV381MUxXQIeW6YszIueblWCVatVrVACzO-L2wWI7VSgto_hvH_ET1E7aVUjAalRXvcEu4qsWx57YS1yVANEbpez3dQUupIRrqGOGnokRHR64nQyVFqTPaS9e2hPvO_miOtlBD3mzQjxLC1O2xxJrG4BIWohlNmMyxgvVXM2OZCurPG5rFyfoitB-rmI6JyvW4tUYRFoJLe5XzjfpUWoe0OUzWxo8y67xrY4tIBAILKGnMM2KDfHKyVJx9JDoVC7jCPHaWC9mSEWSSlunC5Q_xJuJb98MPwDUlrtXkvpJSC9yzbsODR_nnBr5coHEcIlA", +// get_code_url = "https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=81cc4t9fuu9bpu&redirect_uri=https%3A%2F%2Ffengyuexingzi.top%2Fauth%2Flinkedin&state=Wf6tYXQ7y86iRulBOC%2FUXraHneM%3D&scope=r_fullprofile%20r_emailaddress%20w_share"; -]; +// $state = base64_encode(openssl_random_pseudo_bytes(20)); +$state = 'x1Dr3Nu0AaxM1TuLVuGwAJWM'; -$info_url = "https://api.linkedin.com/v1/people/~?format=json"; - -register_shutdown_function('shutdown'); - -function shutdown() -{ - echo '
'; - print_r(error_get_last()); - echo ''; - die('shutdown'); -} - -function dump($data) -{ - echo '
'; - print_r($data); - echo ''; -} - -function curl_get($url, $data) +function getCodeUrl() { - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_HTTPHEADER, [ - 'Authorization: ' . $data['access_token'], - ]); - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_TIMEOUT, 5); - curl_setopt($ch, CURLOPT_HEADER, true); - $result = curl_exec($ch); - $info = curl_getinfo($ch); - $info['result'] = $result; - curl_close($ch); - - return $info; + $url = 'https://www.linkedin.com/oauth/v2/authorization'; + $data = array( + 'response_type' => 'code', + 'client_id' => '81cc4t9fuu9bpu', + 'redirect_uri' => 'https://fengyuexingzi.top/auth/linkedin', + 'state' => $GLOBALS['state'], + 'scope' => 'r_fullprofile r_emailaddress w_share', + ); + foreach ($data as $k => $v) { + if (!$v) { + return false; + } + } + $url .= http_build_query($data, null, '&', PHP_QUERY_RFC3986); + + return $url; } -$result = curl_get($info_url, $data); - -dump($result); - -die; - -$url = "https://www.linkedin.com/oauth/v2/accessToken"; +$url = getCodeUrl(); -$data = array( - 'grant_type' => 'authorization_code', - 'code' => $_GET['code'], - 'redirect_uri' => 'https://fengyuexingzi.top/auth/linkedin', - 'client_id' => '81cc4t9fuu9bpu', - 'client_secret' => 'GdY3ZO8LAHn8y4tX', -); - -$ch = curl_init($url); -curl_setopt($ch, CURLOPT_POST, true); -curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); -curl_setopt($ch, CURLOPT_TRANSFERTEXT, true); -curl_setopt($ch, CURLOPT_TIMEOUT, 5); -curl_setopt($ch, CURLOPT_HEADER, false); -$result = curl_exec($ch); -$info = curl_getinfo($ch); -curl_close($ch); - -$result = json_decode($result, true); -if (isset($result['access_token'])) { - -} +$html = <<