diff options
author | Richard Steinmetz <richard@steinmetz.cloud> | 2025-02-17 14:34:01 +0100 |
---|---|---|
committer | Richard Steinmetz <richard@steinmetz.cloud> | 2025-04-01 11:25:52 +0200 |
commit | 246da73a363c11d02eed69e80e76d7c9a9a04c7b (patch) | |
tree | 925d2a3109f1cd3327a0721380471c773d7d2b04 /apps/dav | |
parent | b03ffab5f0f39139c71cb2b8c370ca3f3d1ad391 (diff) | |
download | nextcloud-server-246da73a363c11d02eed69e80e76d7c9a9a04c7b.tar.gz nextcloud-server-246da73a363c11d02eed69e80e76d7c9a9a04c7b.zip |
fix(oauth2): retain support for legacy ownCloud clientsfix/oauth2/retain-legacy-oc-client-support
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/appinfo/v1/webdav.php | 3 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/BearerAuth.php | 10 | ||||
-rw-r--r-- | apps/dav/lib/Server.php | 3 | ||||
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php | 8 |
4 files changed, 21 insertions, 3 deletions
diff --git a/apps/dav/appinfo/v1/webdav.php b/apps/dav/appinfo/v1/webdav.php index fe47ba74652..baeae66bb20 100644 --- a/apps/dav/appinfo/v1/webdav.php +++ b/apps/dav/appinfo/v1/webdav.php @@ -61,7 +61,8 @@ $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend); $bearerAuthPlugin = new BearerAuth( Server::get(IUserSession::class), Server::get(ISession::class), - Server::get(IRequest::class) + Server::get(IRequest::class), + Server::get(IConfig::class), ); $authPlugin->addBackend($bearerAuthPlugin); diff --git a/apps/dav/lib/Connector/Sabre/BearerAuth.php b/apps/dav/lib/Connector/Sabre/BearerAuth.php index 07bb3e052a5..e189d8fa128 100644 --- a/apps/dav/lib/Connector/Sabre/BearerAuth.php +++ b/apps/dav/lib/Connector/Sabre/BearerAuth.php @@ -7,6 +7,7 @@ namespace OCA\DAV\Connector\Sabre; use OCP\AppFramework\Http; use OCP\Defaults; +use OCP\IConfig; use OCP\IRequest; use OCP\ISession; use OCP\IUserSession; @@ -19,6 +20,7 @@ class BearerAuth extends AbstractBearer { private IUserSession $userSession, private ISession $session, private IRequest $request, + private IConfig $config, private string $principalPrefix = 'principals/users/', ) { // setup realm @@ -57,6 +59,14 @@ class BearerAuth extends AbstractBearer { * @param ResponseInterface $response */ public function challenge(RequestInterface $request, ResponseInterface $response): void { + // Legacy ownCloud clients still authenticate via OAuth2 + $enableOcClients = $this->config->getSystemValueBool('oauth2.enable_oc_clients', false); + $userAgent = $request->getHeader('User-Agent'); + if ($enableOcClients && $userAgent !== null && str_contains($userAgent, 'mirall')) { + parent::challenge($request, $response); + return; + } + $response->setStatus(Http::STATUS_UNAUTHORIZED); } } diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index a14b49c178e..9ea18c029c8 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -157,7 +157,8 @@ class Server { $bearerAuthBackend = new BearerAuth( \OCP\Server::get(IUserSession::class), \OCP\Server::get(ISession::class), - \OCP\Server::get(IRequest::class) + \OCP\Server::get(IRequest::class), + \OCP\Server::get(IConfig::class), ); $authPlugin->addBackend($bearerAuthBackend); // because we are throwing exceptions this plugin has to be the last one diff --git a/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php b/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php index 06c070454af..99c2a461557 100644 --- a/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php @@ -7,10 +7,12 @@ namespace OCA\DAV\Tests\unit\Connector\Sabre; use OC\User\Session; use OCA\DAV\Connector\Sabre\BearerAuth; +use OCP\IConfig; use OCP\IRequest; use OCP\ISession; use OCP\IUser; use OCP\IUserSession; +use PHPUnit\Framework\MockObject\MockObject; use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; use Test\TestCase; @@ -28,17 +30,21 @@ class BearerAuthTest extends TestCase { /** @var BearerAuth */ private $bearerAuth; + private IConfig&MockObject $config; + protected function setUp(): void { parent::setUp(); $this->userSession = $this->createMock(Session::class); $this->session = $this->createMock(ISession::class); $this->request = $this->createMock(IRequest::class); + $this->config = $this->createMock(IConfig::class); $this->bearerAuth = new BearerAuth( $this->userSession, $this->session, - $this->request + $this->request, + $this->config, ); } |