fedi-tumblr/login/activate.php
2020-03-31 18:46:27 -06:00

42 lines
1.4 KiB
PHP

<?php
$cdata = parse_url($setting['url']);
include "data/" . $user_settings['instance'] . ".php";
$cSession = curl_init();
curl_setopt($cSession, CURLOPT_URL, "https://" . $user_settings['instance'] . "/oauth/token");
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_HEADER, false);
curl_setopt($cSession, CURLOPT_POST, 1);
curl_setopt($cSession, CURLOPT_POSTFIELDS, http_build_query(array(
'client_id' => $client['client_id'],
'client_secret' => $client['client_secret'],
'grant_type' => 'authorization_code',
'grant_type' => 'authorization_code',
'code' => $_GET['code'],
'redirect_uri' => $client['redirect_uri']
)));
$result = curl_exec($cSession);
curl_close($cSession);
$data = json_decode($result, true);
//$atoken = msc($data['access_token'],'e');
$atoken = $data['access_token'];
setcookie('token', $atoken, time() + 60 * 60 * 24 * 30, $cdata['path'], $cdata['host'], false, true);
$token = $data['access_token'];
$info = api_get("accounts/verify_credentials");
$user_settings['acct'] = $info['acct'];
$user_settings['username'] = $info['display_name'];
$user_settings['avatar'] = $info['avatar'];
$user_settings['uid'] = $info['id'];
$info = api_get("instance");
if (is_numeric(strpos($info['version'], 'Pleroma'))) {
$user_settings['pleroma'] = 'true';
}
setrawcookie("user_settings", base64_encode(json_encode($user_settings)) , time() + 60 * 60 * 24 * 30, '/');
header('Location: ' . $setting['url']);