UPSTREAM BASELINE: nextcloud/spreed v22.0.12 (без изменений)
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled
Источник: https://github.com/nextcloud/spreed/archive/refs/tags/v22.0.12.tar.gz С этого коммита ветка официального Nextcloud Talk отрезана (решение владельца 2026-07-06). Все дальнейшие изменения — только наши; версии релизов: 22.0.12-f7.N.
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Federation;
|
||||
|
||||
use OCA\Talk\Exceptions\ParticipantNotFoundException;
|
||||
use OCA\Talk\Exceptions\RoomNotFoundException;
|
||||
use OCA\Talk\Participant;
|
||||
use OCA\Talk\Room;
|
||||
use OCP\Federation\ICloudIdManager;
|
||||
use OCP\IRequest;
|
||||
|
||||
class Authenticator {
|
||||
protected ?bool $isFederationRequest = null;
|
||||
protected ?string $federationCloudId = null;
|
||||
protected ?string $accessToken = null;
|
||||
protected ?Room $room = null;
|
||||
protected ?Participant $participant = null;
|
||||
|
||||
public function __construct(
|
||||
protected IRequest $request,
|
||||
protected ICloudIdManager $cloudIdManager,
|
||||
) {
|
||||
}
|
||||
|
||||
protected function readHeaders(): void {
|
||||
$this->isFederationRequest = (bool)$this->request->getHeader('x-nextcloud-federation');
|
||||
if (!$this->isFederationRequest) {
|
||||
$this->federationCloudId = '';
|
||||
$this->accessToken = '';
|
||||
return;
|
||||
}
|
||||
|
||||
$authUser = $this->request->server['PHP_AUTH_USER'] ?? '';
|
||||
$authUser = urldecode($authUser);
|
||||
|
||||
try {
|
||||
$cloudId = $this->cloudIdManager->resolveCloudId($authUser);
|
||||
$this->federationCloudId = $cloudId->getId();
|
||||
$this->accessToken = $this->request->server['PHP_AUTH_PW'] ?? '';
|
||||
} catch (\InvalidArgumentException) {
|
||||
$this->isFederationRequest = false;
|
||||
$this->federationCloudId = '';
|
||||
$this->accessToken = '';
|
||||
}
|
||||
}
|
||||
|
||||
public function isFederationRequest(): bool {
|
||||
if ($this->isFederationRequest === null) {
|
||||
$this->readHeaders();
|
||||
|
||||
if ($this->isFederationRequest === null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->isFederationRequest;
|
||||
}
|
||||
|
||||
public function getCloudId(): string {
|
||||
if ($this->federationCloudId === null) {
|
||||
$this->readHeaders();
|
||||
|
||||
if ($this->federationCloudId === null) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->federationCloudId;
|
||||
}
|
||||
|
||||
public function getAccessToken(): string {
|
||||
if ($this->accessToken === null) {
|
||||
$this->readHeaders();
|
||||
|
||||
if ($this->accessToken === null) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->accessToken;
|
||||
}
|
||||
|
||||
public function authenticated(Room $room, Participant $participant): void {
|
||||
$this->room = $room;
|
||||
$this->participant = $participant;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RoomNotFoundException
|
||||
*/
|
||||
public function getRoom(): Room {
|
||||
if ($this->room === null) {
|
||||
throw new RoomNotFoundException();
|
||||
}
|
||||
return $this->room;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ParticipantNotFoundException
|
||||
*/
|
||||
public function getParticipant(): Participant {
|
||||
if ($this->participant === null) {
|
||||
throw new ParticipantNotFoundException();
|
||||
}
|
||||
return $this->participant;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user