Skip to content

Commit

Permalink
Use only one PSR7 implementation (#1330)
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Coder264 authored Aug 21, 2020
1 parent 6d4393e commit 29f137a
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 31 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
"illuminate/encryption": "^6.18.31|^7.22.4",
"illuminate/http": "^6.18.31|^7.22.4",
"illuminate/support": "^6.18.31|^7.22.4",
"laminas/laminas-diactoros": "^2.2",
"league/oauth2-server": "^8.1",
"nyholm/psr7": "^1.0",
"nyholm/psr7": "^1.3",
"phpseclib/phpseclib": "^2.0",
"symfony/psr-http-message-bridge": "^2.0"
},
Expand Down
15 changes: 6 additions & 9 deletions src/Guards/TokenGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@
use Illuminate\Cookie\CookieValuePrefix;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Http\Request;
use Laminas\Diactoros\ResponseFactory;
use Laminas\Diactoros\ServerRequestFactory;
use Laminas\Diactoros\StreamFactory;
use Laminas\Diactoros\UploadedFileFactory;
use Laravel\Passport\ClientRepository;
use Laravel\Passport\Passport;
use Laravel\Passport\PassportUserProvider;
use Laravel\Passport\TokenRepository;
use Laravel\Passport\TransientToken;
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\ResourceServer;
use Nyholm\Psr7\Factory\Psr17Factory;
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;

class TokenGuard
Expand Down Expand Up @@ -195,12 +192,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 new Diactoros implementation of this PSR-7 request.
// conversion for us to a new Nyholm implementation of this PSR-7 request.
$psr = (new PsrHttpFactory(
new ServerRequestFactory,
new StreamFactory,
new UploadedFileFactory,
new ResponseFactory
new Psr17Factory,
new Psr17Factory,
new Psr17Factory,
new Psr17Factory
))->createRequest($request);

try {
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/AccessTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Laravel\Passport\Http\Controllers;

use Laminas\Diactoros\Response as Psr7Response;
use Laravel\Passport\TokenRepository;
use Lcobucci\JWT\Parser as JwtParser;
use League\OAuth2\Server\AuthorizationServer;
use Nyholm\Psr7\Response as Psr7Response;
use Psr\Http\Message\ServerRequestInterface;

class AccessTokenController
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/ApproveAuthorizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Laravel\Passport\Http\Controllers;

use Illuminate\Http\Request;
use Laminas\Diactoros\Response as Psr7Response;
use League\OAuth2\Server\AuthorizationServer;
use Nyholm\Psr7\Response as Psr7Response;

class ApproveAuthorizationController
{
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/AuthorizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Laminas\Diactoros\Response as Psr7Response;
use Laravel\Passport\Bridge\User;
use Laravel\Passport\ClientRepository;
use Laravel\Passport\Passport;
use Laravel\Passport\TokenRepository;
use League\OAuth2\Server\AuthorizationServer;
use Nyholm\Psr7\Response as Psr7Response;
use Psr\Http\Message\ServerRequestInterface;

class AuthorizationController
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/HandlesOAuthErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Laravel\Passport\Http\Controllers;

use Laminas\Diactoros\Response as Psr7Response;
use Laravel\Passport\Exceptions\OAuthServerException;
use League\OAuth2\Server\Exception\OAuthServerException as LeagueException;
use Nyholm\Psr7\Response as Psr7Response;

trait HandlesOAuthErrors
{
Expand Down
13 changes: 5 additions & 8 deletions src/Http/Middleware/CheckCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

use Closure;
use Illuminate\Auth\AuthenticationException;
use Laminas\Diactoros\ResponseFactory;
use Laminas\Diactoros\ServerRequestFactory;
use Laminas\Diactoros\StreamFactory;
use Laminas\Diactoros\UploadedFileFactory;
use Laravel\Passport\TokenRepository;
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\ResourceServer;
use Nyholm\Psr7\Factory\Psr17Factory;
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;

abstract class CheckCredentials
Expand Down Expand Up @@ -55,10 +52,10 @@ public function __construct(ResourceServer $server, TokenRepository $repository)
public function handle($request, Closure $next, ...$scopes)
{
$psr = (new PsrHttpFactory(
new ServerRequestFactory,
new StreamFactory,
new UploadedFileFactory,
new ResponseFactory
new Psr17Factory,
new Psr17Factory,
new Psr17Factory,
new Psr17Factory
))->createRequest($request);

try {
Expand Down
13 changes: 7 additions & 6 deletions src/PersonalAccessTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Laravel\Passport;

use Laminas\Diactoros\Response;
use Laminas\Diactoros\ServerRequest;
use Lcobucci\JWT\Parser as JwtParser;
use League\OAuth2\Server\AuthorizationServer;
use Nyholm\Psr7\Response;
use Nyholm\Psr7\ServerRequest;
use Psr\Http\Message\ServerRequestInterface;

class PersonalAccessTokenFactory
{
Expand Down Expand Up @@ -89,13 +90,13 @@ public function make($userId, $name, array $scopes = [])
* @param \Laravel\Passport\Client $client
* @param mixed $userId
* @param array $scopes
* @return \Laminas\Diactoros\ServerRequest
* @return \Psr\Http\Message\ServerRequestInterface
*/
protected function createRequest($client, $userId, array $scopes)
{
$secret = Passport::$hashesClientSecrets ? $this->clients->getPersonalAccessClientSecret() : $client->secret;

return (new ServerRequest)->withParsedBody([
return (new ServerRequest('POST', 'not-important'))->withParsedBody([
'grant_type' => 'personal_access',
'client_id' => $client->id,
'client_secret' => $secret,
Expand All @@ -107,10 +108,10 @@ protected function createRequest($client, $userId, array $scopes)
/**
* Dispatch the given request to the authorization server.
*
* @param \Laminas\Diactoros\ServerRequest $request
* @param \Psr\Http\Message\ServerRequestInterface $request
* @return array
*/
protected function dispatchRequestToAuthorizationServer(ServerRequest $request)
protected function dispatchRequestToAuthorizationServer(ServerRequestInterface $request)
{
return json_decode($this->server->respondToAccessTokenRequest(
$request, new Response
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/AccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Laravel\Passport\Tests\Unit;

use Laminas\Diactoros\Response;
use Laravel\Passport\Exceptions\OAuthServerException;
use Laravel\Passport\Http\Controllers\AccessTokenController;
use Laravel\Passport\TokenRepository;
use Lcobucci\JWT\Parser;
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Exception\OAuthServerException as LeagueException;
use Mockery as m;
use Nyholm\Psr7\Response;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ApproveAuthorizationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace Laravel\Passport\Tests\Unit;

use Illuminate\Http\Request;
use Laminas\Diactoros\Response;
use Laravel\Passport\Http\Controllers\ApproveAuthorizationController;
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\RequestTypes\AuthorizationRequest;
use Mockery as m;
use Nyholm\Psr7\Response;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;

Expand Down

0 comments on commit 29f137a

Please sign in to comment.