Improved basepath detection for Magic Auth
This commit is contained in:
parent
3951a77318
commit
75f8b3374e
1 changed files with 16 additions and 5 deletions
|
@ -29,12 +29,14 @@ use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
|
use Friendica\Model\GServer;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
|
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||||
use Friendica\Util\HTTPSignature;
|
use Friendica\Util\HTTPSignature;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
use GuzzleHttp\Psr7\Uri;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,6 +85,8 @@ class Magic extends BaseModule
|
||||||
$this->logger->debug('bdest detected', ['dest' => $dest]);
|
$this->logger->debug('bdest detected', ['dest' => $dest]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$target = $dest ?: $addr;
|
||||||
|
|
||||||
if ($addr ?: $dest) {
|
if ($addr ?: $dest) {
|
||||||
$contact = Contact::getByURL($addr ?: $dest);
|
$contact = Contact::getByURL($addr ?: $dest);
|
||||||
}
|
}
|
||||||
|
@ -110,6 +114,7 @@ class Magic extends BaseModule
|
||||||
// OpenWebAuth
|
// OpenWebAuth
|
||||||
$owner = User::getOwnerDataById($this->userSession->getLocalUserId());
|
$owner = User::getOwnerDataById($this->userSession->getLocalUserId());
|
||||||
|
|
||||||
|
if (!empty($contact['gsid'])) {
|
||||||
$gserver = $this->dba->selectFirst('gserver', ['url'], ['id' => $contact['gsid']]);
|
$gserver = $this->dba->selectFirst('gserver', ['url'], ['id' => $contact['gsid']]);
|
||||||
if (empty($gserver)) {
|
if (empty($gserver)) {
|
||||||
$this->logger->notice('Server not found, redirecting to destination.', ['gsid' => $contact['gsid'], 'dest' => $dest]);
|
$this->logger->notice('Server not found, redirecting to destination.', ['gsid' => $contact['gsid'], 'dest' => $dest]);
|
||||||
|
@ -117,6 +122,12 @@ class Magic extends BaseModule
|
||||||
}
|
}
|
||||||
|
|
||||||
$basepath = $gserver['url'];
|
$basepath = $gserver['url'];
|
||||||
|
} elseif (GServer::check($target)) {
|
||||||
|
$basepath = (string)GServer::cleanUri(new Uri($target));
|
||||||
|
} else {
|
||||||
|
$this->logger->notice('The target is not a server path, redirecting to destination.', ['target' => $target]);
|
||||||
|
System::externalRedirect($dest);
|
||||||
|
}
|
||||||
|
|
||||||
$header = [
|
$header = [
|
||||||
'Accept' => ['application/x-dfrn+json', 'application/x-zot+json'],
|
'Accept' => ['application/x-dfrn+json', 'application/x-zot+json'],
|
||||||
|
|
Loading…
Reference in a new issue