oauth2-server/tests/Grant/AuthCodeGrantTest.php

616 lines
23 KiB
PHP
Raw Normal View History

2014-04-06 23:44:46 +05:30
<?php
namespace LeagueTests\Grant;
use League\OAuth2\Server\Grant\AuthCodeGrant;
use League\OAuth2\Server\Grant\RefreshTokenGrant;
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;
2014-05-07 21:39:52 +05:30
class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
2014-04-06 23:44:46 +05:30
{
public function testSetAuthTokenTTL()
{
$grant = new AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$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
2014-05-07 22:00:07 +05:30
$_GET = [];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
2014-04-06 23:44:46 +05:30
$grant = new AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$server->addGrantType($grant);
2014-06-20 18:46:03 +05:30
$grant->checkAuthorizeParams();
2014-04-06 23:44:46 +05:30
}
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-05-07 22:00:07 +05:30
$_GET = [
2014-04-06 23:44:46 +05:30
'client_id' => 'testapp'
];
$grant = new AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$server->addGrantType($grant);
2014-06-20 18:46:03 +05:30
$grant->checkAuthorizeParams();
2014-04-06 23:44:46 +05:30
}
public function testCheckAuthoriseParamsMissingStateParam()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
2014-04-06 23:44:46 +05:30
2014-05-07 22:00:07 +05:30
$_GET = [
2014-04-06 23:44:46 +05:30
'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 AuthCodeGrant;
2014-05-02 21:51:53 +05:30
$server->requireStateParam(true);
2014-04-06 23:44:46 +05:30
$server->addGrantType($grant);
2014-06-20 18:46:03 +05:30
$grant->checkAuthorizeParams();
2014-04-06 23:44:46 +05:30
}
public function testCheckAuthoriseParamsMissingResponseType()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
2014-04-06 23:44:46 +05:30
2014-05-07 22:00:07 +05:30
$_GET = [
2014-04-06 23:44:46 +05:30
'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 AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$server->addGrantType($grant);
2014-06-20 18:46:03 +05:30
$grant->checkAuthorizeParams();
2014-04-06 23:44:46 +05:30
}
public function testCheckAuthoriseParamsInvalidResponseType()
{
$this->setExpectedException('League\OAuth2\Server\Exception\UnsupportedResponseTypeException');
2014-04-06 23:44:46 +05:30
2014-05-07 22:00:07 +05:30
$_GET = [
2014-04-06 23:44:46 +05:30
'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 AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$server->addGrantType($grant);
2014-06-20 18:46:03 +05:30
$grant->checkAuthorizeParams();
2014-04-06 23:44:46 +05:30
}
public function testCheckAuthoriseParamsInvalidClient()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidClientException');
2014-04-06 23:44:46 +05:30
2014-05-07 22:00:07 +05:30
$_GET = [
2014-04-06 23:44:46 +05:30
'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 AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
$clientStorage->shouldReceive('setServer');
$clientStorage->shouldReceive('get')->andReturn(null);
$server->setClientStorage($clientStorage);
$server->addGrantType($grant);
2014-06-20 18:46:03 +05:30
$grant->checkAuthorizeParams();
2014-04-06 23:44:46 +05:30
}
public function testCheckAuthoriseParamsInvalidScope()
{
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidScopeException');
2014-04-06 23:44:46 +05:30
2014-05-07 22:00:07 +05:30
$_GET = [
2014-04-06 23:44:46 +05:30
'response_type' => 'code',
'client_id' => 'testapp',
'redirect_uri' => 'http://foo/bar',
'scope' => 'foo'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
$grant = new AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$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);
2014-06-20 18:46:03 +05:30
$grant->checkAuthorizeParams();
2014-04-06 23:44:46 +05:30
}
public function testCheckAuthoriseParams()
{
2014-05-07 22:00:07 +05:30
$_GET = [
2014-04-06 23:44:46 +05:30
'response_type' => 'code',
'client_id' => 'testapp',
'redirect_uri' => 'http://foo/bar',
'scope' => 'foo'
];
2014-05-02 21:51:53 +05:30
$server = new AuthorizationServer;
$grant = new AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$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);
2014-06-20 18:46:03 +05:30
$result = $grant->checkAuthorizeParams();
2014-04-06 23:44:46 +05:30
2014-05-02 21:51:53 +05:30
$this->assertTrue($result['client'] instanceof ClientEntity);
2014-05-07 22:00:07 +05:30
$this->assertTrue($result['redirect_uri'] === $_GET['redirect_uri']);
2014-04-06 23:44:46 +05:30
$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 AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$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);
2014-06-20 18:46:03 +05:30
$grant->newAuthorizeRequest('user', 123, [
2014-04-06 23:44:46 +05:30
'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;
$grant = new AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$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;
$grant = new AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$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;
$grant = new AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$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;
$grant = new AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$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;
$grant = new AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$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;
$grant = new AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$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;
$grant = new AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$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;
$grant = new AuthCodeGrant;
2014-04-06 23:44:46 +05:30
$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;
$grant = new AuthCodeGrant;
$rtgrant = new RefreshTokenGrant;
2014-04-06 23:44:46 +05:30
$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();
}
}