friendship ended with social-app. php is my new best friend

fiddle with getting the user info

Changed files
+15 -16
+15 -16
index.php
···
Flight::set('frontpageFeed', FRONTPAGE_FEED);
Flight::set('defaultRelay', DEFAULT_RELAY);
Flight::set('userAuth', array_key_exists('sbs_'.SITE_DOMAIN, $_SESSION) ? $_SESSION['sbs_'.SITE_DOMAIN] : null);
Flight::set('flight.log_errors', false);
Flight::set('flight.handle_errors', false);
Flight::set('flight.content_length', false);
···
});
Flight::route('/login', function(): void {
-
if (!array_key_exists('username', $_GET)) {
-
$latte = new Latte\Engine;
-
$latte->render('./templates/login.latte', array_merge(Flight::get('standardParams'), [
-
'mainClass' => 'form',
-
'ogtitle' => SITE_TITLE." | login",
-
'ogdesc' => SITE_DESC,
-
'ogimage' => '',
-
'ogurl' => 'https://'.SITE_DOMAIN.'/login'
-
]));
-
die(1);
-
}
$username = $_GET['username'];
$bskyToucher = new BskyToucher();
$userInfo = $bskyToucher->getUserInfo($username);
···
$provider = new BskyProvider($options, $client, $httpFactory, $httpFactory, $httpFactory);
$provider->setPds($pds);
$name = $provider->getName();
-
-
echo 'get access token:';
-
print_r($storage->hasAccessToken($name));
-
if (isset($_GET['login']) && $_GET['login'] === $name) {
$auth_url = $provider->getAuthorizationUrl([
'client_assertion_type' => 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
···
]);
header('Location: '.$auth_url);
die(1);
-
} else if (isset($_GET['code'])) {
$storage->storeAccessToken($_GET['code'], $name);
header('Location: https://'.SITE_DOMAIN);
die(1);
} else if (isset($_GET['error'])) {
die(1);
}
});
···
Flight::set('frontpageFeed', FRONTPAGE_FEED);
Flight::set('defaultRelay', DEFAULT_RELAY);
Flight::set('userAuth', array_key_exists('sbs_'.SITE_DOMAIN, $_SESSION) ? $_SESSION['sbs_'.SITE_DOMAIN] : null);
+
Flight::set('userPds', array_key_exists('sbs_'.SITE_DOMAIN.'_pds', $_SESSION) ? $_SESSION['sbs_'.SITE_DOMAIN.'_pds'] : null);
+
Flight::set('userInfo', array_key_exists('sbs_'.SITE_DOMAIN.'_userinfo', $_SESSION) ? $_SESSION['sbs_'.SITE_DOMAIN.'_userinfo'] : null);
Flight::set('flight.log_errors', false);
Flight::set('flight.handle_errors', false);
Flight::set('flight.content_length', false);
···
});
Flight::route('/login', function(): void {
$username = $_GET['username'];
$bskyToucher = new BskyToucher();
$userInfo = $bskyToucher->getUserInfo($username);
···
$provider = new BskyProvider($options, $client, $httpFactory, $httpFactory, $httpFactory);
$provider->setPds($pds);
$name = $provider->getName();
if (isset($_GET['login']) && $_GET['login'] === $name) {
$auth_url = $provider->getAuthorizationUrl([
'client_assertion_type' => 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
···
]);
header('Location: '.$auth_url);
die(1);
+
} else if (isset($_GET['code'], $_GET['iss'])) {
$storage->storeAccessToken($_GET['code'], $name);
+
$_SESSION['sbs_'.SITE_DOMAIN.'_pds'] = $_GET['iss'];
+
$_SESSION['sbs_'.SITE_DOMAIN.'_userinfo'] = $bskyToucher->getUserInfo()
header('Location: https://'.SITE_DOMAIN);
die(1);
} else if (isset($_GET['error'])) {
+
die(1);
+
} else {
+
$latte = new Latte\Engine;
+
$latte->render('./templates/login.latte', array_merge(Flight::get('standardParams'), [
+
'mainClass' => 'form',
+
'ogtitle' => SITE_TITLE." | login",
+
'ogdesc' => SITE_DESC,
+
'ogimage' => '',
+
'ogurl' => 'https://'.SITE_DOMAIN.'/login'
+
]));
die(1);
}
});