<?php
/**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\App;
use Friendica\BaseModule;
use Friendica\Core\L10n;
+use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Core\System;
use Friendica\Database\Database;
use Friendica\Model\Contact;
protected $dba;
/** @var ICanSendHttpRequests */
protected $httpClient;
+ /** @var IHandleUserSessions */
+ protected $userSession;
- public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, ICanSendHttpRequests $httpClient, array $server, array $parameters = [])
+ public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, ICanSendHttpRequests $httpClient, IHandleUserSessions $userSession, $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
- $this->app = $app;
- $this->dba = $dba;
- $this->httpClient = $httpClient;
+ $this->app = $app;
+ $this->dba = $dba;
+ $this->httpClient = $httpClient;
+ $this->userSession = $userSession;
}
protected function rawContent(array $request = [])
$contact = $this->dba->selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]);
// Redirect if the contact is already authenticated on this site.
- if ($this->app->getContactId() && strpos($contact['nurl'], Strings::normaliseLink($this->baseUrl->get())) !== false) {
+ if ($this->app->getContactId() && strpos($contact['nurl'], Strings::normaliseLink($this->baseUrl)) !== false) {
$this->logger->info('Contact is already authenticated');
System::externalRedirect($dest);
}
// OpenWebAuth
- if (local_user() && $owa) {
- $user = User::getById(local_user());
+ if ($this->userSession->getLocalUserId() && $owa) {
+ $user = User::getById($this->userSession->getLocalUserId());
// Extract the basepath
// NOTE: we need another solution because this does only work
$header = HTTPSignature::createSig(
$header,
$user['prvkey'],
- 'acct:' . $user['nickname'] . '@' . $this->baseUrl->getHostname() . ($this->baseUrl->getUrlPath() ? '/' . $this->baseUrl->getUrlPath() : '')
+ 'acct:' . $user['nickname'] . '@' . $this->baseUrl->getHost() . ($this->baseUrl->getPath() ? '/' . $this->baseUrl->getPath() : '')
);
// Try to get an authentication token from the other instance.