mirror of
https://github.com/friendica/friendica
synced 2024-12-23 04:40:15 +00:00
Merge pull request #14015 from annando/did
Internal support for Bluesky tokens
This commit is contained in:
commit
4834255acf
2 changed files with 89 additions and 5 deletions
13
src/App.php
13
src/App.php
|
@ -43,6 +43,7 @@ use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Profile;
|
use Friendica\Model\Profile;
|
||||||
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
|
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
|
use Friendica\Protocol\ATProtocol\DID;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\HTTPInputData;
|
use Friendica\Util\HTTPInputData;
|
||||||
use Friendica\Util\HTTPSignature;
|
use Friendica\Util\HTTPSignature;
|
||||||
|
@ -565,8 +566,8 @@ class App
|
||||||
*/
|
*/
|
||||||
public function runFrontend(App\Router $router, IManagePersonalConfigValues $pconfig, Authentication $auth, App\Page $page, Nav $nav, ModuleHTTPException $httpException, HTTPInputData $httpInput, float $start_time, array $server)
|
public function runFrontend(App\Router $router, IManagePersonalConfigValues $pconfig, Authentication $auth, App\Page $page, Nav $nav, ModuleHTTPException $httpException, HTTPInputData $httpInput, float $start_time, array $server)
|
||||||
{
|
{
|
||||||
$requeststring = ($_SERVER['REQUEST_METHOD'] ?? '') . ' ' . ($_SERVER['REQUEST_URI'] ?? '') . ' ' . ($_SERVER['SERVER_PROTOCOL'] ?? '');
|
$requeststring = ($server['REQUEST_METHOD'] ?? '') . ' ' . ($server['REQUEST_URI'] ?? '') . ' ' . ($server['SERVER_PROTOCOL'] ?? '');
|
||||||
$this->logger->debug('Request received', ['address' => $_SERVER['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $_SERVER['HTTP_REFERER'] ?? '', 'user-agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
|
$this->logger->debug('Request received', ['address' => $server['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $server['HTTP_REFERER'] ?? '', 'user-agent' => $server['HTTP_USER_AGENT'] ?? '']);
|
||||||
$request_start = microtime(true);
|
$request_start = microtime(true);
|
||||||
|
|
||||||
$this->profiler->set($start_time, 'start');
|
$this->profiler->set($start_time, 'start');
|
||||||
|
@ -593,8 +594,10 @@ class App
|
||||||
Core\Hook::callAll('init_1');
|
Core\Hook::callAll('init_1');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DID::routeRequest($this->args->getCommand(), $server);
|
||||||
|
|
||||||
if ($this->mode->isNormal() && !$this->mode->isBackend()) {
|
if ($this->mode->isNormal() && !$this->mode->isBackend()) {
|
||||||
$requester = HTTPSignature::getSigner('', $_SERVER);
|
$requester = HTTPSignature::getSigner('', $server);
|
||||||
if (!empty($requester)) {
|
if (!empty($requester)) {
|
||||||
Profile::addVisitorCookieForHandle($requester);
|
Profile::addVisitorCookieForHandle($requester);
|
||||||
}
|
}
|
||||||
|
@ -716,10 +719,10 @@ class App
|
||||||
$response = $page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig, $nav, $this->session->getLocalUserId());
|
$response = $page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig, $nav, $this->session->getLocalUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->logger->debug('Request processed sucessfully', ['response' => $response->getStatusCode(), 'address' => $_SERVER['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $_SERVER['HTTP_REFERER'] ?? '', 'user-agent' => $_SERVER['HTTP_USER_AGENT'] ?? '', 'duration' => number_format(microtime(true) - $request_start, 3)]);
|
$this->logger->debug('Request processed sucessfully', ['response' => $response->getStatusCode(), 'address' => $server['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $server['HTTP_REFERER'] ?? '', 'user-agent' => $server['HTTP_USER_AGENT'] ?? '', 'duration' => number_format(microtime(true) - $request_start, 3)]);
|
||||||
System::echoResponse($response);
|
System::echoResponse($response);
|
||||||
} catch (HTTPException $e) {
|
} catch (HTTPException $e) {
|
||||||
$this->logger->debug('Request processed with exception', ['response' => $e->getCode(), 'address' => $_SERVER['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $_SERVER['HTTP_REFERER'] ?? '', 'user-agent' => $_SERVER['HTTP_USER_AGENT'] ?? '', 'duration' => number_format(microtime(true) - $request_start, 3)]);
|
$this->logger->debug('Request processed with exception', ['response' => $e->getCode(), 'address' => $server['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $server['HTTP_REFERER'] ?? '', 'user-agent' => $server['HTTP_USER_AGENT'] ?? '', 'duration' => number_format(microtime(true) - $request_start, 3)]);
|
||||||
$httpException->rawContent($e);
|
$httpException->rawContent($e);
|
||||||
}
|
}
|
||||||
$page->logRuntime($this->config, 'runFrontend');
|
$page->logRuntime($this->config, 'runFrontend');
|
||||||
|
|
81
src/Protocol/ATProtocol/DID.php
Normal file
81
src/Protocol/ATProtocol/DID.php
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (C) 2010-2024, the Friendica project
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Friendica\Protocol\ATProtocol;
|
||||||
|
|
||||||
|
use Friendica\Core\System;
|
||||||
|
use Friendica\Database\DBA;
|
||||||
|
use Friendica\DI;
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class handles DID related activities from the AT Protocol
|
||||||
|
*/
|
||||||
|
class DID
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Routes AT Protocol DID requests
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @param array $server
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function routeRequest(string $path, array $server)
|
||||||
|
{
|
||||||
|
$host = DI::baseUrl()->getHost();
|
||||||
|
|
||||||
|
if (($host == $server['SERVER_NAME']) || !strpos($server['SERVER_NAME'], '.' . $host)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!DI::config()->get('bluesky', 'friendica_handles')) {
|
||||||
|
throw new HTTPException\NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($path, ['.well-known/atproto-did', ''])) {
|
||||||
|
throw new HTTPException\NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$nick = str_replace('.' . $host, '', $server['SERVER_NAME']);
|
||||||
|
|
||||||
|
$user = DBA::selectFirst('user', ['uid'], ['nickname' => $nick, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
|
||||||
|
if (empty($user['uid'])) {
|
||||||
|
throw new HTTPException\NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!DI::pConfig()->get($user['uid'], 'bluesky', 'friendica_handle')) {
|
||||||
|
throw new HTTPException\NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($path == '') {
|
||||||
|
System::externalRedirect(DI::baseUrl() . '/profile/' . urlencode($nick), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$did = DI::pConfig()->get($user['uid'], 'bluesky', 'did');
|
||||||
|
if (empty($did)) {
|
||||||
|
throw new HTTPException\NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Content-Type: text/plain');
|
||||||
|
echo $did;
|
||||||
|
System::exit();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue