Skip to content

Commit

Permalink
Merge branch 'release/3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbilbie committed Dec 5, 2013
2 parents e95ae97 + c6ac1de commit 9099173
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 131 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Changelog

## 3.1 (released 2013-12-05)

* No longer necessary to inject the authorisation server into a grant, the server will inject itself
* Added test for 1419ba8cdcf18dd034c8db9f7de86a2594b68605

## 3.0.1 (released 2013-12-02)

* Forgot to tell TravisCI from testing PHP 5.3


## 3.0 (released 2013-12-02)

* Fixed spelling of Implicit grant class (Issue #84)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "league/oauth2-server",
"description": "A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.",
"version": "3.0.1",
"version": "3.1",
"homepage": "https://github.com/php-loep/oauth2-server",
"license": "MIT",
"require": {
Expand Down
4 changes: 4 additions & 0 deletions src/League/OAuth2/Server/Authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ public function addGrantType(GrantTypeInterface $grantType, $identifier = null)
if (is_null($identifier)) {
$identifier = $grantType->getIdentifier();
}

// Inject server into grant
$grantType->setAuthorizationServer($this);

$this->grantTypes[$identifier] = $grantType;

if ( ! is_null($grantType->getResponseType())) {
Expand Down
10 changes: 0 additions & 10 deletions src/League/OAuth2/Server/Grant/AuthCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ class AuthCode implements GrantTypeInterface {
*/
protected $authTokenTTL = 600;

/**
* Constructor
* @param Authorization $authServer Authorization server instance
* @return void
*/
public function __construct(Authorization $authServer)
{
$this->authServer = $authServer;
}

/**
* Override the default access token expire time
* @param int $authTokenTTL
Expand Down
10 changes: 0 additions & 10 deletions src/League/OAuth2/Server/Grant/ClientCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ class ClientCredentials implements GrantTypeInterface {
*/
protected $accessTokenTTL = null;

/**
* Constructor
* @param Authorization $authServer Authorization server instance
* @return void
*/
public function __construct(Authorization $authServer)
{
$this->authServer = $authServer;
}

/**
* Return the identifier
* @return string
Expand Down
42 changes: 41 additions & 1 deletion src/League/OAuth2/Server/Grant/GrantTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,26 @@

namespace League\OAuth2\Server\Grant;

use League\OAuth2\Server\Authorization;

trait GrantTrait {

/**
* Constructor
* @param Authorization $authServer Authorization server instance
* @return void
*/
public function __construct(Authorization $authServer = null)
{
// @codeCoverageIgnoreStart
if ($authServer instanceof Authorization) {
trigger_error(
'Server is now automatically injected into grant as of v3.1 of this library',
E_USER_DEPRECATED
);
} // @codeCoverageIgnoreEnd
}

/**
* Return the identifier
* @return string
Expand All @@ -22,6 +40,17 @@ public function getIdentifier()
return $this->identifier;
}

/**
* Return the identifier
* @param string $identifier
* @return self
*/
public function setIdentifier($identifier)
{
$this->identifier = $identifier;
return $this;
}

/**
* Return the response type
* @return string
Expand All @@ -42,4 +71,15 @@ public function setAccessTokenTTL($accessTokenTTL)
return $this;
}

}
/**
* Inject the authorization server into the grant
* @param Authorization $authServer The authorization server instance
* @return self
*/
public function setAuthorizationServer(Authorization $authServer)
{
$this->authServer = $authServer;
return $this;
}

}
3 changes: 1 addition & 2 deletions src/League/OAuth2/Server/Grant/GrantTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ interface GrantTypeInterface
{
/**
* Constructor
* @param Authorization $authServer Authorization server instance
* @return void
*/
public function __construct(Authorization $authServer);
public function __construct(Authorization $authServer = null);

/**
* Complete the grant flow
Expand Down
10 changes: 0 additions & 10 deletions src/League/OAuth2/Server/Grant/Implicit.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ class Implicit implements GrantTypeInterface {
*/
protected $accessTokenTTL = null;

/**
* Constructor
* @param Authorization $authServer Authorization server instance
* @return void
*/
public function __construct(Authorization $authServer)
{
$this->authServer = $authServer;
}

/**
* Complete the client credentials grant
* @param null|array $inputParams
Expand Down
10 changes: 0 additions & 10 deletions src/League/OAuth2/Server/Grant/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ class Password implements GrantTypeInterface {
*/
protected $accessTokenTTL = null;

/**
* Constructor
* @param Authorization $authServer Authorization server instance
* @return void
*/
public function __construct(Authorization $authServer)
{
$this->authServer = $authServer;
}

/**
* Set the callback to verify a user's username and password
* @param callable $callback The callback function
Expand Down
10 changes: 0 additions & 10 deletions src/League/OAuth2/Server/Grant/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,6 @@ class RefreshToken implements GrantTypeInterface {
*/
protected $rotateRefreshTokens = false;

/**
* Constructor
* @param Authorization $authServer Authorization server instance
* @return void
*/
public function __construct(Authorization $authServer)
{
$this->authServer = $authServer;
}

/**
* Set the TTL of the refresh token
* @param int $refreshTokenTTL
Expand Down
56 changes: 36 additions & 20 deletions tests/authorization/AuthCodeGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,26 @@ private function returnDefault()
return new League\OAuth2\Server\Authorization($this->client, $this->session, $this->scope);
}

public function test_setAuthTokenTTL()
/**
* @expectedException PHPUnit_Framework_Error
*/
public function test__construct()
{
$a = $this->returnDefault();
$grant = new League\OAuth2\Server\Grant\AuthCode($a);
}

public function test_setIdentifier()
{
$grant = new League\OAuth2\Server\Grant\AuthCode();
$grant->setIdentifier('foobar');
$this->assertEquals($grant->getIdentifier(), 'foobar');
}

public function test_setAuthTokenTTL()
{
$a = $this->returnDefault();
$grant = new League\OAuth2\Server\Grant\AuthCode();
$grant->setAuthTokenTTL(30);

$reflector = new ReflectionClass($grant);
Expand All @@ -41,7 +57,7 @@ public function test_setAuthTokenTTL()
public function test_checkAuthoriseParams_noClientId()
{
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$g->checkAuthoriseParams();
}
Expand All @@ -53,7 +69,7 @@ public function test_checkAuthoriseParams_noClientId()
public function test_checkAuthoriseParams_noRedirectUri()
{
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$g->checkAuthoriseParams(array(
'client_id' => 1234
Expand All @@ -67,7 +83,7 @@ public function test_checkAuthoriseParams_noRedirectUri()
public function test_checkAuthoriseParams_noRequiredState()
{
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$a->requireStateParam(true);
$g->checkAuthoriseParams(array(
Expand All @@ -86,7 +102,7 @@ public function test_checkAuthoriseParams_badClient()
$this->client->shouldReceive('getClient')->andReturn(false);

$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$g->checkAuthoriseParams(array(
'client_id' => 1234,
Expand All @@ -108,7 +124,7 @@ public function test_checkAuthoriseParams_missingResponseType()
));

$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$g->checkAuthoriseParams(array(
'client_id' => 1234,
Expand All @@ -130,7 +146,7 @@ public function test_checkAuthoriseParams_badResponseType()
));

$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$g->checkAuthoriseParams(array(
'client_id' => 1234,
Expand All @@ -153,9 +169,9 @@ public function test_checkAuthoriseParams_missingScopes()
));

$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->requireScopeParam(true);

$g->checkAuthoriseParams(array(
Expand Down Expand Up @@ -183,9 +199,9 @@ public function test_checkAuthoriseParams_defaultScope()
));

$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->setDefaultScope('test.scope');
$a->requireScopeParam(false);

Expand Down Expand Up @@ -217,9 +233,9 @@ public function test_checkAuthoriseParams_defaultScopeArray()
));

$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->setDefaultScope(array('test.scope', 'test.scope2'));
$a->requireScopeParam(false);

Expand Down Expand Up @@ -250,9 +266,9 @@ public function test_checkAuthoriseParams_badScopes()
$this->scope->shouldReceive('getScope')->andReturn(false);

$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());

$g->checkAuthoriseParams(array(
'client_id' => 1234,
Expand All @@ -265,9 +281,9 @@ public function test_checkAuthoriseParams_badScopes()
public function test_checkAuthoriseParams_passedInput()
{
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());

$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
Expand Down Expand Up @@ -331,9 +347,9 @@ public function test_checkAuthoriseParams()
));

$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());

$_GET['client_id'] = 1234;
$_GET['redirect_uri'] = 'http://foo/redirect';
Expand Down Expand Up @@ -380,7 +396,7 @@ function test_newAuthoriseRequest()
$this->session->shouldReceive('associateAuthCodeScope')->andReturn(null);

$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);

$params = array(
Expand Down
Loading

0 comments on commit 9099173

Please sign in to comment.