mirror of
				https://github.com/elyby/oauth2-server.git
				synced 2025-05-31 14:12:07 +05:30 
			
		
		
		
	Use __toString() for access token
This commit is contained in:
		@@ -3,6 +3,7 @@
 | 
			
		||||
namespace LeagueTests\Grant;
 | 
			
		||||
 | 
			
		||||
use League\Event\Emitter;
 | 
			
		||||
use League\OAuth2\Server\CryptKey;
 | 
			
		||||
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
 | 
			
		||||
use League\OAuth2\Server\Entities\AuthCodeEntityInterface;
 | 
			
		||||
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
 | 
			
		||||
@@ -353,6 +354,7 @@ class AbstractGrantTest extends TestCase
 | 
			
		||||
 | 
			
		||||
        /** @var AbstractGrant $grantMock */
 | 
			
		||||
        $grantMock = $this->getMockForAbstractClass(AbstractGrant::class);
 | 
			
		||||
        $grantMock->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
        $grantMock->setAccessTokenRepository($accessTokenRepoMock);
 | 
			
		||||
 | 
			
		||||
        $abstractGrantReflection = new \ReflectionClass($grantMock);
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
namespace LeagueTests\Grant;
 | 
			
		||||
 | 
			
		||||
use League\OAuth2\Server\CryptKey;
 | 
			
		||||
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
 | 
			
		||||
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
 | 
			
		||||
use League\OAuth2\Server\Exception\OAuthServerException;
 | 
			
		||||
