mirror of
https://github.com/friendica/friendica
synced 2025-04-19 13:50:15 +00:00
OpenWebAuth path is now fetched during probing
This commit is contained in:
parent
ea5e1f1edc
commit
da37516abf
13 changed files with 143 additions and 52 deletions
|
@ -25,8 +25,10 @@ use Exception;
|
|||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\GServer;
|
||||
|
@ -36,7 +38,7 @@ use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
|||
use Friendica\Util\HTTPSignature;
|
||||
use Friendica\Util\Profiler;
|
||||
use Friendica\Util\Strings;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use Friendica\Worker\UpdateContact;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
|
@ -115,22 +117,39 @@ class Magic extends BaseModule
|
|||
$owner = User::getOwnerDataById($this->userSession->getLocalUserId());
|
||||
|
||||
if (!empty($contact['gsid'])) {
|
||||
$gserver = $this->dba->selectFirst('gserver', ['url'], ['id' => $contact['gsid']]);
|
||||
if (empty($gserver)) {
|
||||
$this->logger->notice('Server not found, redirecting to destination.', ['gsid' => $contact['gsid'], 'dest' => $dest]);
|
||||
System::externalRedirect($dest);
|
||||
}
|
||||
|
||||
$basepath = $gserver['url'];
|
||||
$gsid = $contact['gsid'];
|
||||
} elseif (GServer::check($target)) {
|
||||
$basepath = (string)GServer::cleanUri(new Uri($target));
|
||||
} else {
|
||||
$gsid = GServer::getID($target);
|
||||
}
|
||||
|
||||
if (empty($gsid)) {
|
||||
$this->logger->notice('The target is not a server path, redirecting to destination.', ['target' => $target]);
|
||||
System::externalRedirect($dest);
|
||||
}
|
||||
|
||||
$gserver = $this->dba->selectFirst('gserver', ['url', 'network', 'openwebauth'], ['id' => $gsid]);
|
||||
if (empty($gserver)) {
|
||||
$this->logger->notice('Server not found, redirecting to destination.', ['gsid' => $gsid, 'dest' => $dest]);
|
||||
System::externalRedirect($dest);
|
||||
}
|
||||
|
||||
$openwebauth = $gserver['openwebauth'];
|
||||
|
||||
// This part can be removed, when all server entries had been updated. So removing it in 2025 should be safe.
|
||||
if (empty($openwebauth) && ($gserver['network'] == Protocol::DFRN)) {
|
||||
$this->logger->notice('Open Web Auth path not provided. Assume default path', ['gsid' => $gsid, 'dest' => $dest]);
|
||||
$openwebauth = $gserver['url'] . '/owa';
|
||||
// Update contact to assign the path to the server
|
||||
UpdateContact::add(Worker::PRIORITY_MEDIUM, $contact['id']);
|
||||
}
|
||||
|
||||
if (empty($openwebauth)) {
|
||||
$this->logger->debug('Server does not support open web auth, redirecting to destination.', ['gsid' => $gsid, 'dest' => $dest]);
|
||||
System::externalRedirect($dest);
|
||||
}
|
||||
|
||||
$header = [
|
||||
'Accept' => 'application/x-dfrn+json, application/x-zot+json',
|
||||
'Accept' => 'application/x-zot+json',
|
||||
'X-Open-Web-Auth' => Strings::getRandomHex()
|
||||
];
|
||||
|
||||
|
@ -141,13 +160,13 @@ class Magic extends BaseModule
|
|||
'acct:' . $owner['addr']
|
||||
);
|
||||
|
||||
$this->logger->info('Fetch from remote system', ['basepath' => $basepath, 'headers' => $header]);
|
||||
$this->logger->info('Fetch from remote system', ['openwebauth' => $openwebauth, 'headers' => $header]);
|
||||
|
||||
// Try to get an authentication token from the other instance.
|
||||
try {
|
||||
$curlResult = $this->httpClient->request('get', $basepath . '/owa', [HttpClientOptions::HEADERS => $header]);
|
||||
$curlResult = $this->httpClient->request('get', $openwebauth, [HttpClientOptions::HEADERS => $header]);
|
||||
} catch (Exception $exception) {
|
||||
$this->logger->notice('URL is invalid, redirecting to destination.', ['url' => $basepath, 'error' => $exception, 'dest' => $dest]);
|
||||
$this->logger->notice('URL is invalid, redirecting to destination.', ['url' => $openwebauth, 'error' => $exception, 'dest' => $dest]);
|
||||
System::externalRedirect($dest);
|
||||
}
|
||||
if (!$curlResult->isSuccess()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue