如何将 phly-expressive-oauth2clientauthentication 模块用于 zend-expressive

How use phly-expressive-oauth2clientauthentication module for zend-expressive

嗨,

我想在我的表达应用程序中使用这个模块 (https://github.com/phly/phly-expressive-oauth2clientauthentication)。

我阅读了这份文档https://phly.github.io/phly-expressive-oauth2clientauthentication

这是我所做的:

在我的 config/autoload 文件夹中,我用这个数组添加了一个 oauth2clientauthentication.global.php:

'oauth2clientauthentication' => [
    'routes' => [
        'production' => '/(:provider)(/oauth2callback)',
    ],
],

在我的 pipeline.php 文件中添加

use Phly\Expressive\OAuth2ClientAuthentication\OAuth2CallbackMiddleware;

$app->pipe('/auth', OAuth2CallbackMiddleware::class);

在我的 ConfigProvider.php 文件中,我添加了一个具有此配置的路由(我使用带有 https://github.com/acelaya/expressive-slim-router 的超薄路由器:

[
    'name' => 'admin',
    'path' => '/admin',
    'allowed_methods' => ['GET'],
    'middleware' => [
        SessionMiddleware::class,
        AuthenticationMiddleware::class,
        Action\AdminAction::class,
    ],

当我尝试这个 url : 'http://blog/admin', i get my unauthenticated page with github button. But when i click on the button the url is : 'http://blog/auth/github?redirect=http://blog/admin' 并得到一个错误:

Unable to resolve service "Zend\Expressive\Delegate\NotFoundDelegate"

我不明白问题出在哪里,有人有办法解决这个问题吗?

您似乎没有通过 migration guide 升级 Expressive 安装。

检查你的 config/autoload/dependencies.global.php。它应该包含如下内容:

use Zend\Expressive\Container\NotFoundDelegateFactory;
use Zend\Expressive\Delegate\NotFoundDelegate;

return [
    'dependencies' => [
        'aliases' => [
            'Zend\Expressive\Delegate\DefaultDelegate' => NotFoundDelegate::class,
        ],

        'factories' => [
            NotFoundDelegate::class => NotFoundDelegateFactory::class,
        ],
    ],
];