Skip to content

Commit

Permalink
Merge tag '11.2.0' into 11.next-cake4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
skie committed Jul 13, 2023
2 parents 06c0bd6 + 33af434 commit 0d796dc
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .semver
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
:major: 11
:minor: 1
:minor: 2
:patch: 0
:special: ''
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"php-coveralls/php-coveralls": "^2.1",
"league/oauth1-client": "^1.7",
"cakephp/cakephp-codesniffer": "^4.0",
"web-auth/webauthn-lib": "v3.3.x-dev"
"web-auth/webauthn-lib": "^3.3",
"thenetworg/oauth2-azure": "^2.1"
},
"suggest": {
"league/oauth1-client": "Provides Social Authentication with Twitter",
Expand All @@ -59,7 +60,8 @@
"league/oauth2-linkedin": "Provides Social Authentication with LinkedIn",
"google/recaptcha": "Provides reCAPTCHA validation for registration form",
"robthree/twofactorauth": "Provides Google Authenticator functionality",
"cakephp/authorization": "Provide authorization for users"
"cakephp/authorization": "Provide authorization for users",
"thenetworg/oauth2-azure": "Provides Social Authentication with MS Azure"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -94,5 +96,10 @@
"rector": "rector process src/",
"rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:^0.11.2 && mv composer.backup composer.json",
"coverage-test": "phpunit --stderr --coverage-clover=clover.xml"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false
}
}
}
10 changes: 10 additions & 0 deletions config/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@
'scope' => 'email openid',
],
],
'azure' => [
'service' => 'CakeDC\Auth\Social\Service\OAuth2Service',
'className' => 'TheNetworg\OAuth2\Client\Provider\Azure',
'mapper' => 'CakeDC\Auth\Social\Mapper\Azure',
'options' => [
'redirectUri' => Router::fullBaseUrl() . '/auth/azure',
'linkSocialUri' => Router::fullBaseUrl() . '/link-social/azure',
'callbackLinkSocialUri' => Router::fullBaseUrl() . '/callback-link-social/azure',
],
],
],
],
];
Expand Down
7 changes: 7 additions & 0 deletions src/Controller/Component/LoginComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public function handleLogin($errorOnlyPost, $redirectFailure)
if (!$service) {
throw new \UnexpectedValueException('Authentication service not found in this request');
}
$eventBefore = $this->getController()->dispatchEvent(Plugin::EVENT_BEFORE_LOGIN, []);
if (is_array($eventBefore->getResult())) {
return $this->getController()->redirect($eventBefore->getResult());
}

$result = $service->getResult();
if ($result->isValid()) {
$user = $request->getAttribute('identity')->getOriginalData();
Expand All @@ -75,6 +80,8 @@ public function handleLogin($errorOnlyPost, $redirectFailure)
return $this->afterIdentifyUser($user);
}
if ($request->is('post') || $errorOnlyPost === false) {
$this->getController()->dispatchEvent(Plugin::EVENT_AFTER_LOGIN_FAILURE, ['result' => $result]);

return $this->handleFailure($redirectFailure);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class Plugin extends BasePlugin
* @var string
*/
protected $name = 'CakeDC/Users';
public const EVENT_BEFORE_LOGIN = 'Users.Authentication.beforeLogin';
public const EVENT_AFTER_LOGIN = 'Users.Authentication.afterLogin';
public const EVENT_AFTER_LOGIN_FAILURE = 'Users.Authentication.afterLoginFailure';
public const EVENT_BEFORE_LOGOUT = 'Users.Authentication.beforeLogout';
public const EVENT_AFTER_LOGOUT = 'Users.Authentication.afterLogout';

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Authenticator/SocialAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
use CakeDC\Users\Exception\SocialAuthenticationException;
use CakeDC\Users\Exception\UserNotActiveException;
use CakeDC\Users\Model\Entity\User;
use Laminas\Diactoros\Uri;
use League\OAuth2\Client\Provider\FacebookUser;
use Zend\Diactoros\Uri;

/**
* Test Case for SocialAuthenticator class
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Controller/Traits/LinkSocialTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
use Cake\Http\ServerRequestFactory;
use Cake\I18n\FrozenTime;
use Cake\ORM\TableRegistry;
use Laminas\Diactoros\Uri;
use League\OAuth2\Client\Provider\FacebookUser;
use Zend\Diactoros\Uri;

class LinkSocialTraitTest extends BaseTraitTest
{
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Middleware/SocialAuthMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
use CakeDC\Users\Exception\SocialAuthenticationException;
use CakeDC\Users\Middleware\SocialAuthMiddleware;
use Doctrine\Instantiator\Exception\UnexpectedValueException;
use Laminas\Diactoros\Uri;
use League\OAuth2\Client\Provider\FacebookUser;
use TestApp\Http\TestRequestHandler;
use Zend\Diactoros\Uri;

class SocialAuthMiddlewareTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Middleware/SocialEmailMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
use Cake\TestSuite\TestCase;
use CakeDC\Auth\Social\Mapper\Facebook;
use CakeDC\Users\Middleware\SocialEmailMiddleware;
use Laminas\Diactoros\Uri;
use League\OAuth2\Client\Provider\FacebookUser;
use Zend\Diactoros\Uri;

class SocialEmailMiddlewareTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Utility/UsersUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Cake\Http\ServerRequestFactory;
use Cake\TestSuite\TestCase;
use CakeDC\Users\Utility\UsersUrl;
use Zend\Diactoros\Uri;
use Laminas\Diactoros\Uri;

class UsersUrlTest extends TestCase
{
Expand Down

0 comments on commit 0d796dc

Please sign in to comment.