Skip to content

Commit

Permalink
Merge pull request #307 from owncloud/fix-auth-module-user-lookup
Browse files Browse the repository at this point in the history
Fix user lookup in authmodule
  • Loading branch information
kulmann authored Oct 7, 2021
2 parents 5d66c71 + 3a4335f commit d0c4194
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/AuthModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ public function authToken($bearerToken): ?IUser {

/** @var \OCP\IUserManager $userManager */
$userManager = $container->query('UserManager');
return $userManager->get($accessToken->getUserId());
$userId = $accessToken->getUserId();
if (\strstr($userId, ':')) {
list(1 => $userId) = \explode(':', $userId, 2);
}
return $userManager->get($userId);
}

protected function tokenCanBeHandledByOpenIDConnect(): bool {
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/AuthModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class AuthModuleTest extends TestCase {
/** @var String $userId */
private $userId = 'john';

/** @var String $userIdConcat */
private $userIdConcat = 'John Doe:john';

/** @var ClientMapper $clientMapper */
private $clientMapper;

Expand Down Expand Up @@ -116,6 +119,18 @@ public function testAuth() {
$user = $this->authModule->auth($request);
$this->assertNotNull($user);
$this->assertEquals($this->userId, $user->getUID());

// Valid request with ConcatUserID
$request = $this->getMockBuilder(IRequest::class)->getMock();
$this->accessToken->setUserId($this->userIdConcat);
$this->accessToken = $this->accessTokenMapper->update($this->accessToken);
$request->expects($this->once())
->method('getHeader')
->with($this->equalTo('Authorization'))
->will($this->returnValue('Bearer ' . $this->accessToken->getToken()));
$user = $this->authModule->auth($request);
$this->assertNotNull($user);
$this->assertEquals($this->userId, $user->getUID());
}

/**
Expand Down

0 comments on commit d0c4194

Please sign in to comment.