@@ -40,7 +41,7 @@ class AuthCodeGrantTest extends TestCase
 | 
			
		||||
 | 
			
		||||
    public function setUp()
 | 
			
		||||
    {
 | 
			
		||||
        $this->cryptStub = new CryptTraitStub;
 | 
			
		||||
        $this->cryptStub = new CryptTraitStub();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetIdentifier()
 | 
			
		||||
@@ -608,6 +609,7 @@ class AuthCodeGrantTest extends TestCase
 | 
			
		||||
        $grant->setAccessTokenRepository($accessTokenRepositoryMock);
 | 
			
		||||
        $grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
 | 
			
		||||
        $grant->setEncryptionKey($this->cryptStub->getKey());
 | 
			
		||||
        $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $request = new ServerRequest(
 | 
			
		||||
            [],
 | 
			
		||||
@@ -676,6 +678,7 @@ class AuthCodeGrantTest extends TestCase
 | 
			
		||||
        $grant->setAccessTokenRepository($accessTokenRepositoryMock);
 | 
			
		||||
        $grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
 | 
			
		||||
        $grant->setEncryptionKey($this->cryptStub->getKey());
 | 
			
		||||
        $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $request = new ServerRequest(
 | 
			
		||||
            [],
 | 
			
		||||
@@ -747,6 +750,7 @@ class AuthCodeGrantTest extends TestCase
 | 
			
		||||
        $grant->setAccessTokenRepository($accessTokenRepositoryMock);
 | 
			
		||||
        $grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
 | 
			
		||||
        $grant->setEncryptionKey($this->cryptStub->getKey());
 | 
			
		||||
        $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $request = new ServerRequest(
 | 
			
		||||
            [],
 | 
			
		||||
@@ -1537,6 +1541,7 @@ class AuthCodeGrantTest extends TestCase
 | 
			
		||||
            new \DateInterval('PT10M')
 | 
			
		||||
        );
 | 
			
		||||
        $grant->setEncryptionKey($this->cryptStub->getKey());
 | 
			
		||||
        $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $this->assertInstanceOf(RedirectResponse::class, $grant->completeAuthorizationRequest($authRequest));
 | 
			
		||||
    }
 | 
			
		||||
@@ -1624,6 +1629,7 @@ class AuthCodeGrantTest extends TestCase
 | 
			
		||||
        $grant->setAccessTokenRepository($accessTokenRepositoryMock);
 | 
			
		||||
        $grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
 | 
			
		||||
        $grant->setEncryptionKey($this->cryptStub->getKey());
 | 
			
		||||
        $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $request = new ServerRequest(
 | 
			
		||||
            [],
 | 
			
		||||
@@ -1695,6 +1701,7 @@ class AuthCodeGrantTest extends TestCase
 | 
			
		||||
        $grant->setAccessTokenRepository($accessTokenRepositoryMock);
 | 
			
		||||
        $grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
 | 
			
		||||
        $grant->setEncryptionKey($this->cryptStub->getKey());
 | 
			
		||||
        $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $request = new ServerRequest(
 | 
			
		||||
            [],
 | 
			
		||||
@@ -1766,6 +1773,7 @@ class AuthCodeGrantTest extends TestCase
 | 
			
		||||
        $grant->setAccessTokenRepository($accessTokenRepositoryMock);
 | 
			
		||||
        $grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
 | 
			
		||||
        $grant->setEncryptionKey($this->cryptStub->getKey());
 | 
			
		||||
        $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $request = new ServerRequest(
 | 
			
		||||
            [],
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
namespace LeagueTests\Grant;
 | 
			
		||||
 | 
			
		||||
use League\OAuth2\Server\CryptKey;
 | 
			
		||||
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
 | 
			
		||||
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
 | 
			
		||||
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
 | 
			
		||||
@@ -44,6 +45,7 @@ class ClientCredentialsGrantTest extends TestCase
 | 
			
		||||
        $grant->setAccessTokenRepository($accessTokenRepositoryMock);
 | 
			
		||||
        $grant->setScopeRepository($scopeRepositoryMock);
 | 
			
		||||
        $grant->setDefaultScope(self::DEFAULT_SCOPE);
 | 
			
		||||
        $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $serverRequest = new ServerRequest();
 | 
			
		||||
        $serverRequest = $serverRequest->withParsedBody(
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
namespace LeagueTests\Grant;
 | 
			
		||||
 | 
			
		||||
use League\OAuth2\Server\CryptKey;
 | 
			
		||||
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
 | 
			
		||||
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
 | 
			
		||||
use League\OAuth2\Server\Grant\PasswordGrant;
 | 
			
		||||
@@ -60,6 +61,7 @@ class PasswordGrantTest extends TestCase
 | 
			
		||||
        $grant->setAccessTokenRepository($accessTokenRepositoryMock);
 | 
			
		||||
        $grant->setScopeRepository($scopeRepositoryMock);
 | 
			
		||||
        $grant->setDefaultScope(self::DEFAULT_SCOPE);
 | 
			
		||||
        $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $serverRequest = new ServerRequest();
 | 
			
		||||
        $serverRequest = $serverRequest->withParsedBody(
 | 
			
		||||
 
 | 
			
		||||
@@ -29,8 +29,9 @@ class ResourceServerMiddlewareTest extends TestCase
 | 
			
		||||
        $accessToken->setUserIdentifier(123);
 | 
			
		||||
        $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H')));
 | 
			
		||||
        $accessToken->setClient($client);
 | 
			
		||||
        $accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $token = $accessToken->convertToAccessToken(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
        $token = (string) $accessToken;
 | 
			
		||||
 | 
			
		||||
        $request = new ServerRequest();
 | 
			
		||||
        $request = $request->withHeader('authorization', sprintf('Bearer %s', $token));
 | 
			
		||||
@@ -64,8 +65,9 @@ class ResourceServerMiddlewareTest extends TestCase
 | 
			
		||||
        $accessToken->setUserIdentifier(123);
 | 
			
		||||
        $accessToken->setExpiryDateTime((new \DateTime())->sub(new \DateInterval('PT1H')));
 | 
			
		||||
        $accessToken->setClient($client);
 | 
			
		||||
        $accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $token = $accessToken->convertToAccessToken(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
        $token = (string) $accessToken;
 | 
			
		||||
 | 
			
		||||
        $request = new ServerRequest();
 | 
			
		||||
        $request = $request->withHeader('authorization', sprintf('Bearer %s', $token));
 | 
			
		||||
 
 | 
			
		||||
@@ -35,6 +35,7 @@ class BearerResponseTypeTest extends TestCase
 | 
			
		||||
        $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H')));
 | 
			
		||||
        $accessToken->setClient($client);
 | 
			
		||||
        $accessToken->addScope($scope);
 | 
			
		||||
        $accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $refreshToken = new RefreshTokenEntity();
 | 
			
		||||
        $refreshToken->setIdentifier('abcdef');
 | 
			
		||||
@@ -77,6 +78,7 @@ class BearerResponseTypeTest extends TestCase
 | 
			
		||||
        $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H')));
 | 
			
		||||
        $accessToken->setClient($client);
 | 
			
		||||
        $accessToken->addScope($scope);
 | 
			
		||||
        $accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $refreshToken = new RefreshTokenEntity();
 | 
			
		||||
        $refreshToken->setIdentifier('abcdef');
 | 
			
		||||
@@ -119,6 +121,7 @@ class BearerResponseTypeTest extends TestCase
 | 
			
		||||
        $accessToken->setUserIdentifier(123);
 | 
			
		||||
        $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H')));
 | 
			
		||||
        $accessToken->setClient($client);
 | 
			
		||||
        $accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $refreshToken = new RefreshTokenEntity();
 | 
			
		||||
        $refreshToken->setIdentifier('abcdef');
 | 
			
		||||
@@ -164,6 +167,7 @@ class BearerResponseTypeTest extends TestCase
 | 
			
		||||
        $accessToken->setUserIdentifier(123);
 | 
			
		||||
        $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H')));
 | 
			
		||||
        $accessToken->setClient($client);
 | 
			
		||||
        $accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $refreshToken = new RefreshTokenEntity();
 | 
			
		||||
        $refreshToken->setIdentifier('abcdef');
 | 
			
		||||
@@ -206,6 +210,7 @@ class BearerResponseTypeTest extends TestCase
 | 
			
		||||
        $accessToken->setUserIdentifier(123);
 | 
			
		||||
        $accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H')));
 | 
			
		||||
        $accessToken->setClient($client);
 | 
			
		||||
        $accessToken->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
 | 
			
		||||
 | 
			
		||||
        $refreshToken = new RefreshTokenEntity();
 | 
			
		||||
        $refreshToken->setIdentifier('abcdef');
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user