oauth2-server icon indicating copy to clipboard operation
oauth2-server copied to clipboard

PSR-15 version

Open diogodomanski opened this issue 5 years ago • 2 comments

Hi,

I'm currently using the PSR-7 version with Zend Expressive 2, but I'm facing some obstacles on adapting it to work with Zend Expressive 3.

Is there any plans to create a PSR-15 version of this project?

Is there any guideline to make it work with Zend Expressive 3?

Thanks

diogodomanski avatar Sep 16 '18 21:09 diogodomanski

Hi @diogodomanski. The library doesn't support PSR-15 at the moment but we will add support for this as our middleware was created prior to this standard. There isn't any guidance on how to achieve this as yet.

We will likely release this in version 8 of the package which is currently some way off being released.

Sephster avatar Sep 17 '18 11:09 Sephster

I use the following factory for AuthorizationServerMiddleware with Zend Expressive 3:

use Psr\Container\ContainerInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

use League\OAuth2\Server\Middleware\AuthorizationServerMiddleware;
use League\OAuth2\Server\AuthorizationServer;

class AuthorizationServerMiddlewareFactory
{
   public function __invoke(ContainerInterface $container) {
        $middleware = new AuthorizationServerMiddleware($container->get(AuthorizationServer::class));

        return new class ($middleware) implements MiddlewareInterface {
            private $middleware;

            public function __construct(callable $middleware)
            {
                $this->middleware = $middleware;
            }

            public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
            {
                return ($this->middleware)(
                    $request,
                    new \Zend\Diactoros\Response(),
                    function ($request, $response) {
                        return $response;
                    }
                );
            }
        };
    }
}

For ResourceServerMiddleware is enough to wrap it with Zend\Stratigility\Middleware\DoublePassMiddlewareDecorator.

xgin avatar Jan 06 '19 17:01 xgin