thephpleague / oauth2-server

A spec compliant, secure by default PHP OAuth 2.0 Server
https://oauth2.thephpleague.com
MIT License
6.52k stars 1.12k forks source link

PSR-15 version #942

Open diogodomanski opened 5 years ago

diogodomanski commented 5 years ago

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

Sephster commented 5 years ago

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.

xgin commented 5 years ago

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.