Skip to content

Commit

Permalink
Merge #108 also into release-1.0.0 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jnweiger committed Oct 15, 2020
1 parent f1194d6 commit 19524eb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [1.0.0] - 2020-09-16
## [1.0.0] - 2020-10-16

### Added

- Add configurable post_logout_redirect_uri - [#90](https://github.com/owncloud/openidconnect/issues/90)

### Changed

- Properly handle token expiry in the sabre dav auth backend - [#108](https://github.com/owncloud/openidconnect/pull/108)
- Limit OpenID Connect logins to users of specific user backend - [#100](https://github.com/owncloud/openidconnect/issues/100)
- Properly evaluate the config setting use-token-introspection-endpoint - [#98](https://github.com/owncloud/openidconnect/issues/98)
- Bump libraries
Expand Down
23 changes: 14 additions & 9 deletions lib/Sabre/OpenIdSabreAuthBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,23 @@ private function isDavAuthenticated($username) {
protected function validateBearerToken($bearerToken) {
if ($this->userSession->isLoggedIn() &&
$this->isDavAuthenticated($this->userSession->getUser()->getUID())) {
try {

// verify the bearer token
$tokenUser = $this->authModule->authToken($bearerToken);
if ($tokenUser === null) {
// verify the bearer token
$tokenUser = $this->authModule->authToken($bearerToken);
if ($tokenUser === null) {
return false;
}

// setup the user
$userId = $this->userSession->getUser()->getUID();
$this->setupFilesystem($userId);
$this->session->close();
return $this->principalPrefix . $userId;
} catch (\Exception $ex) {
$this->session->close();
return false;
}

// setup the user
$userId = $this->userSession->getUser()->getUID();
$this->setupFilesystem($userId);
$this->session->close();
return $this->principalPrefix . $userId;
}

$this->setupFilesystem();
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/Sabre/OpenIdSabreAuthBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace OCA\OpenIdConnect\Tests\Unit\Sabre;

use OC\HintException;
use OC\User\LoginException;
use OC\User\Session;
use OCA\OpenIdConnect\OpenIdConnectAuthModule;
use OCA\OpenIdConnect\Sabre\OpenIdSabreAuthBackend;
Expand Down Expand Up @@ -152,4 +153,17 @@ public function testNotLoggedInWithValidToken(): void {
$return = $this->backend->check($this->sabreRequest, $this->sabreResponse);
self::assertEquals([true, 'principals/users/alice'], $return);
}

public function testTokenExpiry(): void {
$this->userSession->method('isLoggedIn')->willReturn(true);
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('alice');
$this->userSession->method('getUser')->willReturn($user);
$this->session->method('get')->with(OpenIdSabreAuthBackend::DAV_AUTHENTICATED)->willReturn('alice');

$this->authModule->expects(self::once())->method('authToken')->with('1234567890')->willThrowException(new LoginException(':zzz:'));

$return = $this->backend->check($this->sabreRequest, $this->sabreResponse);
self::assertEquals([false, 'Bearer token was incorrect'], $return);
}
}

0 comments on commit 19524eb

Please sign in to comment.