-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix remember me login #1347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix remember me login #1347
Changes from 1 commit
d907666
6f86e46
b269ed5
271f2a4
9d6e01e
4da6b20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
* try to reuse the old session token for remember me login * decrypt/encrypt token password and set the session id accordingly * create remember-me cookies only if checkbox is checked and 2fa solved * adjust db token cleanup to store remembered tokens longer * adjust unit tests Signed-off-by: Christoph Wurst <[email protected]>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
|
|
||
| interface IProvider { | ||
|
|
||
|
|
||
| /** | ||
| * Create and persist a new token | ||
| * | ||
|
|
@@ -37,9 +38,10 @@ interface IProvider { | |
| * @param string|null $password | ||
| * @param string $name | ||
| * @param int $type token type | ||
| * @param int $remember whether the session token should be used for remember-me | ||
| * @return IToken | ||
| */ | ||
| public function generateToken($token, $uid, $loginName, $password, $name, $type = IToken::TEMPORARY_TOKEN); | ||
| public function generateToken($token, $uid, $loginName, $password, $name, $type = IToken::TEMPORARY_TOKEN, $remember = IToken::DO_NOT_REMEMBER); | ||
|
|
||
| /** | ||
| * Get a token by token id | ||
|
|
@@ -50,6 +52,12 @@ public function generateToken($token, $uid, $loginName, $password, $name, $type | |
| */ | ||
| public function getToken($tokenId) ; | ||
|
|
||
| /** | ||
| * @param string $oldSessionId | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add at least a single line comment what the function is supposed to do? :)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| * @param string $sessionId | ||
| */ | ||
| public function renewSessionToken($oldSessionId, $sessionId); | ||
|
|
||
| /** | ||
| * Invalidate (delete) the given session token | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ class Manager { | |
| const SESSION_UID_KEY = 'two_factor_auth_uid'; | ||
| const BACKUP_CODES_APP_ID = 'twofactor_backupcodes'; | ||
| const BACKUP_CODES_PROVIDER_ID = 'backup_codes'; | ||
| const REMEBER_LOGIN = 'two_factor_remember_login'; | ||
|
||
|
|
||
| /** @var AppManager */ | ||
| private $appManager; | ||
|
|
@@ -51,6 +52,7 @@ class Manager { | |
| * @param AppManager $appManager | ||
| * @param ISession $session | ||
| * @param IConfig $config | ||
| * @param Session $userSession | ||
|
||
| */ | ||
| public function __construct(AppManager $appManager, ISession $session, IConfig $config) { | ||
| $this->appManager = $appManager; | ||
|
|
@@ -171,11 +173,16 @@ public function verifyChallenge($providerId, IUser $user, $challenge) { | |
| return false; | ||
| } | ||
|
|
||
| $result = $provider->verifyChallenge($user, $challenge); | ||
| if ($result) { | ||
| $passed = $provider->verifyChallenge($user, $challenge); | ||
| if ($passed) { | ||
| if ($this->session->get(self::REMEBER_LOGIN) === true) { | ||
| // TODO: resolve cyclic dependency and use DI | ||
| \OC::$server->getUserSession()->createRememberMeToken($user); | ||
| } | ||
| $this->session->remove(self::SESSION_UID_KEY); | ||
| $this->session->remove(self::REMEBER_LOGIN); | ||
| } | ||
| return $result; | ||
| return $passed; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -202,12 +209,14 @@ public function needsSecondFactor(IUser $user = null) { | |
| } | ||
|
|
||
| /** | ||
| * Prepare the 2FA login (set session value) | ||
| * Prepare the 2FA login | ||
| * | ||
| * @param IUser $user | ||
| * @param boolean $rememberMe | ||
| */ | ||
| public function prepareTwoFactorLogin(IUser $user) { | ||
| public function prepareTwoFactorLogin(IUser $user, $rememberMe) { | ||
| $this->session->set(self::SESSION_UID_KEY, $user->getUID()); | ||
| $this->session->set(self::REMEBER_LOGIN, $rememberMe); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function needs tests. Will write myself later.