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

Compare changes

Choose any two refs to compare.

Changed files
+61 -55
templates
+57 -55
index.php
···
});
Flight::route('/login', function(): void {
+
if (isset($_GET['username'])) {
$username = $_GET['username'];
-
$bskyToucher = new BskyToucher();
-
$userInfo = $bskyToucher->getUserInfo($username);
-
if (!$userInfo) die(1);
-
$pds = $userInfo->pds;
-
$options = new OAuthOptions([
-
'key' => 'https://'.SITE_DOMAIN.CLIENT_ID,
-
'secret' => CLIENT_SECRET,
-
'callbackURL' => 'https://'.SITE_DOMAIN.'/login',
-
'sessionStart' => true,
-
'sessionStorageVar' => 'sbs_'.SITE_DOMAIN
-
]);
-
$storage = new SessionStorage($options);
-
$connector = new React\Socket\Connector([
-
'dns' => '1.1.1.1'
-
]);
-
$http = new React\Http\Browser($connector);
-
$httpFactory = new HttpFactory();
-
$token_builder = Builder::new(new JoseEncoder(), ChainedFormatter::default());
-
$algorithm = new Sha256();
-
$signing_key = InMemory::file(CERT_PATH);
-
$now = new DateTimeImmutable();
-
$token = $token_builder
-
->withHeader('alg', 'ES256')
-
->withHeader('typ', 'JWT')
-
->withHeader('kid', 'ocwgKj_O7H9at1sL6yWf9ZZ82NOM7D0xlN8HGIyWH6M')
-
->issuedBy('https://'.SITE_DOMAIN.CLIENT_ID)
-
->identifiedBy(uniqid())
-
->relatedTo('https://'.SITE_DOMAIN.CLIENT_ID)
-
->permittedFor($pds)
-
->issuedAt($now->modify('-5 seconds'))
-
->getToken($algorithm, $signing_key);
-
$client = new GuzzleHttp\Client([
-
'verify' => true,
-
'headers' => [
-
'User-Agent' => USER_AGENT_STR,
-
'Authorization' => 'Bearer: '.$token->toString()
-
]
-
]);
-
$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',
-
'client_assertion' => $token->toString()
+
$bskyToucher = new BskyToucher();
+
$userInfo = $bskyToucher->getUserInfo($username);
+
if (!$userInfo) die(1);
+
$pds = $userInfo->pds;
+
$options = new OAuthOptions([
+
'key' => 'https://'.SITE_DOMAIN.CLIENT_ID,
+
'secret' => CLIENT_SECRET,
+
'callbackURL' => 'https://'.SITE_DOMAIN.'/login',
+
'sessionStart' => true,
+
'sessionStorageVar' => 'sbs_'.SITE_DOMAIN
]);
-
Flight::redirect($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()
-
Flight::redirect('/');
-
die(1);
-
} else if (isset($_GET['error'])) {
-
die(1);
+
$storage = new SessionStorage($options);
+
$connector = new React\Socket\Connector([
+
'dns' => '1.1.1.1'
+
]);
+
$http = new React\Http\Browser($connector);
+
$httpFactory = new HttpFactory();
+
$token_builder = Builder::new(new JoseEncoder(), ChainedFormatter::default());
+
$algorithm = new Sha256();
+
$signing_key = InMemory::file(CERT_PATH);
+
$now = new DateTimeImmutable();
+
$token = $token_builder
+
->withHeader('alg', 'ES256')
+
->withHeader('typ', 'JWT')
+
->withHeader('kid', 'ocwgKj_O7H9at1sL6yWf9ZZ82NOM7D0xlN8HGIyWH6M')
+
->issuedBy('https://'.SITE_DOMAIN.CLIENT_ID)
+
->identifiedBy(uniqid())
+
->relatedTo('https://'.SITE_DOMAIN.CLIENT_ID)
+
->permittedFor($pds)
+
->issuedAt($now->modify('-5 seconds'))
+
->getToken($algorithm, $signing_key);
+
$client = new GuzzleHttp\Client([
+
'verify' => true,
+
'headers' => [
+
'User-Agent' => USER_AGENT_STR,
+
'Authorization' => 'Bearer: '.$token->toString()
+
]
+
]);
+
$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',
+
'client_assertion' => $token->toString()
+
]);
+
Flight::redirect($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();
+
Flight::redirect('/');
+
die(1);
+
} else if (isset($_GET['error'])) {
+
die(1);
+
}
} else {
$latte = new Latte\Engine;
$latte->render('./templates/login.latte', array_merge(Flight::get('standardParams'), [
+4
templates/layout.latte
···
data-theme="{$setTheme}"
data-font="{$setFont}"
>
+
<!--
+
{print_r($_SESSION)}
+
{print_r(PHP_SESSION_DISABLED)}
+
-->
<div id="page">
<header>
<h1><a href="/">{include '_partials/logo.latte'}{$siteTitle}</a></h1>