diff --git a/CHANGELOG.md b/CHANGELOG.md index b016b76..bf0dc8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 2.3.3 under development - Enh #120: Explicitly import classes and constants in "use" section (@vjik) +- Enh #127: Bump `yiisoft/auth` version to `^3.3.0`, and fix deprecated classes usage (@klsoft-web, @vjik) ## 2.3.2 December 23, 2025 diff --git a/README.md b/README.md index 4ec205f..8607d0d 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ the state at every request. For this purpose, you can use the `clear()` method. ### Authentication methods -This package provides two authentication methods, `WebAuth` and `ApiAuth`, that implement the `Yiisoft\Auth\AuthenticationMethodInterface`. Both can be provided to the `Yiisoft\Auth\Authentication` middleware as authentication method. +This package provides two authentication methods, `WebAuth` and `ApiAuth`, that implement the `Yiisoft\Auth\AuthenticatorWithChallengeInterface`. Both can be provided to the `Yiisoft\Auth\Authentication` middleware as authentication method. #### WebAuth @@ -232,7 +232,7 @@ return [ ``` If the application is used along with the [yiisoft/config](https://github.com/yiisoft/config), the package is [configured](./config/di-web.php) -automatically to use `WebAuth` as default implementation of `Yiisoft\Auth\AuthenticationMethodInterface`. +automatically to use `WebAuth` as default implementation of `Yiisoft\Auth\AuthenticatorInterface`. #### ApiAuth @@ -253,15 +253,15 @@ $middleware = new Authentication( ); ``` -of to define it as an implementation of `Yiisoft\Auth\AuthenticationMethodInterface` in the [DI container](https://github.com/yiisoft/di) configuration: +of to define it as an implementation of `Yiisoft\Auth\AuthenticatorInterface` in the [DI container](https://github.com/yiisoft/di) configuration: ```php // config/web/di/auth.php -use Yiisoft\Auth\AuthenticationMethodInterface; +use Yiisoft\Auth\AuthenticatorInterface; use Yiisoft\User\Method\ApiAuth; return [ - AuthenticationMethodInterface::class => ApiAuth::class, + AuthenticatorInterface::class => ApiAuth::class, ]; ``` diff --git a/composer.json b/composer.json index 2345ad2..830a9dc 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "psr/http-server-middleware": "^1.0", "psr/log": "^1.1 || ^2.0 || ^3.0", "yiisoft/access": "^2.0", - "yiisoft/auth": "^2.0 || ^3.0", + "yiisoft/auth": "^3.3.0", "yiisoft/cookies": "^1.2", "yiisoft/session": "^1.0 || ^2.0 || ^3.0", "yiisoft/http": "^1.2" diff --git a/config/di-web.php b/config/di-web.php index 057704a..50f1370 100644 --- a/config/di-web.php +++ b/config/di-web.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Yiisoft\Auth\AuthenticationMethodInterface; +use Yiisoft\Auth\AuthenticatorInterface; use Yiisoft\User\CurrentUser; use Yiisoft\User\Guest\GuestIdentityFactory; use Yiisoft\User\Guest\GuestIdentityFactoryInterface; @@ -27,6 +28,7 @@ 'withAuthUrl()' => [$params['yiisoft/user']['authUrl']], ], + AuthenticatorInterface::class => WebAuth::class, AuthenticationMethodInterface::class => WebAuth::class, GuestIdentityFactoryInterface::class => GuestIdentityFactory::class, diff --git a/src/Method/ApiAuth.php b/src/Method/ApiAuth.php index e43fe8a..145b080 100644 --- a/src/Method/ApiAuth.php +++ b/src/Method/ApiAuth.php @@ -11,7 +11,11 @@ use Yiisoft\User\CurrentUser; /** - * Implementation of the `AuthenticationMethodInterface` for authenticating users in the API clients. + * Implementation of the `AuthenticatorInterface` for authenticating users in the API clients. + * + * @psalm-suppress DeprecatedInterface Implements the deprecated `AuthenticationMethodInterface` (instead of + * `AuthenticatorInterface` directly) to avoid a backward compatibility break. Will be switched + * to `AuthenticatorInterface` in the next major version, see https://github.com/yiisoft/user/issues/130. */ final class ApiAuth implements AuthenticationMethodInterface { diff --git a/src/Method/WebAuth.php b/src/Method/WebAuth.php index 90097b6..c4c3ced 100644 --- a/src/Method/WebAuth.php +++ b/src/Method/WebAuth.php @@ -13,7 +13,11 @@ use Yiisoft\User\CurrentUser; /** - * Implementation of the `AuthenticationMethodInterface` for authenticating users in the web applications. + * Implementation of the `AuthenticatorWithChallengeInterface` for authenticating users in the web applications. + * + * @psalm-suppress DeprecatedInterface Implements the deprecated `AuthenticationMethodInterface` (instead of + * `AuthenticatorWithChallengeInterface` directly) to avoid a backward compatibility break. Will be switched + * to `AuthenticatorWithChallengeInterface` in the next major version, see https://github.com/yiisoft/user/issues/130. */ final class WebAuth implements AuthenticationMethodInterface { diff --git a/src/UserAuth.php b/src/UserAuth.php index a473a4b..c05dbb5 100644 --- a/src/UserAuth.php +++ b/src/UserAuth.php @@ -13,9 +13,12 @@ use Yiisoft\User\Method\WebAuth; /** - * Implementation of the authentication interface for the user. + * Implementation of the `AuthenticatorWithChallengeInterface` interface for the user. * * @deprecated Use {@see WebAuth}. This class will be removed in the next major version. + * See https://github.com/yiisoft/user/issues/131. + * + * @psalm-suppress DeprecatedInterface */ final class UserAuth implements AuthenticationMethodInterface { diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index ecfe8ef..2e6eb5a 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -11,6 +11,7 @@ use Psr\Log\LoggerInterface; use ReflectionObject; use Yiisoft\Auth\AuthenticationMethodInterface; +use Yiisoft\Auth\AuthenticatorInterface; use Yiisoft\Auth\IdentityRepositoryInterface; use Yiisoft\Di\Container; use Yiisoft\Di\ContainerConfig; @@ -37,11 +38,13 @@ public function testBase(): void $this->assertInstanceOf(GuestIdentityFactory::class, $container->get(GuestIdentityFactoryInterface::class)); $this->assertInstanceOf(LoginMiddleware::class, $container->get(LoginMiddleware::class)); - $webAuth = $container->get(AuthenticationMethodInterface::class); + $webAuth = $container->get(AuthenticatorInterface::class); $this->assertInstanceOf(WebAuth::class, $webAuth); $this->assertSame('/login', $this->getInaccessibleProperty($webAuth, 'authUrl')); + $this->assertInstanceOf(WebAuth::class, $container->get(AuthenticationMethodInterface::class)); + $cookieLogin = $container->get(CookieLogin::class); $this->assertInstanceOf(CookieLogin::class, $cookieLogin); @@ -67,11 +70,13 @@ public function testOverrideParams(): void ], ]); - $webAuth = $container->get(AuthenticationMethodInterface::class); + $webAuth = $container->get(AuthenticatorInterface::class); $this->assertInstanceOf(WebAuth::class, $webAuth); $this->assertSame('/override', $this->getInaccessibleProperty($webAuth, 'authUrl')); + $this->assertInstanceOf(WebAuth::class, $container->get(AuthenticationMethodInterface::class)); + $cookieLogin = $container->get(CookieLogin::class); $this->assertInstanceOf(CookieLogin::class, $cookieLogin);