Skip to content

Commit ee7f611

Browse files
author
Lionel Elie Mamane
committed
Return correct loginname in credentials,
even when token is invalid or has no password. Returning the uid as loginname is wrong, and leads to problems when these differ. E.g. the getapppassword API was creating app token with the uid as loginname. In a scenario with external authentication (such as LDAP), these tokens were then invalidated next time their underlying password was checked, and systematically ceased to function. Signed-off-by: Lionel Elie Mamane <lionel@mamane.lu>
1 parent 8325ab4 commit ee7f611

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

lib/private/Authentication/LoginCredentials/Store.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function getLoginCredentials(): ICredentials {
112112

113113
if ($trySession && $this->session->exists('login_credentials')) {
114114
$creds = json_decode($this->session->get('login_credentials'));
115-
return new Credentials($creds->uid, $creds->uid, $creds->password);
115+
return new Credentials($creds->uid, $creds->login_name, $creds->password);
116116
}
117117

118118
// If we reach this line, an exception was thrown.

lib/private/Server.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,9 @@ public function __construct($webRoot, \OC\Config $config) {
557557
$dispatcher = $this->query(IEventDispatcher::class);
558558
$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
559559
});
560-
$userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) {
560+
$userSession->listen('\OC\User', 'postLogin', function ($user, $login_name, $password, $isTokenLogin) {
561561
/** @var $user \OC\User\User */
562-
\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
562+
\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'login_name' => $login_name, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
563563

564564
/** @var IEventDispatcher $dispatcher */
565565
$dispatcher = $this->query(IEventDispatcher::class);

lib/private/User/Session.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
* - preUnassignedUserId(string $uid)
8181
* - postUnassignedUserId(string $uid)
8282
* - preLogin(string $user, string $password)
83-
* - postLogin(\OC\User\User $user, string $password)
83+
* - postLogin(\OC\User\User $user, string $loginName, string $password, boolean $isTokenLogin)
8484
* - preRememberedLogin(string $uid)
8585
* - postRememberedLogin(\OC\User\User $user)
8686
* - logout()
@@ -400,11 +400,13 @@ public function completeLogin(IUser $user, array $loginDetails, $regenerateSessi
400400

401401
$this->dispatcher->dispatchTyped(new PostLoginEvent(
402402
$user,
403+
$loginDetails['loginName'],
403404
$loginDetails['password'],
404405
$isToken
405406
));
406407
$this->manager->emit('\OC\User', 'postLogin', [
407408
$user,
409+
$loginDetails['loginName'],
408410
$loginDetails['password'],
409411
$isToken,
410412
]);

lib/public/User/Events/PostLoginEvent.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ class PostLoginEvent extends Event {
3838
/** @var IUser */
3939
private $user;
4040

41+
/**
42+
* @since 20.0.0
43+
* @var string
44+
*/
45+
private $loginName;
46+
4147
/** @var string */
4248
private $password;
4349

@@ -47,9 +53,10 @@ class PostLoginEvent extends Event {
4753
/**
4854
* @since 18.0.0
4955
*/
50-
public function __construct(IUser $user, string $password, bool $isTokenLogin) {
56+
public function __construct(IUser $user, string $loginName, string $password, bool $isTokenLogin) {
5157
parent::__construct();
5258
$this->user = $user;
59+
$this->loginName = $loginName;
5360
$this->password = $password;
5461
$this->isTokenLogin = $isTokenLogin;
5562
}
@@ -61,6 +68,13 @@ public function getUser(): IUser {
6168
return $this->user;
6269
}
6370

71+
/**
72+
* @since 20.0.0
73+
*/
74+
public function getLoginName(): string {
75+
return $this->login_name;
76+
}
77+
6478
/**
6579
* @since 18.0.0
6680
*/

0 commit comments

Comments
 (0)