Skip to content

Commit

Permalink
ensures that access_token storage is CryptoToken, even if defaults ar…
Browse files Browse the repository at this point in the history
…e set otherwise, using CryptoTokenInterface
  • Loading branch information
bshaffer committed Jan 30, 2014
1 parent 2fb46d6 commit b8ec843
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/OAuth2/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use OAuth2\GrantType\RefreshToken;
use OAuth2\GrantType\AuthorizationCode;
use OAuth2\Storage\CryptoToken as CryptoTokenStorage;
use OAuth2\Storage\CryptoTokenInterface;

/**
* Server class for OAuth2
Expand Down Expand Up @@ -428,12 +429,13 @@ protected function createDefaultTokenController()

protected function createDefaultResourceController()
{
if (!isset($this->storages['access_token'])) {
if ($this->config['use_crypto_tokens']) {
if ($this->config['use_crypto_tokens']) {
// overwrites access token storage with crypto token storage if "use_crypto_tokens" is set
if (!isset($this->storages['access_token']) || !$this->storages['access_token'] instanceof CryptoTokenInterface) {
$this->storages['access_token'] = $this->createDefaultCryptoTokenStorage();
} else {
throw new \LogicException("You must supply a storage object implementing OAuth2\Storage\AccessTokenInterface to use the resource server");
}
} elseif (!isset($this->storages['access_token'])) {
throw new \LogicException("You must supply a storage object implementing OAuth2\Storage\AccessTokenInterface or use CryptoTokens to use the resource server");
}

if (!$this->tokenType) {
Expand Down
2 changes: 1 addition & 1 deletion src/OAuth2/Storage/CryptoToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @author Brent Shaffer <bshafs at gmail dot com>
*/
class CryptoToken implements AccessTokenInterface
class CryptoToken implements CryptoTokenInterface
{
protected $publicKeyStorage;
protected $tokenStorage;
Expand Down
14 changes: 14 additions & 0 deletions src/OAuth2/Storage/CryptoTokenInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace OAuth2\Storage;

/**
* No specific methods, but allows the library to check "instanceof"
* against interface rather than class
*
* @author Brent Shaffer <bshafs at gmail dot com>
*/
interface CryptoTokenInterface extends AccessTokenInterface
{

}

0 comments on commit b8ec843

Please sign in to comment.