phpoauth-2.0mezzio

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


Hy,

I would like to use this module (https://github.com/phly/phly-expressive-oauth2clientauthentication)in my expressive application.

I read this documentation https://phly.github.io/phly-expressive-oauth2clientauthentication

here is what I did :

in my config/autoload folder i add a oauth2clientauthentication.global.php with this array :

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

in my pipeline.php file i add

use Phly\Expressive\OAuth2ClientAuthentication\OAuth2CallbackMiddleware;

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

in my ConfigProvider.php file i add a route with this config (I use slim router with https://github.com/acelaya/expressive-slim-router:

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

When i tried this 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' and get an error :

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

I do not understand where is the problem, anyone have an idea to solve this?


Solution

  • It looks like you upgraded your Expressive installation without going through the migration guide.

    Check your config/autoload/dependencies.global.php. It should contain something like this:

    use Zend\Expressive\Container\NotFoundDelegateFactory;
    use Zend\Expressive\Delegate\NotFoundDelegate;
    
    return [
        'dependencies' => [
            'aliases' => [
                'Zend\Expressive\Delegate\DefaultDelegate' => NotFoundDelegate::class,
            ],
    
            'factories' => [
                NotFoundDelegate::class => NotFoundDelegateFactory::class,
            ],
        ],
    ];