···
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);
71
+
Flight::set('userPds', array_key_exists('sbs_'.SITE_DOMAIN.'_pds', $_SESSION) ? $_SESSION['sbs_'.SITE_DOMAIN.'_pds'] : null);
72
+
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);
···
'setTheme' => array_key_exists('sbs_theme', $_COOKIE) ? $_COOKIE['sbs_theme'] : DEFAULT_THEME,
'setFont' => array_key_exists('sbs_font', $_COOKIE) ? $_COOKIE['sbs_font'] : DEFAULT_FONT,
'userAuth' => Flight::get('userAuth'),
84
+
'userPds' => Flight::get('userPds'),
85
+
'userInfo' => Flight::Get('userInfo'),
'favFeeds' => $favoriteFeeds,
···
Flight::route('/login', function(): void {
181
-
if (!array_key_exists('username', $_GET)) {
185
+
if (isset($_GET['username'])) {
186
+
$username = $_GET['username'];
187
+
$bskyToucher = new BskyToucher();
188
+
$userInfo = $bskyToucher->getUserInfo($username);
189
+
if (!$userInfo) die(1);
190
+
$pds = $userInfo->pds;
191
+
$options = new OAuthOptions([
192
+
'key' => 'https://'.SITE_DOMAIN.CLIENT_ID,
193
+
'secret' => CLIENT_SECRET,
194
+
'callbackURL' => 'https://'.SITE_DOMAIN.'/login',
195
+
'sessionStart' => true,
196
+
'sessionStorageVar' => 'sbs_'.SITE_DOMAIN
198
+
$storage = new SessionStorage($options);
199
+
$connector = new React\Socket\Connector([
202
+
$http = new React\Http\Browser($connector);
203
+
$httpFactory = new HttpFactory();
204
+
$token_builder = Builder::new(new JoseEncoder(), ChainedFormatter::default());
205
+
$algorithm = new Sha256();
206
+
$signing_key = InMemory::file(CERT_PATH);
207
+
$now = new DateTimeImmutable();
208
+
$token = $token_builder
209
+
->withHeader('alg', 'ES256')
210
+
->withHeader('typ', 'JWT')
211
+
->withHeader('kid', 'ocwgKj_O7H9at1sL6yWf9ZZ82NOM7D0xlN8HGIyWH6M')
212
+
->issuedBy('https://'.SITE_DOMAIN.CLIENT_ID)
213
+
->identifiedBy(uniqid())
214
+
->relatedTo('https://'.SITE_DOMAIN.CLIENT_ID)
215
+
->permittedFor($pds)
216
+
->issuedAt($now->modify('-5 seconds'))
217
+
->getToken($algorithm, $signing_key);
218
+
$client = new GuzzleHttp\Client([
221
+
'User-Agent' => USER_AGENT_STR,
222
+
'Authorization' => 'Bearer: '.$token->toString()
225
+
$provider = new BskyProvider($options, $client, $httpFactory, $httpFactory, $httpFactory);
226
+
$provider->setPds($pds);
227
+
$name = $provider->getName();
228
+
if (isset($_GET['login']) && $_GET['login'] === $name) {
229
+
$auth_url = $provider->getAuthorizationUrl([
230
+
'client_assertion_type' => 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
231
+
'client_assertion' => $token->toString()
233
+
Flight::redirect($auth_url);
235
+
} else if (isset($_GET['code'], $_GET['iss'])) {
236
+
$storage->storeAccessToken($_GET['code'], $name);
237
+
$_SESSION['sbs_'.SITE_DOMAIN.'_pds'] = $_GET['iss'];
238
+
$_SESSION['sbs_'.SITE_DOMAIN.'_userinfo'] = $bskyToucher->getUserInfo();
239
+
Flight::redirect('/');
241
+
} else if (isset($_GET['error'])) {
$latte = new Latte\Engine;
$latte->render('./templates/login.latte', array_merge(Flight::get('standardParams'), [
···
'ogurl' => 'https://'.SITE_DOMAIN.'/login'
192
-
$username = $_GET['username'];
193
-
$bskyToucher = new BskyToucher();
194
-
$userInfo = $bskyToucher->getUserInfo($username);
195
-
if (!$userInfo) die(1);
196
-
$pds = $userInfo->pds;
197
-
$options = new OAuthOptions([
198
-
'key' => 'https://'.SITE_DOMAIN.CLIENT_ID,
199
-
'secret' => CLIENT_SECRET,
200
-
'callbackURL' => 'https://'.SITE_DOMAIN.'/login',
201
-
'sessionStart' => true,
202
-
'sessionStorageVar' => 'sbs_'.SITE_DOMAIN
204
-
$storage = new SessionStorage($options);
205
-
$connector = new React\Socket\Connector([
208
-
$http = new React\Http\Browser($connector);
209
-
$httpFactory = new HttpFactory();
210
-
$token_builder = Builder::new(new JoseEncoder(), ChainedFormatter::default());
211
-
$algorithm = new Sha256();
212
-
$signing_key = InMemory::file(CERT_PATH);
213
-
$now = new DateTimeImmutable();
214
-
$token = $token_builder
215
-
->withHeader('alg', 'ES256')
216
-
->withHeader('typ', 'JWT')
217
-
->withHeader('kid', 'ocwgKj_O7H9at1sL6yWf9ZZ82NOM7D0xlN8HGIyWH6M')
218
-
->issuedBy('https://'.SITE_DOMAIN.CLIENT_ID)
219
-
->identifiedBy(uniqid())
220
-
->relatedTo('https://'.SITE_DOMAIN.CLIENT_ID)
221
-
->permittedFor($pds)
222
-
->issuedAt($now->modify('-5 seconds'))
223
-
->getToken($algorithm, $signing_key);
224
-
$client = new GuzzleHttp\Client([
227
-
'User-Agent' => USER_AGENT_STR,
228
-
'Authorization' => 'Bearer: '.$token->toString()
231
-
$provider = new BskyProvider($options, $client, $httpFactory, $httpFactory, $httpFactory);
232
-
$provider->setPds($pds);
233
-
$name = $provider->getName();
235
-
echo 'get access token:';
236
-
print_r($storage->hasAccessToken($name));
238
-
if (isset($_GET['login']) && $_GET['login'] === $name) {
239
-
$auth_url = $provider->getAuthorizationUrl([
240
-
'client_assertion_type' => 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
241
-
'client_assertion' => $token->toString()
243
-
header('Location: '.$auth_url);
245
-
} else if (isset($_GET['code'])) {
246
-
$storage->storeAccessToken($_GET['code'], $name);
247
-
header('Location: https://'.SITE_DOMAIN);
249
-
} else if (isset($_GET['error'])) {
256
+
Flight::route('/logout', function(): void {
257
+
unset($_SESSION['sbs_'.SITE_DOMAIN]);
258
+
unset($_SESSION['sbs_'.SITE_DOMAIN.'_pds']);
259
+
unset($_SESSION['sbs_'.SITE_DOMAIN.'_userinfo']);
260
+
Flight::redirect('/');
Flight::route('/createaccount', function(): void {