oauth2-server/tests/Grant/AuthCodeTest.php

617 lines
22 KiB
PHP
Raw Normal View History

2014-04-06 23:44:46 +05:30
<?php
namespace LeagueTests\Grant;
use League\OAuth2\Server\Grant\AuthCode;
use League\OAuth2\Server\Grant\RefreshToken;
2014-05-02 19:44:12 +05:30
use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Entity\SessionEntity;
2014-05-02 21:51:53 +05:30
use League\OAuth2\Server\Entity\AuthCodeEntity;
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Exception\InvalidRequestException;
2014-04-06 23:44:46 +05:30
use Mockery as M;
class AuthCodeTest extends \PHPUnit_Framework_TestCase
{
public function testSetAuthTokenTTL()
{
$grant = new AuthCode;
$grant->setAuthTokenTTL(100);
$class = new \ReflectionClass($grant);
$property = $class->getProperty('authTokenTTL');
$property->setAccessible(true);
$this->assertEquals(100, $property->getValue($grant));
}
public function testCheckAuthoriseParamsMissingClientId()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
2014-04-06 23:44:46 +05:30
$_POST = [];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$server->addGrantType($grant);
$grant->checkAuthoriseParams();
}
public function testCheckAuthoriseParamsMissingRedirectUri()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
2014-04-06 23:44:46 +05:30
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$_POST = [
'client_id' => 'testapp'
];
$grant = new AuthCode;
$server->addGrantType($grant);
$grant->checkAuthoriseParams();
}
public function testCheckAuthoriseParamsMissingStateParam()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
2014-04-06 23:44:46 +05:30
$_POST = [
'client_id' => 'testapp',
'redirect_uri' => 'http://foo/bar'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
2014-05-02 21:51:53 +05:30
$server->requireStateParam(true);
2014-04-06 23:44:46 +05:30
$server->addGrantType($grant);
$grant->checkAuthoriseParams();
}
public function testCheckAuthoriseParamsMissingResponseType()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
2014-04-06 23:44:46 +05:30
$_POST = [
'client_id' => 'testapp',
'redirect_uri' => 'http://foo/bar'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$server->addGrantType($grant);
$grant->checkAuthoriseParams();
}
public function testCheckAuthoriseParamsInvalidResponseType()
{
$this->setExpectedException('League\OAuth2\Server\Exception\UnsupportedResponseTypeException');
2014-04-06 23:44:46 +05:30
$_POST = [
'client_id' => 'testapp',
'redirect_uri' => 'http://foo/bar',
'response_type' => 'foobar'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$server->addGrantType($grant);
$grant->checkAuthoriseParams();
}
public function testCheckAuthoriseParamsInvalidClient()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidClientException');
2014-04-06 23:44:46 +05:30
$_POST = [
'client_id' => 'testapp',
'redirect_uri' => 'http://foo/bar',
'response_type' => 'code'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
$clientStorage->shouldReceive('setServer');
$clientStorage->shouldReceive('get')->andReturn(null);
2014-05-02 21:51:53 +05:30
2014-04-06 23:44:46 +05:30
$server->setClientStorage($clientStorage);
$server->addGrantType($grant);
$grant->checkAuthoriseParams();
}
public function testCheckAuthoriseParamsInvalidScope()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidScopeException');
2014-04-06 23:44:46 +05:30
$_POST = [
'response_type' => 'code',
'client_id' => 'testapp',
'redirect_uri' => 'http://foo/bar',
'scope' => 'foo'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
$clientStorage->shouldReceive('setServer');
$clientStorage->shouldReceive('get')->andReturn(
2014-05-02 21:51:53 +05:30
(new ClientEntity($server))->setId('testapp')
2014-04-06 23:44:46 +05:30
);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('setServer');
$sessionStorage->shouldReceive('create');
$sessionStorage->shouldReceive('getScopes')->andReturn([]);
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('setServer');
$accessTokenStorage->shouldReceive('create');
$accessTokenStorage->shouldReceive('getScopes')->andReturn([]);
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
$scopeStorage->shouldReceive('setServer');
$scopeStorage->shouldReceive('get')->andReturn(null);
$server->setClientStorage($clientStorage);
$server->setScopeStorage($scopeStorage);
$server->setSessionStorage($sessionStorage);
$server->setAccessTokenStorage($accessTokenStorage);
$server->addGrantType($grant);
$grant->checkAuthoriseParams();
}
public function testCheckAuthoriseParams()
{
$_POST = [
'response_type' => 'code',
'client_id' => 'testapp',
'redirect_uri' => 'http://foo/bar',
'scope' => 'foo'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
$clientStorage->shouldReceive('setServer');
$clientStorage->shouldReceive('get')->andReturn(
2014-05-02 21:51:53 +05:30
(new ClientEntity($server))->setId('testapp')
2014-04-06 23:44:46 +05:30
);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('setServer');
$sessionStorage->shouldReceive('create')->andreturn(123);
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
2014-05-02 21:51:53 +05:30
(new ScopeEntity($server))->setId('foo')
2014-04-06 23:44:46 +05:30
]);
$sessionStorage->shouldReceive('associateScope');
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('setServer');
$accessTokenStorage->shouldReceive('create');
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
2014-05-02 21:51:53 +05:30
(new ScopeEntity($server))->setId('foo')
2014-04-06 23:44:46 +05:30
]);
$accessTokenStorage->shouldReceive('associateScope');
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
$scopeStorage->shouldReceive('setServer');
$scopeStorage->shouldReceive('get')->andReturn(
2014-05-02 21:51:53 +05:30
(new ScopeEntity($server))->setId('foo')
2014-04-06 23:44:46 +05:30
);
$server->setClientStorage($clientStorage);
$server->setScopeStorage($scopeStorage);
$server->setSessionStorage($sessionStorage);
$server->setAccessTokenStorage($accessTokenStorage);
$server->addGrantType($grant);
$result = $grant->checkAuthoriseParams();
2014-05-02 21:51:53 +05:30
$this->assertTrue($result['client'] instanceof ClientEntity);
2014-04-06 23:44:46 +05:30
$this->assertTrue($result['redirect_uri'] === $_POST['redirect_uri']);
$this->assertTrue($result['state'] === null);
$this->assertTrue($result['response_type'] === 'code');
2014-05-02 21:51:53 +05:30
$this->assertTrue($result['scopes']['foo'] instanceof ScopeEntity);
2014-04-06 23:44:46 +05:30
}
public function testNewAuthoriseRequest()
{
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
2014-05-02 21:51:53 +05:30
$client = (new ClientEntity($server))->setId('testapp');
$scope = (new ScopeEntity($server))->setId('foo');
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$server->addGrantType($grant);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('setServer');
$sessionStorage->shouldReceive('create')->andreturn(123);
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([$scope]);
$sessionStorage->shouldReceive('associateScope');
$server->setSessionStorage($sessionStorage);
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
$authCodeStorage->shouldReceive('setServer');
$authCodeStorage->shouldReceive('get');
$authCodeStorage->shouldReceive('create');
$authCodeStorage->shouldReceive('associateScope');
$server->setAuthCodeStorage($authCodeStorage);
$grant->newAuthoriseRequest('user', 123, [
'client' => $client,
'redirect_uri' => 'http://foo/bar',
'scopes' => [$scope],
'state' => 'foobar'
]);
}
public function testCompleteFlowMissingClientId()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
2014-04-06 23:44:46 +05:30
$_POST['grant_type'] = 'authorization_code';
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$server->addGrantType($grant);
$server->issueAccessToken();
}
public function testCompleteFlowMissingClientSecret()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
2014-04-06 23:44:46 +05:30
$_POST = [
'grant_type' => 'authorization_code',
'client_id' => 'testapp'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$server->addGrantType($grant);
$server->issueAccessToken();
}
public function testCompleteFlowMissingRedirectUri()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
2014-04-06 23:44:46 +05:30
$_POST = [
'grant_type' => 'authorization_code',
'client_id' => 'testapp',
'client_secret' => 'foobar'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$server->addGrantType($grant);
$server->issueAccessToken();
}
public function testCompleteFlowInvalidClient()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidClientException');
2014-04-06 23:44:46 +05:30
$_POST = [
'grant_type' => 'authorization_code',
'client_id' => 'testapp',
'client_secret' => 'foobar',
'redirect_uri' => 'http://foo/bar'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
$clientStorage->shouldReceive('setServer');
$clientStorage->shouldReceive('get')->andReturn(null);
$server->setClientStorage($clientStorage);
$server->addGrantType($grant);
$server->issueAccessToken();
}
public function testCompleteFlowMissingCode()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
2014-04-06 23:44:46 +05:30
$_POST = [
'grant_type' => 'authorization_code',
'client_id' => 'testapp',
'client_secret' => 'foobar',
'redirect_uri' => 'http://foo/bar'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
$clientStorage->shouldReceive('setServer');
$clientStorage->shouldReceive('get')->andReturn(
2014-05-02 21:51:53 +05:30
(new ClientEntity($server))->setId('testapp')
2014-04-06 23:44:46 +05:30
);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('setServer');
$sessionStorage->shouldReceive('create');
$sessionStorage->shouldReceive('getScopes')->andReturn([]);
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('setServer');
$accessTokenStorage->shouldReceive('create');
$accessTokenStorage->shouldReceive('getScopes')->andReturn([]);
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
$scopeStorage->shouldReceive('setServer');
$scopeStorage->shouldReceive('get')->andReturn(null);
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
$authCodeStorage->shouldReceive('setServer');
$authCodeStorage->shouldReceive('get');
$server->setClientStorage($clientStorage);
$server->setScopeStorage($scopeStorage);
$server->setSessionStorage($sessionStorage);
$server->setAccessTokenStorage($accessTokenStorage);
$server->setAuthCodeStorage($authCodeStorage);
$server->addGrantType($grant);
$server->issueAccessToken();
}
public function testCompleteFlowInvalidCode()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
2014-04-06 23:44:46 +05:30
$_POST = [
'grant_type' => 'authorization_code',
'client_id' => 'testapp',
'client_secret' => 'foobar',
'redirect_uri' => 'http://foo/bar',
'code' => 'foobar'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
$clientStorage->shouldReceive('setServer');
$clientStorage->shouldReceive('get')->andReturn(
2014-05-02 21:51:53 +05:30
(new ClientEntity($server))->setId('testapp')
2014-04-06 23:44:46 +05:30
);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('setServer');
$sessionStorage->shouldReceive('create');
$sessionStorage->shouldReceive('getScopes')->andReturn([]);
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('setServer');
$accessTokenStorage->shouldReceive('create');
$accessTokenStorage->shouldReceive('getScopes')->andReturn([]);
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
$scopeStorage->shouldReceive('setServer');
$scopeStorage->shouldReceive('get')->andReturn(null);
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
$authCodeStorage->shouldReceive('setServer');
$authCodeStorage->shouldReceive('get');
$server->setClientStorage($clientStorage);
$server->setScopeStorage($scopeStorage);
$server->setSessionStorage($sessionStorage);
$server->setAccessTokenStorage($accessTokenStorage);
$server->setAuthCodeStorage($authCodeStorage);
$server->addGrantType($grant);
$server->issueAccessToken();
}
public function testCompleteFlowRedirectUriMismatch()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
2014-04-06 23:44:46 +05:30
$_POST = [
'grant_type' => 'authorization_code',
'client_id' => 'testapp',
'client_secret' => 'foobar',
'redirect_uri' => 'http://foo/bar',
'code' => 'foobar'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
$clientStorage->shouldReceive('setServer');
$clientStorage->shouldReceive('get')->andReturn(
2014-05-02 21:51:53 +05:30
(new ClientEntity($server))->setId('testapp')
2014-04-06 23:44:46 +05:30
);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('setServer');
$sessionStorage->shouldReceive('create');
$sessionStorage->shouldReceive('getScopes')->andReturn([]);
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('setServer');
$accessTokenStorage->shouldReceive('create');
$accessTokenStorage->shouldReceive('getScopes')->andReturn([]);
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
$scopeStorage->shouldReceive('setServer');
$scopeStorage->shouldReceive('get')->andReturn(null);
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
$authCodeStorage->shouldReceive('setServer');
$authCodeStorage->shouldReceive('get')->andReturn(
2014-05-02 21:51:53 +05:30
(new AuthCodeEntity($server))->setToken('foobar')->setRedirectUri('http://fail/face')
2014-04-06 23:44:46 +05:30
);
$server->setClientStorage($clientStorage);
$server->setScopeStorage($scopeStorage);
$server->setSessionStorage($sessionStorage);
$server->setAccessTokenStorage($accessTokenStorage);
$server->setAuthCodeStorage($authCodeStorage);
$server->addGrantType($grant);
$server->issueAccessToken();
}
public function testCompleteFlow()
{
$_POST = [
'grant_type' => 'authorization_code',
'client_id' => 'testapp',
'client_secret' => 'foobar',
'redirect_uri' => 'http://foo/bar',
'code' => 'foo'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
$clientStorage->shouldReceive('setServer');
$clientStorage->shouldReceive('getBySession')->andReturn(
2014-05-02 21:51:53 +05:30
(new ClientEntity($server))->setId('testapp')
2014-04-06 23:44:46 +05:30
);
$clientStorage->shouldReceive('get')->andReturn(
2014-05-02 21:51:53 +05:30
(new ClientEntity($server))->setId('testapp')
2014-04-06 23:44:46 +05:30
);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('setServer');
$sessionStorage->shouldReceive('create')->andreturn(123);
$sessionStorage->shouldReceive('associateScope');
$sessionStorage->shouldReceive('getByAuthCode')->andReturn(
2014-05-02 21:51:53 +05:30
(new SessionEntity($server))->setId('foobar')
2014-04-06 23:44:46 +05:30
);
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('setServer');
$accessTokenStorage->shouldReceive('create');
$accessTokenStorage->shouldReceive('associateScope');
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
2014-05-02 21:51:53 +05:30
(new ScopeEntity($server))->setId('foo')
2014-04-06 23:44:46 +05:30
]);
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
$scopeStorage->shouldReceive('setServer');
$scopeStorage->shouldReceive('get')->andReturn(
2014-05-02 21:51:53 +05:30
(new ScopeEntity($server))->setId('foo')
2014-04-06 23:44:46 +05:30
);
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
$authCodeStorage->shouldReceive('setServer');
$authCodeStorage->shouldReceive('delete');
$authCodeStorage->shouldReceive('get')->andReturn(
2014-05-02 21:51:53 +05:30
(new AuthCodeEntity($server))->setToken('foobar')->setRedirectUri('http://foo/bar')
2014-04-06 23:44:46 +05:30
);
$authCodeStorage->shouldReceive('getScopes')->andReturn([
2014-05-02 21:51:53 +05:30
(new ScopeEntity($server))->setId('foo')
2014-04-06 23:44:46 +05:30
]);
$server->setClientStorage($clientStorage);
$server->setScopeStorage($scopeStorage);
$server->setSessionStorage($sessionStorage);
$server->setAccessTokenStorage($accessTokenStorage);
$server->setAuthCodeStorage($authCodeStorage);
$server->addGrantType($grant);
$server->issueAccessToken();
}
public function testCompleteFlowWithRefreshToken()
{
$_POST = [
'grant_type' => 'authorization_code',
'client_id' => 'testapp',
'client_secret' => 'foobar',
'redirect_uri' => 'http://foo/bar',
'code' => 'foo'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCode;
$rtgrant = new RefreshToken;
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
$clientStorage->shouldReceive('setServer');
$clientStorage->shouldReceive('getBySession')->andReturn(
2014-05-02 21:51:53 +05:30
(new ClientEntity($server))->setId('testapp')
2014-04-06 23:44:46 +05:30
);
$clientStorage->shouldReceive('get')->andReturn(
2014-05-02 21:51:53 +05:30
(new ClientEntity($server))->setId('testapp')
2014-04-06 23:44:46 +05:30
);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('setServer');
$sessionStorage->shouldReceive('create')->andreturn(123);
$sessionStorage->shouldReceive('associateScope');
$sessionStorage->shouldReceive('getByAuthCode')->andReturn(
2014-05-02 21:51:53 +05:30
(new SessionEntity($server))->setId('foobar')
2014-04-06 23:44:46 +05:30
);
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('setServer');
$accessTokenStorage->shouldReceive('create');
$accessTokenStorage->shouldReceive('associateScope');
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
2014-05-02 21:51:53 +05:30
(new ScopeEntity($server))->setId('foo')
2014-04-06 23:44:46 +05:30
]);
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
$scopeStorage->shouldReceive('setServer');
$scopeStorage->shouldReceive('get')->andReturn(
2014-05-02 21:51:53 +05:30
(new ScopeEntity($server))->setId('foo')
2014-04-06 23:44:46 +05:30
);
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
$authCodeStorage->shouldReceive('setServer');
$authCodeStorage->shouldReceive('delete');
$authCodeStorage->shouldReceive('get')->andReturn(
2014-05-02 21:51:53 +05:30
(new AuthCodeEntity($server))->setToken('foobar')->setRedirectUri('http://foo/bar')
2014-04-06 23:44:46 +05:30
);
$authCodeStorage->shouldReceive('getScopes')->andReturn([
2014-05-02 21:51:53 +05:30
(new ScopeEntity($server))->setId('foo')
2014-04-06 23:44:46 +05:30
]);
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
$refreshTokenStorage->shouldReceive('setServer');
$refreshTokenStorage->shouldReceive('create');
$refreshTokenStorage->shouldReceive('associateScope');
$server->setClientStorage($clientStorage);
$server->setScopeStorage($scopeStorage);
$server->setSessionStorage($sessionStorage);
$server->setAccessTokenStorage($accessTokenStorage);
$server->setAuthCodeStorage($authCodeStorage);
$server->setRefreshTokenStorage($refreshTokenStorage);
$server->addGrantType($grant);
$server->addGrantType($rtgrant);
$server->issueAccessToken();
}
}