Skip to content

Commit

Permalink
use diactoros 2.0 and psr-http-factory
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 18, 2019
1 parent bbc7e84 commit aadf603
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"league/oauth2-server": "^7.0",
"phpseclib/phpseclib": "^2.0",
"symfony/psr-http-message-bridge": "~1.0",
"zendframework/zend-diactoros": "~1.0"
"zendframework/zend-diactoros": "~2.0"
},
"require-dev": {
"mockery/mockery": "~1.0",
Expand Down
13 changes: 11 additions & 2 deletions src/Guards/TokenGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
use Firebase\JWT\JWT;
use Illuminate\Http\Request;
use Laravel\Passport\Passport;
use Zend\Diactoros\StreamFactory;
use Illuminate\Container\Container;
use Zend\Diactoros\ResponseFactory;
use Laravel\Passport\TransientToken;
use Laravel\Passport\TokenRepository;
use Laravel\Passport\ClientRepository;
use Zend\Diactoros\UploadedFileFactory;
use League\OAuth2\Server\ResourceServer;
use Zend\Diactoros\ServerRequestFactory;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Contracts\Debug\ExceptionHandler;
use League\OAuth2\Server\Exception\OAuthServerException;
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;

class TokenGuard
{
Expand Down Expand Up @@ -168,7 +172,12 @@ protected function getPsrRequestViaBearerToken($request)
// First, we will convert the Symfony request to a PSR-7 implementation which will
// be compatible with the base OAuth2 library. The Symfony bridge can perform a
// conversion for us to a Zend Diactoros implementation of the PSR-7 request.
$psr = (new DiactorosFactory)->createRequest($request);
$psr = (new PsrHttpFactory(
new ServerRequestFactory,
new StreamFactory,
new UploadedFileFactory,
new ResponseFactory
))->createRequest($request);

try {
return $this->server->validateAuthenticatedRequest($psr);
Expand Down
13 changes: 11 additions & 2 deletions src/Http/Middleware/CheckClientCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
namespace Laravel\Passport\Http\Middleware;

use Closure;
use Zend\Diactoros\StreamFactory;
use Zend\Diactoros\ResponseFactory;
use Zend\Diactoros\UploadedFileFactory;
use League\OAuth2\Server\ResourceServer;
use Zend\Diactoros\ServerRequestFactory;
use Illuminate\Auth\AuthenticationException;
use Laravel\Passport\Exceptions\MissingScopeException;
use League\OAuth2\Server\Exception\OAuthServerException;
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;

class CheckClientCredentials
{
Expand Down Expand Up @@ -40,7 +44,12 @@ public function __construct(ResourceServer $server)
*/
public function handle($request, Closure $next, ...$scopes)
{
$psr = (new DiactorosFactory)->createRequest($request);
$psr = (new PsrHttpFactory(
new ServerRequestFactory,
new StreamFactory,
new UploadedFileFactory,
new ResponseFactory
))->createRequest($request);

try {
$psr = $this->server->validateAuthenticatedRequest($psr);
Expand Down
13 changes: 11 additions & 2 deletions src/Http/Middleware/CheckClientCredentialsForAnyScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
namespace Laravel\Passport\Http\Middleware;

use Closure;
use Zend\Diactoros\StreamFactory;
use Zend\Diactoros\ResponseFactory;
use Zend\Diactoros\UploadedFileFactory;
use League\OAuth2\Server\ResourceServer;
use Zend\Diactoros\ServerRequestFactory;
use Illuminate\Auth\AuthenticationException;
use Laravel\Passport\Exceptions\MissingScopeException;
use League\OAuth2\Server\Exception\OAuthServerException;
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;

class CheckClientCredentialsForAnyScope
{
Expand Down Expand Up @@ -40,7 +44,12 @@ public function __construct(ResourceServer $server)
*/
public function handle($request, Closure $next, ...$scopes)
{
$psr = (new DiactorosFactory)->createRequest($request);
$psr = (new PsrHttpFactory(
new ServerRequestFactory,
new StreamFactory,
new UploadedFileFactory,
new ResponseFactory
))->createRequest($request);

try {
$psr = $this->server->validateAuthenticatedRequest($psr);
Expand Down

0 comments on commit aadf603

Please sign in to comment.