Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0dc1802
Merge pull request #681 from CakeDC/develop
steinkel Apr 20, 2018
544cace
fix docs
steinkel Apr 26, 2018
30ea0af
CakeDC/Users.RememberMe -> CakeDC/Auth.RememberMe
andrej-griniuk Apr 30, 2018
d190a3b
Merge pull request #688 from CakeDC/andrej-griniuk-patch-1
steinkel Apr 30, 2018
3cf87b4
Save user in temp session for Two factor authentication
rochamarcelo Jun 8, 2018
03c6fb2
Save user in temp session for Two factor authentication
rochamarcelo Jun 8, 2018
c56d6fc
Two factor authentication verify should work when temporary session i…
rochamarcelo Jun 8, 2018
c17ac3a
check for array when extracting temporarySession
steinkel Jun 11, 2018
d218b9a
refs #rochamarcelo-google-two-factor-auth fix deprecations
steinkel Jun 11, 2018
da95b32
Merge pull request #699 from CakeDC/rochamarcelo-issue/google-two-fac…
steinkel Jun 13, 2018
efe4297
Update .semver
steinkel Jun 13, 2018
aba4fd1
refs #692 update cakedc/auth
steinkel Jun 13, 2018
de13b7e
Update CHANGELOG.md
steinkel Jun 13, 2018
b1e5dee
fix typo
steinkel Jun 13, 2018
9b85908
Fix secrets being regenerated on every request.
Jun 13, 2018
0f26b67
Use the Auth component to store user data.
Jun 13, 2018
c2f0491
Add two-step auth code verification tests.
Jun 13, 2018
4188f58
Merge pull request #700 from ndm2/issue/two-factor-auth-secret-regene…
steinkel Jun 20, 2018
526d066
Update .semver
steinkel Jun 20, 2018
2fc40f2
Update CHANGELOG.md
steinkel Jun 20, 2018
342d981
Change the old syntax of `$this->request->session()` to `$this->reque…
Lartak Jul 28, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .semver
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
:major: 7
:minor: 0
:patch: 0
:patch: 2
:special: ''
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Changelog
Releases for CakePHP 3
-------------

* 7.0.1
* Fixed an issue with 2FA only working on the second try

* 7.0.1
* Fixed a security issue in 2 factor authentication, reported by @ndm2
* Updated to cakedc/auth ^3.0
* Documentation fixes

* 7.0.0
* Removed deprecations for CakePHP 3.6
* Added a new `UsersAuthComponent::EVENT_AFTER_CHANGE_PASSWORD`
Expand Down
4 changes: 2 additions & 2 deletions Docs/Documentation/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ NOTE: SOME keys were hidden in this doc page, please refer to `vendor/cakedc/use
'all' => [
'finder' => 'active',
],
'CakeDC/Users.RememberMe',
'CakeDC/Auth.RememberMe',
'Form',
],
'authorize' => [
Expand All @@ -140,10 +140,10 @@ Using the UsersAuthComponent default initialization, the component will load the
* 'Form'
* 'CakeDC/Users.Social' check [SocialAuthenticate](SocialAuthenticate.md) for configuration options
* 'CakeDC/Auth.RememberMe' check [RememberMeAuthenticate](https://github.com/CakeDC/auth/blob/master/src/RememberMeAuthenticate.php) for configuration options
* 'CakeDC/Auth.ApiKey' check [ApiKeyAuthenticate](https://github.com/CakeDC/auth/blob/master/Docs/Documentation/ApiKeyAuthenticate.md) for configuration options
* Authorize
* 'CakeDC/Auth.Superuser' check [SuperuserAuthorize](https://github.com/CakeDC/auth/blob/master/Docs/Documentation/SuperuserAuthorize.md) for configuration options
* 'CakeDC/Auth.SimpleRbac' check [SimpleRbacAuthorize](https://github.com/CakeDC/auth/blob/master/Docs/Documentation/SimpleRbacAuthorize.md) for configuration options
* 'CakeDC/Auth.ApiKey' check [ApiKeyAuthenticate](https://github.com/CakeDC/auth/blob/master/Docs/Documentation/ApiKeyAuthenticate.md) for configuration options

## Using the user's email to login

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"require": {
"cakephp/cakephp": "^3.6",
"cakedc/auth": "^2.0"
"cakedc/auth": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^5.0",
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/Traits/LinkSocialTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function linkSocial($alias = null)
}
$authUrl = $provider->getAuthorizationUrl($temporaryCredentials);
if (empty($temporaryCredentials)) {
$this->request->session()->write('SocialLink.oauth2state', $provider->getState());
$this->request->getSession()->write('SocialLink.oauth2state', $provider->getState());
}

return $this->redirect($authUrl);
Expand Down Expand Up @@ -228,8 +228,8 @@ protected function _validateCallbackSocialLink()
}

$sessionKey = 'SocialLink.oauth2state';
$oauth2state = $this->request->session()->read($sessionKey);
$this->request->session()->delete($sessionKey);
$oauth2state = $this->request->getSession()->read($sessionKey);
$this->request->getSession()->delete($sessionKey);
$state = $queryParams['state'];

return $oauth2state === $state;
Expand Down
29 changes: 15 additions & 14 deletions src/Controller/Traits/LoginTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,20 +218,15 @@ public function verify()
return $this->redirect(Configure::read('Auth.loginAction'));
}

// storing user's session in the temporary one
// until the GA verification is checked
$temporarySession = $this->Auth->user();
$this->request->getSession()->delete('Auth.User');
$temporarySession = $this->request->getSession()->read('temporarySession');
if (!is_array($temporarySession) || empty($temporarySession)) {
$this->Flash->error(__d('CakeDC/Users', 'Invalid request.'), 'default', [], 'auth');

if (!empty($temporarySession)) {
$this->request->getSession()->write('temporarySession', $temporarySession);
}

if (array_key_exists('secret', $temporarySession)) {
$secret = $temporarySession['secret'];
return $this->redirect(Configure::read('Auth.loginAction'));
}

$secretVerified = Hash::get((array)$temporarySession, 'secret_verified');
$secret = Hash::get($temporarySession, 'secret');
$secretVerified = Hash::get($temporarySession, 'secret_verified');

// showing QR-code until shared secret is verified
if (!$secretVerified) {
Expand All @@ -245,6 +240,8 @@ public function verify()
->set(['secret' => $secret])
->where(['id' => $temporarySession['id']]);
$query->execute();

$this->request->getSession()->write('temporarySession.secret', $secret);
} catch (\Exception $e) {
$this->request->getSession()->destroy();
$message = $e->getMessage();
Expand Down Expand Up @@ -278,10 +275,12 @@ public function verify()
->set(['secret_verified' => true])
->where(['id' => $user['id']])
->execute();

$user['secret_verified'] = true;
}

$this->request->getSession()->delete('temporarySession');
$this->request->getSession()->write('Auth.User', $user);
$this->Auth->setUser($user);
$url = $this->Auth->redirectUrl();

return $this->redirect($url);
Expand Down Expand Up @@ -322,14 +321,16 @@ protected function _checkReCaptcha()
protected function _afterIdentifyUser($user, $socialLogin = false, $googleAuthenticatorLogin = false)
{
if (!empty($user)) {
$this->Auth->setUser($user);

if ($googleAuthenticatorLogin) {
// storing user's session in the temporary one
// until the GA verification is checked
$this->request->getSession()->write('temporarySession', $user);
$url = Configure::read('GoogleAuthenticator.verifyAction');

return $this->redirect($url);
}

$this->Auth->setUser($user);
$event = $this->dispatchEvent(UsersAuthComponent::EVENT_AFTER_LOGIN, ['user' => $user]);
if (is_array($event->result)) {
return $this->redirect($event->result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public function setUp()
$this->backupUsersConfig = Configure::read('Users');

Router::reload();
Plugin::routes('CakeDC/Users');
Router::connect('/route/*', [
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function setUp()
$this->backupUsersConfig = Configure::read('Users');

Router::reload();
Plugin::routes('CakeDC/Users');
Router::connect('/route/*', [
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
Expand Down
Loading