mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
8cfa3dcdad | ||
|
9ec1380889 | ||
|
2af7195f06 | ||
|
8c6fd6c05a | ||
|
2df6446eb2 | ||
|
6157bd77ca | ||
|
76de634f2b | ||
|
cfada388db | ||
|
2f971dc77f | ||
|
ae7b7e9aa9 | ||
|
bed6c3287e | ||
|
f83e5a8731 | ||
|
35369038db | ||
|
6a1f927a6c | ||
|
b2c0933ee6 | ||
|
3104d13eba | ||
|
8b1f3ef193 | ||
|
1ff885cff1 | ||
|
d950797bd9 | ||
|
d6e6b8b710 | ||
|
001c15bfad | ||
|
7fbc563524 | ||
|
0d949d53f3 | ||
|
d071cd112a | ||
|
4c1cd04a24 | ||
|
30162c8899 | ||
|
b21aac0ab2 |
@@ -6,9 +6,8 @@ php:
|
|||||||
- 5.6
|
- 5.6
|
||||||
- hhvm
|
- hhvm
|
||||||
|
|
||||||
before_script:
|
install:
|
||||||
- travis_retry composer self-update
|
- travis_retry composer install --no-interaction --prefer-source
|
||||||
- travis_retry composer install --no-interaction --prefer-source --dev
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- mkdir -p build/logs
|
- mkdir -p build/logs
|
||||||
@@ -16,4 +15,4 @@ script:
|
|||||||
|
|
||||||
after_script:
|
after_script:
|
||||||
- wget https://scrutinizer-ci.com/ocular.phar
|
- wget https://scrutinizer-ci.com/ocular.phar
|
||||||
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
|
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
|
||||||
|
18
CHANGELOG.md
18
CHANGELOG.md
@@ -1,5 +1,23 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 4.0.3 (released 2014-12-02)
|
||||||
|
|
||||||
|
* Fix bad type hintings (Issue #267)
|
||||||
|
* Do not forget to set the expire time (Issue #268)
|
||||||
|
|
||||||
|
## 4.0.2 (released 2014-11-21)
|
||||||
|
|
||||||
|
* Improved interfaces (Issue #255)
|
||||||
|
* Learnt how to spell delimiter and so `getScopeDelimiter()` and `setScopeDelimiter()` methods have been renamed
|
||||||
|
* Docblock improvements (Issue #254)
|
||||||
|
|
||||||
|
## 4.0.1 (released 2014-11-09)
|
||||||
|
|
||||||
|
* Alias the master branch in composer.json (Issue #243)
|
||||||
|
* Numerous PHP CodeSniffer fixes (Issue #244)
|
||||||
|
* .travis.yml update (Issue #245)
|
||||||
|
* The getAccessToken method should return an AccessTokenEntity object instead of a string in ResourceServer.php (#246)
|
||||||
|
|
||||||
## 4.0.0 (released 2014-11-08)
|
## 4.0.0 (released 2014-11-08)
|
||||||
|
|
||||||
* Complete rewrite
|
* Complete rewrite
|
||||||
|
@@ -55,10 +55,5 @@
|
|||||||
"psr-4": {
|
"psr-4": {
|
||||||
"LeagueTests\\": "tests/unit/"
|
"LeagueTests\\": "tests/unit/"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"extra": {
|
|
||||||
"branch-alias": {
|
|
||||||
"dev-develop": "4.0.x-dev"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,16 +2,14 @@
|
|||||||
|
|
||||||
namespace RelationalExample\Storage;
|
namespace RelationalExample\Storage;
|
||||||
|
|
||||||
use League\OAuth2\Server\Storage\AccessTokenInterface;
|
|
||||||
use League\OAuth2\Server\Storage\Adapter;
|
|
||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
|
||||||
use League\OAuth2\Server\Entity\AbstractTokenEntity;
|
|
||||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
|
||||||
|
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
use League\OAuth2\Server\Entity\AbstractTokenEntity;
|
||||||
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
|
use League\OAuth2\Server\Storage\AbstractStorage;
|
||||||
|
use League\OAuth2\Server\Storage\AccessTokenInterface;
|
||||||
|
|
||||||
class AccessTokenStorage extends Adapter implements AccessTokenInterface
|
class AccessTokenStorage extends AbstractStorage implements AccessTokenInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -36,7 +34,7 @@ class AccessTokenStorage extends Adapter implements AccessTokenInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getScopes(AbstractTokenEntity $token)
|
public function getScopes(AccessTokenEntity $token)
|
||||||
{
|
{
|
||||||
$result = Capsule::table('oauth_access_token_scopes')
|
$result = Capsule::table('oauth_access_token_scopes')
|
||||||
->select(['oauth_scopes.id', 'oauth_scopes.description'])
|
->select(['oauth_scopes.id', 'oauth_scopes.description'])
|
||||||
@@ -50,7 +48,7 @@ class AccessTokenStorage extends Adapter implements AccessTokenInterface
|
|||||||
foreach ($result as $row) {
|
foreach ($result as $row) {
|
||||||
$scope = (new ScopeEntity($this->server))->hydrate([
|
$scope = (new ScopeEntity($this->server))->hydrate([
|
||||||
'id' => $row['id'],
|
'id' => $row['id'],
|
||||||
'description' => $row['description']
|
'description' => $row['description'],
|
||||||
]);
|
]);
|
||||||
$response[] = $scope;
|
$response[] = $scope;
|
||||||
}
|
}
|
||||||
@@ -68,26 +66,26 @@ class AccessTokenStorage extends Adapter implements AccessTokenInterface
|
|||||||
->insert([
|
->insert([
|
||||||
'access_token' => $token,
|
'access_token' => $token,
|
||||||
'session_id' => $sessionId,
|
'session_id' => $sessionId,
|
||||||
'expire_time' => $expireTime
|
'expire_time' => $expireTime,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function associateScope(AbstractTokenEntity $token, ScopeEntity $scope)
|
public function associateScope(AccessTokenEntity $token, ScopeEntity $scope)
|
||||||
{
|
{
|
||||||
Capsule::table('oauth_access_token_scopes')
|
Capsule::table('oauth_access_token_scopes')
|
||||||
->insert([
|
->insert([
|
||||||
'access_token' => $token->getId(),
|
'access_token' => $token->getId(),
|
||||||
'scope' => $scope->getId()
|
'scope' => $scope->getId(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function delete(AbstractTokenEntity $token)
|
public function delete(AccessTokenEntity $token)
|
||||||
{
|
{
|
||||||
Capsule::table('oauth_access_token_scopes')
|
Capsule::table('oauth_access_token_scopes')
|
||||||
->where('access_token', $token->getId())
|
->where('access_token', $token->getId())
|
||||||
|
@@ -2,14 +2,13 @@
|
|||||||
|
|
||||||
namespace RelationalExample\Storage;
|
namespace RelationalExample\Storage;
|
||||||
|
|
||||||
use League\OAuth2\Server\Storage\AuthCodeInterface;
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
use League\OAuth2\Server\Storage\Adapter;
|
|
||||||
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
|
use League\OAuth2\Server\Storage\AbstractStorage;
|
||||||
|
use League\OAuth2\Server\Storage\AuthCodeInterface;
|
||||||
|
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
class AuthCodeStorage extends AbstractStorage implements AuthCodeInterface
|
||||||
|
|
||||||
class AuthCodeStorage extends Adapter implements AuthCodeInterface
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -25,6 +24,8 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface
|
|||||||
$token = new AuthCodeEntity($this->server);
|
$token = new AuthCodeEntity($this->server);
|
||||||
$token->setId($result[0]['auth_code']);
|
$token->setId($result[0]['auth_code']);
|
||||||
$token->setRedirectUri($result[0]['client_redirect_uri']);
|
$token->setRedirectUri($result[0]['client_redirect_uri']);
|
||||||
|
$token->setExpireTime($result[0]['expire_time']);
|
||||||
|
|
||||||
return $token;
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface
|
|||||||
'auth_code' => $token,
|
'auth_code' => $token,
|
||||||
'client_redirect_uri' => $redirectUri,
|
'client_redirect_uri' => $redirectUri,
|
||||||
'session_id' => $sessionId,
|
'session_id' => $sessionId,
|
||||||
'expire_time' => $expireTime
|
'expire_time' => $expireTime,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface
|
|||||||
foreach ($result as $row) {
|
foreach ($result as $row) {
|
||||||
$scope = (new ScopeEntity($this->server))->hydrate([
|
$scope = (new ScopeEntity($this->server))->hydrate([
|
||||||
'id' => $row['id'],
|
'id' => $row['id'],
|
||||||
'description' => $row['description']
|
'description' => $row['description'],
|
||||||
]);
|
]);
|
||||||
$response[] = $scope;
|
$response[] = $scope;
|
||||||
}
|
}
|
||||||
@@ -76,7 +77,7 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface
|
|||||||
Capsule::table('oauth_auth_code_scopes')
|
Capsule::table('oauth_auth_code_scopes')
|
||||||
->insert([
|
->insert([
|
||||||
'auth_code' => $token->getId(),
|
'auth_code' => $token->getId(),
|
||||||
'scope' => $scope->getId()
|
'scope' => $scope->getId(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,14 +2,13 @@
|
|||||||
|
|
||||||
namespace RelationalExample\Storage;
|
namespace RelationalExample\Storage;
|
||||||
|
|
||||||
use League\OAuth2\Server\Storage\ClientInterface;
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
use League\OAuth2\Server\Storage\Adapter;
|
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
|
use League\OAuth2\Server\Storage\AbstractStorage;
|
||||||
|
use League\OAuth2\Server\Storage\ClientInterface;
|
||||||
|
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
class ClientStorage extends AbstractStorage implements ClientInterface
|
||||||
|
|
||||||
class ClientStorage extends Adapter implements ClientInterface
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -36,7 +35,7 @@ class ClientStorage extends Adapter implements ClientInterface
|
|||||||
$client = new ClientEntity($this->server);
|
$client = new ClientEntity($this->server);
|
||||||
$client->hydrate([
|
$client->hydrate([
|
||||||
'id' => $result[0]['id'],
|
'id' => $result[0]['id'],
|
||||||
'name' => $result[0]['name']
|
'name' => $result[0]['name'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $client;
|
return $client;
|
||||||
@@ -60,7 +59,7 @@ class ClientStorage extends Adapter implements ClientInterface
|
|||||||
$client = new ClientEntity($this->server);
|
$client = new ClientEntity($this->server);
|
||||||
$client->hydrate([
|
$client->hydrate([
|
||||||
'id' => $result[0]['id'],
|
'id' => $result[0]['id'],
|
||||||
'name' => $result[0]['name']
|
'name' => $result[0]['name'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $client;
|
return $client;
|
||||||
|
@@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
namespace RelationalExample\Storage;
|
namespace RelationalExample\Storage;
|
||||||
|
|
||||||
use League\OAuth2\Server\Storage\RefreshTokenInterface;
|
|
||||||
use League\OAuth2\Server\Storage\Adapter;
|
|
||||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
|
||||||
|
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||||
|
use League\OAuth2\Server\Storage\AbstractStorage;
|
||||||
|
use League\OAuth2\Server\Storage\RefreshTokenInterface;
|
||||||
|
|
||||||
class RefreshTokenStorage extends Adapter implements RefreshTokenInterface
|
class RefreshTokenStorage extends AbstractStorage implements RefreshTokenInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -40,7 +39,7 @@ class RefreshTokenStorage extends Adapter implements RefreshTokenInterface
|
|||||||
->insert([
|
->insert([
|
||||||
'refresh_token' => $token,
|
'refresh_token' => $token,
|
||||||
'access_token' => $accessToken,
|
'access_token' => $accessToken,
|
||||||
'expire_time' => $expireTime
|
'expire_time' => $expireTime,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,5 +52,4 @@ class RefreshTokenStorage extends Adapter implements RefreshTokenInterface
|
|||||||
->where('refresh_token', $token->getId())
|
->where('refresh_token', $token->getId())
|
||||||
->delete();
|
->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
namespace RelationalExample\Storage;
|
namespace RelationalExample\Storage;
|
||||||
|
|
||||||
use League\OAuth2\Server\Storage\ScopeInterface;
|
|
||||||
use League\OAuth2\Server\Storage\Adapter;
|
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
|
||||||
|
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
|
use League\OAuth2\Server\Storage\AbstractStorage;
|
||||||
|
use League\OAuth2\Server\Storage\ScopeInterface;
|
||||||
|
|
||||||
class ScopeStorage extends Adapter implements ScopeInterface
|
class ScopeStorage extends AbstractStorage implements ScopeInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -25,7 +24,7 @@ class ScopeStorage extends Adapter implements ScopeInterface
|
|||||||
|
|
||||||
return (new ScopeEntity($this->server))->hydrate([
|
return (new ScopeEntity($this->server))->hydrate([
|
||||||
'id' => $result[0]['id'],
|
'id' => $result[0]['id'],
|
||||||
'description' => $result[0]['description']
|
'description' => $result[0]['description'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,16 +2,15 @@
|
|||||||
|
|
||||||
namespace RelationalExample\Storage;
|
namespace RelationalExample\Storage;
|
||||||
|
|
||||||
use League\OAuth2\Server\Storage\SessionInterface;
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
use League\OAuth2\Server\Storage\Adapter;
|
|
||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
|
use League\OAuth2\Server\Storage\AbstractStorage;
|
||||||
|
use League\OAuth2\Server\Storage\SessionInterface;
|
||||||
|
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
class SessionStorage extends AbstractStorage implements SessionInterface
|
||||||
|
|
||||||
class SessionStorage extends Adapter implements SessionInterface
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@@ -74,7 +73,7 @@ class SessionStorage extends Adapter implements SessionInterface
|
|||||||
foreach ($result as $scope) {
|
foreach ($result as $scope) {
|
||||||
$scopes[] = (new ScopeEntity($this->server))->hydrate([
|
$scopes[] = (new ScopeEntity($this->server))->hydrate([
|
||||||
'id' => $scope['id'],
|
'id' => $scope['id'],
|
||||||
'description' => $scope['description']
|
'description' => $scope['description'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +89,7 @@ class SessionStorage extends Adapter implements SessionInterface
|
|||||||
->insertGetId([
|
->insertGetId([
|
||||||
'owner_type' => $ownerType,
|
'owner_type' => $ownerType,
|
||||||
'owner_id' => $ownerId,
|
'owner_id' => $ownerId,
|
||||||
'client_id' => $clientId
|
'client_id' => $clientId,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $id;
|
return $id;
|
||||||
@@ -104,7 +103,7 @@ class SessionStorage extends Adapter implements SessionInterface
|
|||||||
Capsule::table('oauth_session_scopes')
|
Capsule::table('oauth_session_scopes')
|
||||||
->insert([
|
->insert([
|
||||||
'session_id' => $session->getId(),
|
'session_id' => $session->getId(),
|
||||||
'scope' => $scope->getId()
|
'scope' => $scope->getId(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,19 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
use \Orno\Http\Request;
|
|
||||||
use \Orno\Http\Response;
|
use League\OAuth2\Server\ResourceServer;
|
||||||
use \Orno\Http\JsonResponse;
|
use Orno\Http\Exception\NotFoundException;
|
||||||
use \Orno\Http\Exception\NotFoundException;
|
use Orno\Http\Request;
|
||||||
use \League\OAuth2\Server\ResourceServer;
|
use Orno\Http\Response;
|
||||||
use \RelationalExample\Storage;
|
use RelationalExample\Model;
|
||||||
use \RelationalExample\Model;
|
use RelationalExample\Storage;
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
||||||
use \League\Event\Emitter;
|
|
||||||
|
|
||||||
include __DIR__.'/vendor/autoload.php';
|
include __DIR__.'/vendor/autoload.php';
|
||||||
|
|
||||||
// Routing setup
|
// Routing setup
|
||||||
$request = (new Request)->createFromGlobals();
|
$request = (new Request())->createFromGlobals();
|
||||||
$router = new \Orno\Route\RouteCollection;
|
$router = new \Orno\Route\RouteCollection();
|
||||||
$router->setStrategy(\Orno\Route\RouteStrategyInterface::RESTFUL_STRATEGY);
|
$router->setStrategy(\Orno\Route\RouteStrategyInterface::RESTFUL_STRATEGY);
|
||||||
|
|
||||||
// Set up the OAuth 2.0 resource server
|
// Set up the OAuth 2.0 resource server
|
||||||
@@ -30,8 +28,8 @@ $server = new ResourceServer(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Routing setup
|
// Routing setup
|
||||||
$request = (new Request)->createFromGlobals();
|
$request = (new Request())->createFromGlobals();
|
||||||
$router = new \Orno\Route\RouteCollection;
|
$router = new \Orno\Route\RouteCollection();
|
||||||
|
|
||||||
// GET /tokeninfo
|
// GET /tokeninfo
|
||||||
$router->get('/tokeninfo', function (Request $request) use ($server) {
|
$router->get('/tokeninfo', function (Request $request) use ($server) {
|
||||||
@@ -41,7 +39,7 @@ $router->get('/tokeninfo', function (Request $request) use ($server) {
|
|||||||
'owner_type' => $server->getOwnerType(),
|
'owner_type' => $server->getOwnerType(),
|
||||||
'access_token' => $server->getAccessToken(),
|
'access_token' => $server->getAccessToken(),
|
||||||
'client_id' => $server->getClientId(),
|
'client_id' => $server->getClientId(),
|
||||||
'scopes' => $server->getScopes()
|
'scopes' => $server->getScopes(),
|
||||||
];
|
];
|
||||||
|
|
||||||
return new Response(json_encode($token));
|
return new Response(json_encode($token));
|
||||||
@@ -58,7 +56,7 @@ $router->get('/users', function (Request $request) use ($server) {
|
|||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
$user = [
|
$user = [
|
||||||
'username' => $result['username'],
|
'username' => $result['username'],
|
||||||
'name' => $result['name']
|
'name' => $result['name'],
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($server->hasScope('email')) {
|
if ($server->hasScope('email')) {
|
||||||
@@ -86,7 +84,7 @@ $router->get('/users/{username}', function (Request $request, $args) use ($serve
|
|||||||
|
|
||||||
$user = [
|
$user = [
|
||||||
'username' => $result[0]['username'],
|
'username' => $result[0]['username'],
|
||||||
'name' => $result[0]['name']
|
'name' => $result[0]['name'],
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($server->hasScope('email')) {
|
if ($server->hasScope('email')) {
|
||||||
@@ -103,7 +101,6 @@ $router->get('/users/{username}', function (Request $request, $args) use ($serve
|
|||||||
$dispatcher = $router->getDispatcher();
|
$dispatcher = $router->getDispatcher();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Check that access token is present
|
// Check that access token is present
|
||||||
$server->isValidRequest(false);
|
$server->isValidRequest(false);
|
||||||
|
|
||||||
@@ -112,34 +109,25 @@ try {
|
|||||||
$request->getMethod(),
|
$request->getMethod(),
|
||||||
$request->getPathInfo()
|
$request->getPathInfo()
|
||||||
);
|
);
|
||||||
|
|
||||||
} catch (\Orno\Http\Exception $e) {
|
} catch (\Orno\Http\Exception $e) {
|
||||||
|
|
||||||
// A failed response
|
// A failed response
|
||||||
$response = $e->getJsonResponse();
|
$response = $e->getJsonResponse();
|
||||||
$response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()]));
|
$response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()]));
|
||||||
|
|
||||||
} catch (\League\OAuth2\Server\Exception\OAuthException $e) {
|
} catch (\League\OAuth2\Server\Exception\OAuthException $e) {
|
||||||
|
|
||||||
$response = new Response(json_encode([
|
$response = new Response(json_encode([
|
||||||
'error' => $e->errorType,
|
'error' => $e->errorType,
|
||||||
'message' => $e->getMessage()
|
'message' => $e->getMessage(),
|
||||||
]), $e->httpStatusCode);
|
]), $e->httpStatusCode);
|
||||||
|
|
||||||
foreach ($e->getHttpHeaders() as $header) {
|
foreach ($e->getHttpHeaders() as $header) {
|
||||||
$response->headers($header);
|
$response->headers($header);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
$response = new Orno\Http\Response();
|
||||||
$response = new Orno\Http\Response;
|
|
||||||
$response->setStatusCode(500);
|
$response->setStatusCode(500);
|
||||||
$response->setContent(json_encode(['status_code' => 500, 'message' => $e->getMessage()]));
|
$response->setContent(json_encode(['status_code' => 500, 'message' => $e->getMessage()]));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
// Return the response
|
// Return the response
|
||||||
$response->headers->set('Content-type', 'application/json');
|
$response->headers->set('Content-type', 'application/json');
|
||||||
$response->send();
|
$response->send();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,29 +1,24 @@
|
|||||||
<?php
|
<?php
|
||||||
use \Orno\Http\Request;
|
|
||||||
use \Orno\Http\Response;
|
use Orno\Http\Request;
|
||||||
use \Orno\Http\JsonResponse;
|
use Orno\Http\Response;
|
||||||
use \Orno\Http\Exception\NotFoundException;
|
use RelationalExample\Storage;
|
||||||
use \League\OAuth2\Server\ResourceServer;
|
|
||||||
use \RelationalExample\Storage;
|
|
||||||
use \RelationalExample\Model;
|
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
||||||
use \League\Event\Emitter;
|
|
||||||
|
|
||||||
include __DIR__.'/vendor/autoload.php';
|
include __DIR__.'/vendor/autoload.php';
|
||||||
|
|
||||||
// Routing setup
|
// Routing setup
|
||||||
$request = (new Request)->createFromGlobals();
|
$request = (new Request())->createFromGlobals();
|
||||||
$router = new \Orno\Route\RouteCollection;
|
$router = new \Orno\Route\RouteCollection();
|
||||||
$router->setStrategy(\Orno\Route\RouteStrategyInterface::RESTFUL_STRATEGY);
|
$router->setStrategy(\Orno\Route\RouteStrategyInterface::RESTFUL_STRATEGY);
|
||||||
|
|
||||||
// Set up the OAuth 2.0 authorization server
|
// Set up the OAuth 2.0 authorization server
|
||||||
$server = new \League\OAuth2\Server\AuthorizationServer;
|
$server = new \League\OAuth2\Server\AuthorizationServer();
|
||||||
$server->setSessionStorage(new Storage\SessionStorage);
|
$server->setSessionStorage(new Storage\SessionStorage());
|
||||||
$server->setAccessTokenStorage(new Storage\AccessTokenStorage);
|
$server->setAccessTokenStorage(new Storage\AccessTokenStorage());
|
||||||
$server->setRefreshTokenStorage(new Storage\RefreshTokenStorage);
|
$server->setRefreshTokenStorage(new Storage\RefreshTokenStorage());
|
||||||
$server->setClientStorage(new Storage\ClientStorage);
|
$server->setClientStorage(new Storage\ClientStorage());
|
||||||
$server->setScopeStorage(new Storage\ScopeStorage);
|
$server->setScopeStorage(new Storage\ScopeStorage());
|
||||||
$server->setAuthCodeStorage(new Storage\AuthCodeStorage);
|
$server->setAuthCodeStorage(new Storage\AuthCodeStorage());
|
||||||
|
|
||||||
$authCodeGrant = new \League\OAuth2\Server\Grant\AuthCodeGrant();
|
$authCodeGrant = new \League\OAuth2\Server\Grant\AuthCodeGrant();
|
||||||
$server->addGrantType($authCodeGrant);
|
$server->addGrantType($authCodeGrant);
|
||||||
@@ -32,28 +27,24 @@ $refrehTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant();
|
|||||||
$server->addGrantType($refrehTokenGrant);
|
$server->addGrantType($refrehTokenGrant);
|
||||||
|
|
||||||
// Routing setup
|
// Routing setup
|
||||||
$request = (new Request)->createFromGlobals();
|
$request = (new Request())->createFromGlobals();
|
||||||
$router = new \Orno\Route\RouteCollection;
|
$router = new \Orno\Route\RouteCollection();
|
||||||
|
|
||||||
$router->get('/authorize', function (Request $request) use ($server) {
|
$router->get('/authorize', function (Request $request) use ($server) {
|
||||||
|
|
||||||
// First ensure the parameters in the query string are correct
|
// First ensure the parameters in the query string are correct
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$authParams = $server->getGrantType('authorization_code')->checkAuthorizeParams();
|
$authParams = $server->getGrantType('authorization_code')->checkAuthorizeParams();
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
return new Response(
|
return new Response(
|
||||||
json_encode([
|
json_encode([
|
||||||
'error' => $e->errorType,
|
'error' => $e->errorType,
|
||||||
'message' => $e->getMessage()
|
'message' => $e->getMessage(),
|
||||||
]),
|
]),
|
||||||
$e->httpStatusCode,
|
$e->httpStatusCode,
|
||||||
$e->getHttpHeaders()
|
$e->getHttpHeaders()
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normally at this point you would show the user a sign-in screen and ask them to authorize the requested scopes
|
// Normally at this point you would show the user a sign-in screen and ask them to authorize the requested scopes
|
||||||
@@ -78,21 +69,18 @@ $router->get('/authorize', function (Request $request) use ($server) {
|
|||||||
$router->post('/access_token', function (Request $request) use ($server) {
|
$router->post('/access_token', function (Request $request) use ($server) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$response = $server->issueAccessToken();
|
$response = $server->issueAccessToken();
|
||||||
|
|
||||||
return new Response(json_encode($response), 200);
|
return new Response(json_encode($response), 200);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
return new Response(
|
return new Response(
|
||||||
json_encode([
|
json_encode([
|
||||||
'error' => $e->errorType,
|
'error' => $e->errorType,
|
||||||
'message' => $e->getMessage()
|
'message' => $e->getMessage(),
|
||||||
]),
|
]),
|
||||||
$e->httpStatusCode,
|
$e->httpStatusCode,
|
||||||
$e->getHttpHeaders()
|
$e->getHttpHeaders()
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -100,40 +88,30 @@ $router->post('/access_token', function (Request $request) use ($server) {
|
|||||||
$dispatcher = $router->getDispatcher();
|
$dispatcher = $router->getDispatcher();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// A successful response
|
// A successful response
|
||||||
$response = $dispatcher->dispatch(
|
$response = $dispatcher->dispatch(
|
||||||
$request->getMethod(),
|
$request->getMethod(),
|
||||||
$request->getPathInfo()
|
$request->getPathInfo()
|
||||||
);
|
);
|
||||||
|
|
||||||
} catch (\Orno\Http\Exception $e) {
|
} catch (\Orno\Http\Exception $e) {
|
||||||
|
|
||||||
// A failed response
|
// A failed response
|
||||||
$response = $e->getJsonResponse();
|
$response = $e->getJsonResponse();
|
||||||
$response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()]));
|
$response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()]));
|
||||||
|
|
||||||
} catch (\League\OAuth2\Server\Exception\OAuthException $e) {
|
} catch (\League\OAuth2\Server\Exception\OAuthException $e) {
|
||||||
|
|
||||||
$response = new Response(json_encode([
|
$response = new Response(json_encode([
|
||||||
'error' => $e->errorType,
|
'error' => $e->errorType,
|
||||||
'message' => $e->getMessage()
|
'message' => $e->getMessage(),
|
||||||
]), $e->httpStatusCode);
|
]), $e->httpStatusCode);
|
||||||
|
|
||||||
foreach ($e->getHttpHeaders() as $header) {
|
foreach ($e->getHttpHeaders() as $header) {
|
||||||
$response->headers($header);
|
$response->headers($header);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
$response = new Orno\Http\Response();
|
||||||
$response = new Orno\Http\Response;
|
|
||||||
$response->setStatusCode(500);
|
$response->setStatusCode(500);
|
||||||
$response->setContent(json_encode(['status_code' => 500, 'message' => $e->getMessage()]));
|
$response->setContent(json_encode(['status_code' => 500, 'message' => $e->getMessage()]));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
// Return the response
|
// Return the response
|
||||||
$response->headers->set('Content-type', 'application/json');
|
$response->headers->set('Content-type', 'application/json');
|
||||||
$response->send();
|
$response->send();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -6,13 +6,13 @@ use Illuminate\Database\Capsule\Manager as Capsule;
|
|||||||
|
|
||||||
include __DIR__.'/../vendor/autoload.php';
|
include __DIR__.'/../vendor/autoload.php';
|
||||||
|
|
||||||
$capsule = new Capsule;
|
$capsule = new Capsule();
|
||||||
|
|
||||||
$capsule->addConnection([
|
$capsule->addConnection([
|
||||||
'driver' => 'sqlite',
|
'driver' => 'sqlite',
|
||||||
'database' => __DIR__.'/oauth2.sqlite3',
|
'database' => __DIR__.'/oauth2.sqlite3',
|
||||||
'charset' => 'utf8',
|
'charset' => 'utf8',
|
||||||
'collation' => 'utf8_unicode_ci'
|
'collation' => 'utf8_unicode_ci',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$capsule->setAsGlobal();
|
$capsule->setAsGlobal();
|
||||||
|
@@ -29,7 +29,7 @@ Capsule::table('users')->insert([
|
|||||||
'password' => password_hash('whisky', PASSWORD_DEFAULT),
|
'password' => password_hash('whisky', PASSWORD_DEFAULT),
|
||||||
'name' => 'Alex Bilbie',
|
'name' => 'Alex Bilbie',
|
||||||
'email' => 'hello@alexbilbie.com',
|
'email' => 'hello@alexbilbie.com',
|
||||||
'photo' => 'https://s.gravatar.com/avatar/14902eb1dac66b8458ebbb481d80f0a3'
|
'photo' => 'https://s.gravatar.com/avatar/14902eb1dac66b8458ebbb481d80f0a3',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Capsule::table('users')->insert([
|
Capsule::table('users')->insert([
|
||||||
@@ -37,7 +37,7 @@ Capsule::table('users')->insert([
|
|||||||
'password' => password_hash('cider', PASSWORD_DEFAULT),
|
'password' => password_hash('cider', PASSWORD_DEFAULT),
|
||||||
'name' => 'Phil Sturgeon',
|
'name' => 'Phil Sturgeon',
|
||||||
'email' => 'email@philsturgeon.co.uk',
|
'email' => 'email@philsturgeon.co.uk',
|
||||||
'photo' => 'https://s.gravatar.com/avatar/14df293d6c5cd6f05996dfc606a6a951'
|
'photo' => 'https://s.gravatar.com/avatar/14df293d6c5cd6f05996dfc606a6a951',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@@ -54,7 +54,7 @@ Capsule::schema()->create('oauth_clients', function ($table) {
|
|||||||
Capsule::table('oauth_clients')->insert([
|
Capsule::table('oauth_clients')->insert([
|
||||||
'id' => 'testclient',
|
'id' => 'testclient',
|
||||||
'secret' => 'secret',
|
'secret' => 'secret',
|
||||||
'name' => 'Test Client'
|
'name' => 'Test Client',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@@ -69,7 +69,7 @@ Capsule::schema()->create('oauth_client_redirect_uris', function ($table) {
|
|||||||
|
|
||||||
Capsule::table('oauth_client_redirect_uris')->insert([
|
Capsule::table('oauth_client_redirect_uris')->insert([
|
||||||
'client_id' => 'testclient',
|
'client_id' => 'testclient',
|
||||||
'redirect_uri' => 'http://example.com/redirect'
|
'redirect_uri' => 'http://example.com/redirect',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@@ -84,17 +84,17 @@ Capsule::schema()->create('oauth_scopes', function ($table) {
|
|||||||
|
|
||||||
Capsule::table('oauth_scopes')->insert([
|
Capsule::table('oauth_scopes')->insert([
|
||||||
'id' => 'basic',
|
'id' => 'basic',
|
||||||
'description' => 'Basic details about your account'
|
'description' => 'Basic details about your account',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Capsule::table('oauth_scopes')->insert([
|
Capsule::table('oauth_scopes')->insert([
|
||||||
'id' => 'email',
|
'id' => 'email',
|
||||||
'description' => 'Your email address'
|
'description' => 'Your email address',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Capsule::table('oauth_scopes')->insert([
|
Capsule::table('oauth_scopes')->insert([
|
||||||
'id' => 'photo',
|
'id' => 'photo',
|
||||||
'description' => 'Your photo'
|
'description' => 'Your photo',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@@ -114,19 +114,19 @@ Capsule::schema()->create('oauth_sessions', function ($table) {
|
|||||||
Capsule::table('oauth_sessions')->insert([
|
Capsule::table('oauth_sessions')->insert([
|
||||||
'owner_type' => 'client',
|
'owner_type' => 'client',
|
||||||
'owner_id' => 'testclient',
|
'owner_id' => 'testclient',
|
||||||
'client_id' => 'testclient'
|
'client_id' => 'testclient',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Capsule::table('oauth_sessions')->insert([
|
Capsule::table('oauth_sessions')->insert([
|
||||||
'owner_type' => 'user',
|
'owner_type' => 'user',
|
||||||
'owner_id' => '1',
|
'owner_id' => '1',
|
||||||
'client_id' => 'testclient'
|
'client_id' => 'testclient',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Capsule::table('oauth_sessions')->insert([
|
Capsule::table('oauth_sessions')->insert([
|
||||||
'owner_type' => 'user',
|
'owner_type' => 'user',
|
||||||
'owner_id' => '2',
|
'owner_id' => '2',
|
||||||
'client_id' => 'testclient'
|
'client_id' => 'testclient',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@@ -144,19 +144,19 @@ Capsule::schema()->create('oauth_access_tokens', function ($table) {
|
|||||||
Capsule::table('oauth_access_tokens')->insert([
|
Capsule::table('oauth_access_tokens')->insert([
|
||||||
'access_token' => 'iamgod',
|
'access_token' => 'iamgod',
|
||||||
'session_id' => '1',
|
'session_id' => '1',
|
||||||
'expire_time' => time() + 86400
|
'expire_time' => time() + 86400,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Capsule::table('oauth_access_tokens')->insert([
|
Capsule::table('oauth_access_tokens')->insert([
|
||||||
'access_token' => 'iamalex',
|
'access_token' => 'iamalex',
|
||||||
'session_id' => '2',
|
'session_id' => '2',
|
||||||
'expire_time' => time() + 86400
|
'expire_time' => time() + 86400,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Capsule::table('oauth_access_tokens')->insert([
|
Capsule::table('oauth_access_tokens')->insert([
|
||||||
'access_token' => 'iamphil',
|
'access_token' => 'iamphil',
|
||||||
'session_id' => '3',
|
'session_id' => '3',
|
||||||
'expire_time' => time() + 86400
|
'expire_time' => time() + 86400,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@@ -199,27 +199,27 @@ Capsule::schema()->create('oauth_access_token_scopes', function ($table) {
|
|||||||
|
|
||||||
Capsule::table('oauth_access_token_scopes')->insert([
|
Capsule::table('oauth_access_token_scopes')->insert([
|
||||||
'access_token' => 'iamgod',
|
'access_token' => 'iamgod',
|
||||||
'scope' => 'basic'
|
'scope' => 'basic',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Capsule::table('oauth_access_token_scopes')->insert([
|
Capsule::table('oauth_access_token_scopes')->insert([
|
||||||
'access_token' => 'iamgod',
|
'access_token' => 'iamgod',
|
||||||
'scope' => 'email'
|
'scope' => 'email',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Capsule::table('oauth_access_token_scopes')->insert([
|
Capsule::table('oauth_access_token_scopes')->insert([
|
||||||
'access_token' => 'iamgod',
|
'access_token' => 'iamgod',
|
||||||
'scope' => 'photo'
|
'scope' => 'photo',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Capsule::table('oauth_access_token_scopes')->insert([
|
Capsule::table('oauth_access_token_scopes')->insert([
|
||||||
'access_token' => 'iamphil',
|
'access_token' => 'iamphil',
|
||||||
'scope' => 'email'
|
'scope' => 'email',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Capsule::table('oauth_access_token_scopes')->insert([
|
Capsule::table('oauth_access_token_scopes')->insert([
|
||||||
'access_token' => 'iamalex',
|
'access_token' => 'iamalex',
|
||||||
'scope' => 'photo'
|
'scope' => 'photo',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@@ -1,29 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
use \Orno\Http\Request;
|
|
||||||
use \Orno\Http\Response;
|
use Orno\Http\Request;
|
||||||
use \Orno\Http\JsonResponse;
|
use Orno\Http\Response;
|
||||||
use \Orno\Http\Exception\NotFoundException;
|
use RelationalExample\Model;
|
||||||
use \League\OAuth2\Server\ResourceServer;
|
use RelationalExample\Storage;
|
||||||
use \RelationalExample\Storage;
|
|
||||||
use \RelationalExample\Model;
|
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
||||||
use \League\Event\Emitter;
|
|
||||||
|
|
||||||
include __DIR__.'/vendor/autoload.php';
|
include __DIR__.'/vendor/autoload.php';
|
||||||
|
|
||||||
// Routing setup
|
// Routing setup
|
||||||
$request = (new Request)->createFromGlobals();
|
$request = (new Request())->createFromGlobals();
|
||||||
$router = new \Orno\Route\RouteCollection;
|
$router = new \Orno\Route\RouteCollection();
|
||||||
$router->setStrategy(\Orno\Route\RouteStrategyInterface::RESTFUL_STRATEGY);
|
$router->setStrategy(\Orno\Route\RouteStrategyInterface::RESTFUL_STRATEGY);
|
||||||
|
|
||||||
// Set up the OAuth 2.0 authorization server
|
// Set up the OAuth 2.0 authorization server
|
||||||
$server = new \League\OAuth2\Server\AuthorizationServer;
|
$server = new \League\OAuth2\Server\AuthorizationServer();
|
||||||
$server->setSessionStorage(new Storage\SessionStorage);
|
$server->setSessionStorage(new Storage\SessionStorage());
|
||||||
$server->setAccessTokenStorage(new Storage\AccessTokenStorage);
|
$server->setAccessTokenStorage(new Storage\AccessTokenStorage());
|
||||||
$server->setRefreshTokenStorage(new Storage\RefreshTokenStorage);
|
$server->setRefreshTokenStorage(new Storage\RefreshTokenStorage());
|
||||||
$server->setClientStorage(new Storage\ClientStorage);
|
$server->setClientStorage(new Storage\ClientStorage());
|
||||||
$server->setScopeStorage(new Storage\ScopeStorage);
|
$server->setScopeStorage(new Storage\ScopeStorage());
|
||||||
$server->setAuthCodeStorage(new Storage\AuthCodeStorage);
|
$server->setAuthCodeStorage(new Storage\AuthCodeStorage());
|
||||||
|
|
||||||
$clientCredentials = new \League\OAuth2\Server\Grant\ClientCredentialsGrant();
|
$clientCredentials = new \League\OAuth2\Server\Grant\ClientCredentialsGrant();
|
||||||
$server->addGrantType($clientCredentials);
|
$server->addGrantType($clientCredentials);
|
||||||
@@ -47,27 +43,24 @@ $refrehTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant();
|
|||||||
$server->addGrantType($refrehTokenGrant);
|
$server->addGrantType($refrehTokenGrant);
|
||||||
|
|
||||||
// Routing setup
|
// Routing setup
|
||||||
$request = (new Request)->createFromGlobals();
|
$request = (new Request())->createFromGlobals();
|
||||||
$router = new \Orno\Route\RouteCollection;
|
$router = new \Orno\Route\RouteCollection();
|
||||||
|
|
||||||
$router->post('/access_token', function (Request $request) use ($server) {
|
$router->post('/access_token', function (Request $request) use ($server) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$response = $server->issueAccessToken();
|
$response = $server->issueAccessToken();
|
||||||
|
|
||||||
return new Response(json_encode($response), 200);
|
return new Response(json_encode($response), 200);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
return new Response(
|
return new Response(
|
||||||
json_encode([
|
json_encode([
|
||||||
'error' => $e->errorType,
|
'error' => $e->errorType,
|
||||||
'message' => $e->getMessage()
|
'message' => $e->getMessage(),
|
||||||
]),
|
]),
|
||||||
$e->httpStatusCode,
|
$e->httpStatusCode,
|
||||||
$e->getHttpHeaders()
|
$e->getHttpHeaders()
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -75,40 +68,30 @@ $router->post('/access_token', function (Request $request) use ($server) {
|
|||||||
$dispatcher = $router->getDispatcher();
|
$dispatcher = $router->getDispatcher();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// A successful response
|
// A successful response
|
||||||
$response = $dispatcher->dispatch(
|
$response = $dispatcher->dispatch(
|
||||||
$request->getMethod(),
|
$request->getMethod(),
|
||||||
$request->getPathInfo()
|
$request->getPathInfo()
|
||||||
);
|
);
|
||||||
|
|
||||||
} catch (\Orno\Http\Exception $e) {
|
} catch (\Orno\Http\Exception $e) {
|
||||||
|
|
||||||
// A failed response
|
// A failed response
|
||||||
$response = $e->getJsonResponse();
|
$response = $e->getJsonResponse();
|
||||||
$response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()]));
|
$response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()]));
|
||||||
|
|
||||||
} catch (\League\OAuth2\Server\Exception\OAuthException $e) {
|
} catch (\League\OAuth2\Server\Exception\OAuthException $e) {
|
||||||
|
|
||||||
$response = new Response(json_encode([
|
$response = new Response(json_encode([
|
||||||
'error' => $e->errorType,
|
'error' => $e->errorType,
|
||||||
'message' => $e->getMessage()
|
'message' => $e->getMessage(),
|
||||||
]), $e->httpStatusCode);
|
]), $e->httpStatusCode);
|
||||||
|
|
||||||
foreach ($e->getHttpHeaders() as $header) {
|
foreach ($e->getHttpHeaders() as $header) {
|
||||||
$response->headers($header);
|
$response->headers($header);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
$response = new Orno\Http\Response();
|
||||||
$response = new Orno\Http\Response;
|
|
||||||
$response->setStatusCode(500);
|
$response->setStatusCode(500);
|
||||||
$response->setContent(json_encode(['status_code' => 500, 'message' => $e->getMessage()]));
|
$response->setContent(json_encode(['status_code' => 500, 'message' => $e->getMessage()]));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
// Return the response
|
// Return the response
|
||||||
$response->headers->set('Content-type', 'application/json');
|
$response->headers->set('Content-type', 'application/json');
|
||||||
$response->send();
|
$response->send();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -11,16 +11,15 @@
|
|||||||
|
|
||||||
namespace League\OAuth2\Server;
|
namespace League\OAuth2\Server;
|
||||||
|
|
||||||
use League\OAuth2\Server\Exception;
|
|
||||||
use League\OAuth2\Server\TokenType\TokenTypeInterface;
|
|
||||||
use League\OAuth2\Server\Storage\SessionInterface;
|
|
||||||
use League\OAuth2\Server\Storage\AccessTokenInterface;
|
|
||||||
use League\OAuth2\Server\Storage\RefreshTokenInterface;
|
|
||||||
use League\OAuth2\Server\Storage\AuthCodeInterface;
|
|
||||||
use League\OAuth2\Server\Storage\ScopeInterface;
|
|
||||||
use League\OAuth2\Server\Storage\ClientInterface;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use League\Event\Emitter;
|
use League\Event\Emitter;
|
||||||
|
use League\OAuth2\Server\Storage\AccessTokenInterface;
|
||||||
|
use League\OAuth2\Server\Storage\AuthCodeInterface;
|
||||||
|
use League\OAuth2\Server\Storage\ClientInterface;
|
||||||
|
use League\OAuth2\Server\Storage\RefreshTokenInterface;
|
||||||
|
use League\OAuth2\Server\Storage\ScopeInterface;
|
||||||
|
use League\OAuth2\Server\Storage\SessionInterface;
|
||||||
|
use League\OAuth2\Server\TokenType\TokenTypeInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth 2.0 Resource Server
|
* OAuth 2.0 Resource Server
|
||||||
@@ -98,7 +97,7 @@ abstract class AbstractServer
|
|||||||
public function setEventEmitter($emitter = null)
|
public function setEventEmitter($emitter = null)
|
||||||
{
|
{
|
||||||
if ($emitter === null) {
|
if ($emitter === null) {
|
||||||
$this->eventEmitter = new Emitter;
|
$this->eventEmitter = new Emitter();
|
||||||
} else {
|
} else {
|
||||||
$this->eventEmitter = $emitter;
|
$this->eventEmitter = $emitter;
|
||||||
}
|
}
|
||||||
@@ -189,7 +188,7 @@ abstract class AbstractServer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the refresh token storage
|
* Set the refresh token storage
|
||||||
* @param \League\OAuth2\Server\Storage\RefreshTokenInteface $storage
|
* @param \League\OAuth2\Server\Storage\RefreshTokenInterface $storage
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setRefreshTokenStorage(RefreshTokenInterface $storage)
|
public function setRefreshTokenStorage(RefreshTokenInterface $storage)
|
||||||
@@ -202,7 +201,7 @@ abstract class AbstractServer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the auth code storage
|
* Set the auth code storage
|
||||||
* @param \League\OAuth2\Server\Storage\AuthCodeInterface $authCode
|
* @param \League\OAuth2\Server\Storage\AuthCodeInterface $storage
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setAuthCodeStorage(AuthCodeInterface $storage)
|
public function setAuthCodeStorage(AuthCodeInterface $storage)
|
||||||
|
@@ -12,14 +12,7 @@
|
|||||||
namespace League\OAuth2\Server;
|
namespace League\OAuth2\Server;
|
||||||
|
|
||||||
use League\OAuth2\Server\Grant\GrantTypeInterface;
|
use League\OAuth2\Server\Grant\GrantTypeInterface;
|
||||||
use League\OAuth2\Server\Storage\ClientInterface;
|
|
||||||
use League\OAuth2\Server\Storage\AccessTokenInterface;
|
|
||||||
use League\OAuth2\Server\Storage\AuthCodeInterface;
|
|
||||||
use League\OAuth2\Server\Storage\RefreshTokenInterface;
|
|
||||||
use League\OAuth2\Server\Storage\SessionInterface;
|
|
||||||
use League\OAuth2\Server\Storage\ScopeInterface;
|
|
||||||
use League\OAuth2\Server\TokenType\Bearer;
|
use League\OAuth2\Server\TokenType\Bearer;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth 2.0 authorization server class
|
* OAuth 2.0 authorization server class
|
||||||
@@ -31,7 +24,7 @@ class AuthorizationServer extends AbstractServer
|
|||||||
* The OAuth 2 specification states it should be a space but most use a comma
|
* The OAuth 2 specification states it should be a space but most use a comma
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $scopeDelimeter = ' ';
|
protected $scopeDelimiter = ' ';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The TTL (time to live) of an access token in seconds (default: 3600)
|
* The TTL (time to live) of an access token in seconds (default: 3600)
|
||||||
@@ -76,7 +69,7 @@ class AuthorizationServer extends AbstractServer
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
// Set Bearer as the default token type
|
// Set Bearer as the default token type
|
||||||
$this->setTokenType(new Bearer);
|
$this->setTokenType(new Bearer());
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
@@ -127,7 +120,7 @@ class AuthorizationServer extends AbstractServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Require the "scope" paremter in checkAuthoriseParams()
|
* Require the "scope" parameter in checkAuthoriseParams()
|
||||||
* @param boolean $require
|
* @param boolean $require
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
@@ -150,7 +143,7 @@ class AuthorizationServer extends AbstractServer
|
|||||||
/**
|
/**
|
||||||
* Default scope to be used if none is provided and requireScopeParam() is false
|
* Default scope to be used if none is provided and requireScopeParam() is false
|
||||||
* @param string $default Name of the default scope
|
* @param string $default Name of the default scope
|
||||||
* @param self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setDefaultScope($default = null)
|
public function setDefaultScope($default = null)
|
||||||
{
|
{
|
||||||
@@ -170,8 +163,7 @@ class AuthorizationServer extends AbstractServer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Require the "state" paremter in checkAuthoriseParams()
|
* Require the "state" paremter in checkAuthoriseParams()
|
||||||
* @param boolean $require
|
* @return bool
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function stateParamRequired()
|
public function stateParamRequired()
|
||||||
{
|
{
|
||||||
@@ -181,7 +173,7 @@ class AuthorizationServer extends AbstractServer
|
|||||||
/**
|
/**
|
||||||
* Require the "state" paremter in checkAuthoriseParams()
|
* Require the "state" paremter in checkAuthoriseParams()
|
||||||
* @param boolean $require
|
* @param boolean $require
|
||||||
* @return void
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function requireStateParam($require = true)
|
public function requireStateParam($require = true)
|
||||||
{
|
{
|
||||||
@@ -191,21 +183,22 @@ class AuthorizationServer extends AbstractServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the scope delimeter
|
* Get the scope delimiter
|
||||||
* @return string The scope delimiter (default: ",")
|
* @return string The scope delimiter (default: ",")
|
||||||
*/
|
*/
|
||||||
public function getScopeDelimeter()
|
public function getScopeDelimiter()
|
||||||
{
|
{
|
||||||
return $this->scopeDelimeter;
|
return $this->scopeDelimiter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the scope delimiter
|
* Set the scope delimiter
|
||||||
* @param string $scopeDelimeter
|
* @param string $scopeDelimiter
|
||||||
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setScopeDelimeter($scopeDelimeter = ' ')
|
public function setScopeDelimiter($scopeDelimiter = ' ')
|
||||||
{
|
{
|
||||||
$this->scopeDelimeter = $scopeDelimeter;
|
$this->scopeDelimiter = $scopeDelimiter;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -222,6 +215,7 @@ class AuthorizationServer extends AbstractServer
|
|||||||
/**
|
/**
|
||||||
* Set the TTL for an access token
|
* Set the TTL for an access token
|
||||||
* @param int $accessTokenTTL The new TTL
|
* @param int $accessTokenTTL The new TTL
|
||||||
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setAccessTokenTTL($accessTokenTTL = 3600)
|
public function setAccessTokenTTL($accessTokenTTL = 3600)
|
||||||
{
|
{
|
||||||
@@ -233,6 +227,7 @@ class AuthorizationServer extends AbstractServer
|
|||||||
/**
|
/**
|
||||||
* Issue an access token
|
* Issue an access token
|
||||||
* @return array Authorise request parameters
|
* @return array Authorise request parameters
|
||||||
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function issueAccessToken()
|
public function issueAccessToken()
|
||||||
{
|
{
|
||||||
@@ -252,8 +247,9 @@ class AuthorizationServer extends AbstractServer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a grant type class
|
* Return a grant type class
|
||||||
* @param string $grantType The grant type identifer
|
* @param string $grantType The grant type identifier
|
||||||
* @return Grant\GrantTypeInterface
|
* @return Grant\GrantTypeInterface
|
||||||
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function getGrantType($grantType)
|
public function getGrantType($grantType)
|
||||||
{
|
{
|
||||||
|
@@ -11,10 +11,8 @@
|
|||||||
|
|
||||||
namespace League\OAuth2\Server\Entity;
|
namespace League\OAuth2\Server\Entity;
|
||||||
|
|
||||||
use League\OAuth2\Server\Util\SecureKey;
|
|
||||||
use League\OAuth2\Server\AbstractServer;
|
use League\OAuth2\Server\AbstractServer;
|
||||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
use League\OAuth2\Server\Util\SecureKey;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract token class
|
* Abstract token class
|
||||||
@@ -107,7 +105,7 @@ abstract class AbstractTokenEntity
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set token ID
|
* Set token ID
|
||||||
* @param string $token Token ID
|
* @param string $id Token ID
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setId($id = null)
|
public function setId($id = null)
|
||||||
@@ -170,6 +168,7 @@ abstract class AbstractTokenEntity
|
|||||||
if ($this->id === null) {
|
if ($this->id === null) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -47,7 +47,7 @@ class AccessTokenEntity extends AbstractTokenEntity
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all scopes associated with the access token
|
* Return all scopes associated with the access token
|
||||||
* @return \League\OAuth2\Server\Entity\Scope[]
|
* @return \League\OAuth2\Server\Entity\ScopeEntity[]
|
||||||
*/
|
*/
|
||||||
public function getScopes()
|
public function getScopes()
|
||||||
{
|
{
|
||||||
|
@@ -56,7 +56,7 @@ class AuthCodeEntity extends AbstractTokenEntity
|
|||||||
|
|
||||||
return $uri.http_build_query([
|
return $uri.http_build_query([
|
||||||
'code' => $this->getId(),
|
'code' => $this->getId(),
|
||||||
'state' => $state
|
'state' => $state,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ class AuthCodeEntity extends AbstractTokenEntity
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all scopes associated with the session
|
* Return all scopes associated with the session
|
||||||
* @return \League\OAuth2\Server\Entity\Scope[]
|
* @return \League\OAuth2\Server\Entity\ScopeEntity[]
|
||||||
*/
|
*/
|
||||||
public function getScopes()
|
public function getScopes()
|
||||||
{
|
{
|
||||||
|
@@ -15,7 +15,8 @@ trait EntityTrait
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Hydrate an entity with properites
|
* Hydrate an entity with properites
|
||||||
* @param array $properties
|
* @param array $properties
|
||||||
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function hydrate(array $properties)
|
public function hydrate(array $properties)
|
||||||
{
|
{
|
||||||
|
@@ -30,7 +30,7 @@ class RefreshTokenEntity extends AbstractTokenEntity
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the ID of the associated access token
|
* Set the ID of the associated access token
|
||||||
* @param string $accessToken
|
* @param string $accessTokenId
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setAccessTokenId($accessTokenId)
|
public function setAccessTokenId($accessTokenId)
|
||||||
@@ -42,7 +42,7 @@ class RefreshTokenEntity extends AbstractTokenEntity
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Associate an access token
|
* Associate an access token
|
||||||
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken
|
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessTokenEntity
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setAccessToken(AccessTokenEntity $accessTokenEntity)
|
public function setAccessToken(AccessTokenEntity $accessTokenEntity)
|
||||||
@@ -54,7 +54,7 @@ class RefreshTokenEntity extends AbstractTokenEntity
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return access token
|
* Return access token
|
||||||
* @return AccessToken
|
* @return AccessTokenEntity
|
||||||
*/
|
*/
|
||||||
public function getAccessToken()
|
public function getAccessToken()
|
||||||
{
|
{
|
||||||
|
@@ -12,8 +12,7 @@
|
|||||||
namespace League\OAuth2\Server\Entity;
|
namespace League\OAuth2\Server\Entity;
|
||||||
|
|
||||||
use League\OAuth2\Server\AbstractServer;
|
use League\OAuth2\Server\AbstractServer;
|
||||||
use League\OAuth2\Server\Event;
|
use League\OAuth2\Server\Event\SessionOwnerEvent;
|
||||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Session entity grant
|
* Session entity grant
|
||||||
@@ -137,7 +136,7 @@ class SessionEntity
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all scopes associated with the session
|
* Return all scopes associated with the session
|
||||||
* @return \League\OAuth2\Server\Entity\Scope[]
|
* @return \League\OAuth2\Server\Entity\ScopeEntity[]
|
||||||
*/
|
*/
|
||||||
public function getScopes()
|
public function getScopes()
|
||||||
{
|
{
|
||||||
@@ -153,11 +152,11 @@ class SessionEntity
|
|||||||
* @param \League\OAuth2\Server\Entity\Scope[]
|
* @param \League\OAuth2\Server\Entity\Scope[]
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function formatScopes($unformated = [])
|
private function formatScopes($unformatted = [])
|
||||||
{
|
{
|
||||||
$scopes = [];
|
$scopes = [];
|
||||||
if (is_array($unformated)) {
|
if (is_array($unformatted)) {
|
||||||
foreach ($unformated as $scope) {
|
foreach ($unformatted as $scope) {
|
||||||
if ($scope instanceof ScopeEntity) {
|
if ($scope instanceof ScopeEntity) {
|
||||||
$scopes[$scope->getId()] = $scope;
|
$scopes[$scope->getId()] = $scope;
|
||||||
}
|
}
|
||||||
@@ -229,7 +228,7 @@ class SessionEntity
|
|||||||
$this->ownerType = $type;
|
$this->ownerType = $type;
|
||||||
$this->ownerId = $id;
|
$this->ownerId = $id;
|
||||||
|
|
||||||
$this->server->getEventEmitter()->emit(new Event\SessionOwnerEvent($this));
|
$this->server->getEventEmitter()->emit(new SessionOwnerEvent($this));
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ class ClientAuthenticationFailedEvent extends AbstractEvent
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Init the event with a request
|
* Init the event with a request
|
||||||
* @param \Symfony\Component\HttpFoundation\Requesty $request
|
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||||
*/
|
*/
|
||||||
public function __construct(Request $request)
|
public function __construct(Request $request)
|
||||||
{
|
{
|
||||||
|
@@ -24,7 +24,7 @@ class UserAuthenticationFailedEvent extends AbstractEvent
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Init the event with a request
|
* Init the event with a request
|
||||||
* @param \Symfony\Component\HttpFoundation\Requesty $request
|
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||||
*/
|
*/
|
||||||
public function __construct(Request $request)
|
public function __construct(Request $request)
|
||||||
{
|
{
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace League\OAuth2\Server\Exception;
|
namespace League\OAuth2\Server\Exception;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\Util\RedirectUri;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,6 +37,7 @@ class OAuthException extends \Exception
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Throw a new exception
|
* Throw a new exception
|
||||||
|
* @param string $msg Exception Message
|
||||||
*/
|
*/
|
||||||
public function __construct($msg = 'An error occured')
|
public function __construct($msg = 'An error occured')
|
||||||
{
|
{
|
||||||
@@ -57,7 +59,7 @@ class OAuthException extends \Exception
|
|||||||
*/
|
*/
|
||||||
public function getRedirectUri()
|
public function getRedirectUri()
|
||||||
{
|
{
|
||||||
return \League\OAuth2\Server\Util\RedirectUri::make(
|
return RedirectUri::make(
|
||||||
$this->redirectUri,
|
$this->redirectUri,
|
||||||
[
|
[
|
||||||
'error' => $this->errorType,
|
'error' => $this->errorType,
|
||||||
|
@@ -12,8 +12,8 @@
|
|||||||
namespace League\OAuth2\Server\Grant;
|
namespace League\OAuth2\Server\Grant;
|
||||||
|
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
use League\OAuth2\Server\Exception;
|
use League\OAuth2\Server\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,7 +35,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback to authenticate a user's name and password
|
* Callback to authenticate a user's name and password
|
||||||
* @var function
|
* @var callable
|
||||||
*/
|
*/
|
||||||
protected $callback;
|
protected $callback;
|
||||||
|
|
||||||
@@ -52,8 +52,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
|||||||
protected $accessTokenTTL;
|
protected $accessTokenTTL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the identifier
|
* {@inheritdoc}
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getIdentifier()
|
public function getIdentifier()
|
||||||
{
|
{
|
||||||
@@ -61,9 +60,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the identifier
|
* {@inheritdoc}
|
||||||
* @param string $identifier
|
|
||||||
* @return self
|
|
||||||
*/
|
*/
|
||||||
public function setIdentifier($identifier)
|
public function setIdentifier($identifier)
|
||||||
{
|
{
|
||||||
@@ -73,8 +70,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the response type
|
* {@inheritdoc}
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getResponseType()
|
public function getResponseType()
|
||||||
{
|
{
|
||||||
@@ -107,9 +103,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inject the authorization server into the grant
|
* {@inheritdoc}
|
||||||
* @param \League\OAuth2\Server\AuthorizationServer $server The authorization server instance
|
|
||||||
* @return self
|
|
||||||
*/
|
*/
|
||||||
public function setAuthorizationServer(AuthorizationServer $server)
|
public function setAuthorizationServer(AuthorizationServer $server)
|
||||||
{
|
{
|
||||||
@@ -120,15 +114,16 @@ abstract class AbstractGrant implements GrantTypeInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a list of scopes, validate them and return an array of Scope entities
|
* Given a list of scopes, validate them and return an array of Scope entities
|
||||||
* @param string $scopeParam A string of scopes (e.g. "profile email birthday")
|
* @param string $scopeParam A string of scopes (e.g. "profile email birthday")
|
||||||
* @param \League\OAuth2\Server\Entity\ClientEntity $client Client entity
|
* @param \League\OAuth2\Server\Entity\ClientEntity $client Client entity
|
||||||
* @param string|null $redirectUri The redirect URI to return the user to
|
* @param string|null $redirectUri The redirect URI to return the user to
|
||||||
* @return \League\OAuth2\Server\Entity\ScopeEntity[]
|
* @return \League\OAuth2\Server\Entity\ScopeEntity[]
|
||||||
* @throws \League\OAuth2\Server\Exception\InvalidScopeException If scope is invalid, or no scopes passed when required
|
* @throws \League\OAuth2\Server\Exception\InvalidScopeException If scope is invalid, or no scopes passed when required
|
||||||
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function validateScopes($scopeParam = '', ClientEntity $client, $redirectUri = null)
|
public function validateScopes($scopeParam = '', ClientEntity $client, $redirectUri = null)
|
||||||
{
|
{
|
||||||
$scopesList = explode($this->server->getScopeDelimeter(), $scopeParam);
|
$scopesList = explode($this->server->getScopeDelimiter(), $scopeParam);
|
||||||
|
|
||||||
for ($i = 0; $i < count($scopesList); $i++) {
|
for ($i = 0; $i < count($scopesList); $i++) {
|
||||||
$scopesList[$i] = trim($scopesList[$i]);
|
$scopesList[$i] = trim($scopesList[$i]);
|
||||||
|
@@ -11,15 +11,14 @@
|
|||||||
|
|
||||||
namespace League\OAuth2\Server\Grant;
|
namespace League\OAuth2\Server\Grant;
|
||||||
|
|
||||||
use League\OAuth2\Server\Request;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Exception;
|
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
|
||||||
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
|
||||||
use League\OAuth2\Server\Util\SecureKey;
|
|
||||||
use League\OAuth2\Server\Event;
|
use League\OAuth2\Server\Event;
|
||||||
|
use League\OAuth2\Server\Exception;
|
||||||
|
use League\OAuth2\Server\Util\SecureKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auth code grant class
|
* Auth code grant class
|
||||||
@@ -40,7 +39,7 @@ class AuthCodeGrant extends AbstractGrant
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* AuthServer instance
|
* AuthServer instance
|
||||||
* @var AuthServer
|
* @var \League\OAuth2\Server\AuthorizationServer
|
||||||
*/
|
*/
|
||||||
protected $server = null;
|
protected $server = null;
|
||||||
|
|
||||||
@@ -70,6 +69,8 @@ class AuthCodeGrant extends AbstractGrant
|
|||||||
* Check authorize parameters
|
* Check authorize parameters
|
||||||
*
|
*
|
||||||
* @return array Authorize request parameters
|
* @return array Authorize request parameters
|
||||||
|
*
|
||||||
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function checkAuthorizeParams()
|
public function checkAuthorizeParams()
|
||||||
{
|
{
|
||||||
@@ -160,6 +161,7 @@ class AuthCodeGrant extends AbstractGrant
|
|||||||
/**
|
/**
|
||||||
* Complete the auth code grant
|
* Complete the auth code grant
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function completeFlow()
|
public function completeFlow()
|
||||||
{
|
{
|
||||||
@@ -234,7 +236,7 @@ class AuthCodeGrant extends AbstractGrant
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($session->getScopes() as $scope) {
|
foreach ($session->getScopes() as $scope) {
|
||||||
$accessToken->associateScope($scope);
|
$accessToken->associateScope($scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->server->getTokenType()->setSession($session);
|
$this->server->getTokenType()->setSession($session);
|
||||||
@@ -257,7 +259,7 @@ class AuthCodeGrant extends AbstractGrant
|
|||||||
$accessToken->setSession($session);
|
$accessToken->setSession($session);
|
||||||
$accessToken->save();
|
$accessToken->save();
|
||||||
|
|
||||||
if ($this->server->hasGrantType('refresh_token')) {
|
if (isset($refreshToken) && $this->server->hasGrantType('refresh_token')) {
|
||||||
$refreshToken->setAccessToken($accessToken);
|
$refreshToken->setAccessToken($accessToken);
|
||||||
$refreshToken->save();
|
$refreshToken->save();
|
||||||
}
|
}
|
||||||
|
@@ -14,9 +14,9 @@ namespace League\OAuth2\Server\Grant;
|
|||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
|
use League\OAuth2\Server\Event;
|
||||||
use League\OAuth2\Server\Exception;
|
use League\OAuth2\Server\Exception;
|
||||||
use League\OAuth2\Server\Util\SecureKey;
|
use League\OAuth2\Server\Util\SecureKey;
|
||||||
use League\OAuth2\Server\Event;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client credentials grant class
|
* Client credentials grant class
|
||||||
@@ -37,7 +37,7 @@ class ClientCredentialsGrant extends AbstractGrant
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* AuthServer instance
|
* AuthServer instance
|
||||||
* @var AuthServer
|
* @var \League\OAuth2\Server\AuthorizationServer
|
||||||
*/
|
*/
|
||||||
protected $server = null;
|
protected $server = null;
|
||||||
|
|
||||||
@@ -50,10 +50,11 @@ class ClientCredentialsGrant extends AbstractGrant
|
|||||||
/**
|
/**
|
||||||
* Complete the client credentials grant
|
* Complete the client credentials grant
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function completeFlow()
|
public function completeFlow()
|
||||||
{
|
{
|
||||||
// Get the required params
|
// Get the required params
|
||||||
$clientId = $this->server->getRequest()->request->get('client_id', null);
|
$clientId = $this->server->getRequest()->request->get('client_id', null);
|
||||||
if (is_null($clientId)) {
|
if (is_null($clientId)) {
|
||||||
$clientId = $this->server->getRequest()->getUser();
|
$clientId = $this->server->getRequest()->getUser();
|
||||||
@@ -99,11 +100,11 @@ class ClientCredentialsGrant extends AbstractGrant
|
|||||||
|
|
||||||
// Associate scopes with the session and access token
|
// Associate scopes with the session and access token
|
||||||
foreach ($scopes as $scope) {
|
foreach ($scopes as $scope) {
|
||||||
$session->associateScope($scope);
|
$session->associateScope($scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($session->getScopes() as $scope) {
|
foreach ($session->getScopes() as $scope) {
|
||||||
$accessToken->associateScope($scope);
|
$accessToken->associateScope($scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save everything
|
// Save everything
|
||||||
|
@@ -11,11 +11,39 @@
|
|||||||
|
|
||||||
namespace League\OAuth2\Server\Grant;
|
namespace League\OAuth2\Server\Grant;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grant type interface
|
* Grant type interface
|
||||||
*/
|
*/
|
||||||
interface GrantTypeInterface
|
interface GrantTypeInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Return the identifier
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getIdentifier();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the identifier
|
||||||
|
* @param string $identifier
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setIdentifier($identifier);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the response type
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getResponseType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject the authorization server into the grant
|
||||||
|
* @param \League\OAuth2\Server\AuthorizationServer $server The authorization server instance
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setAuthorizationServer(AuthorizationServer $server);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Complete the grant flow
|
* Complete the grant flow
|
||||||
* @return array
|
* @return array
|
||||||
|
@@ -11,13 +11,13 @@
|
|||||||
|
|
||||||
namespace League\OAuth2\Server\Grant;
|
namespace League\OAuth2\Server\Grant;
|
||||||
|
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
|
||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
|
use League\OAuth2\Server\Event;
|
||||||
use League\OAuth2\Server\Exception;
|
use League\OAuth2\Server\Exception;
|
||||||
use League\OAuth2\Server\Util\SecureKey;
|
use League\OAuth2\Server\Util\SecureKey;
|
||||||
use League\OAuth2\Server\Event;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Password grant class
|
* Password grant class
|
||||||
@@ -61,6 +61,7 @@ class PasswordGrant extends AbstractGrant
|
|||||||
/**
|
/**
|
||||||
* Return the callback function
|
* Return the callback function
|
||||||
* @return callable
|
* @return callable
|
||||||
|
* @throws
|
||||||
*/
|
*/
|
||||||
protected function getVerifyCredentialsCallback()
|
protected function getVerifyCredentialsCallback()
|
||||||
{
|
{
|
||||||
@@ -74,6 +75,7 @@ class PasswordGrant extends AbstractGrant
|
|||||||
/**
|
/**
|
||||||
* Complete the password grant
|
* Complete the password grant
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function completeFlow()
|
public function completeFlow()
|
||||||
{
|
{
|
||||||
@@ -141,11 +143,11 @@ class PasswordGrant extends AbstractGrant
|
|||||||
|
|
||||||
// Associate scopes with the session and access token
|
// Associate scopes with the session and access token
|
||||||
foreach ($scopes as $scope) {
|
foreach ($scopes as $scope) {
|
||||||
$session->associateScope($scope);
|
$session->associateScope($scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($session->getScopes() as $scope) {
|
foreach ($session->getScopes() as $scope) {
|
||||||
$accessToken->associateScope($scope);
|
$accessToken->associateScope($scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->server->getTokenType()->setSession($session);
|
$this->server->getTokenType()->setSession($session);
|
||||||
|
@@ -11,13 +11,12 @@
|
|||||||
|
|
||||||
namespace League\OAuth2\Server\Grant;
|
namespace League\OAuth2\Server\Grant;
|
||||||
|
|
||||||
use League\OAuth2\Server\Request;
|
|
||||||
use League\OAuth2\Server\Exception;
|
|
||||||
use League\OAuth2\Server\Util\SecureKey;
|
|
||||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
|
||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||||
use League\OAuth2\Server\Event;
|
use League\OAuth2\Server\Event;
|
||||||
|
use League\OAuth2\Server\Exception;
|
||||||
|
use League\OAuth2\Server\Util\SecureKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Referesh token grant
|
* Referesh token grant
|
||||||
|
@@ -11,14 +11,12 @@
|
|||||||
|
|
||||||
namespace League\OAuth2\Server;
|
namespace League\OAuth2\Server;
|
||||||
|
|
||||||
use League\OAuth2\Server\Storage\ClientInterface;
|
|
||||||
use League\OAuth2\Server\Storage\AccessTokenInterface;
|
|
||||||
use League\OAuth2\Server\Storage\SessionInterface;
|
|
||||||
use League\OAuth2\Server\Storage\ScopeInterface;
|
|
||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
|
use League\OAuth2\Server\Storage\AccessTokenInterface;
|
||||||
|
use League\OAuth2\Server\Storage\ClientInterface;
|
||||||
|
use League\OAuth2\Server\Storage\ScopeInterface;
|
||||||
|
use League\OAuth2\Server\Storage\SessionInterface;
|
||||||
use League\OAuth2\Server\TokenType\Bearer;
|
use League\OAuth2\Server\TokenType\Bearer;
|
||||||
use League\OAuth2\Server\Exception;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth 2.0 Resource Server
|
* OAuth 2.0 Resource Server
|
||||||
@@ -39,10 +37,10 @@ class ResourceServer extends AbstractServer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise the resource server
|
* Initialise the resource server
|
||||||
* @param SessionInterface $sessionStorage
|
* @param SessionInterface $sessionStorage
|
||||||
* @param AccessTokenInteface $accessTokenStorage
|
* @param AccessTokenInterface $accessTokenStorage
|
||||||
* @param ClientInterface $clientStorage
|
* @param ClientInterface $clientStorage
|
||||||
* @param ScopeInterface $scopeStorage
|
* @param ScopeInterface $scopeStorage
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@@ -57,7 +55,7 @@ class ResourceServer extends AbstractServer
|
|||||||
$this->setScopeStorage($scopeStorage);
|
$this->setScopeStorage($scopeStorage);
|
||||||
|
|
||||||
// Set Bearer as the default token type
|
// Set Bearer as the default token type
|
||||||
$this->setTokenType(new Bearer);
|
$this->setTokenType(new Bearer());
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
@@ -66,7 +64,7 @@ class ResourceServer extends AbstractServer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the query string key for the access token.
|
* Sets the query string key for the access token.
|
||||||
* @param $key The new query string key
|
* @param string $key The new query string key
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setIdKey($key)
|
public function setIdKey($key)
|
||||||
@@ -78,17 +76,21 @@ class ResourceServer extends AbstractServer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the access token
|
* Gets the access token
|
||||||
* @return string
|
* @return \League\OAuth2\Server\Entity\AccessTokenEntity
|
||||||
*/
|
*/
|
||||||
public function getAccessToken()
|
public function getAccessToken()
|
||||||
{
|
{
|
||||||
return $this->accessToken->getId();
|
return $this->accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the access token is valid or not
|
* Checks if the access token is valid or not
|
||||||
* @param $headersOnly Limit Access Token to Authorization header only
|
* @param bool $headersOnly Limit Access Token to Authorization header only
|
||||||
|
* @param AccessTokenEntity|null $accessToken Access Token
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
*
|
||||||
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function isValidRequest($headersOnly = true, $accessToken = null)
|
public function isValidRequest($headersOnly = true, $accessToken = null)
|
||||||
{
|
{
|
||||||
@@ -101,13 +103,13 @@ class ResourceServer extends AbstractServer
|
|||||||
|
|
||||||
// Ensure the access token exists
|
// Ensure the access token exists
|
||||||
if (!$this->accessToken instanceof AccessTokenEntity) {
|
if (!$this->accessToken instanceof AccessTokenEntity) {
|
||||||
throw new Exception\AccessDeniedException;
|
throw new Exception\AccessDeniedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the access token hasn't expired
|
// Check the access token hasn't expired
|
||||||
// Ensure the auth code hasn't expired
|
// Ensure the auth code hasn't expired
|
||||||
if ($this->accessToken->isExpired() === true) {
|
if ($this->accessToken->isExpired() === true) {
|
||||||
throw new Exception\AccessDeniedException;
|
throw new Exception\AccessDeniedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -115,8 +117,8 @@ class ResourceServer extends AbstractServer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads in the access token from the headers
|
* Reads in the access token from the headers
|
||||||
* @param $headersOnly Limit Access Token to Authorization header only
|
* @param bool $headersOnly Limit Access Token to Authorization header only
|
||||||
* @throws Exception\MissingAccessTokenException Thrown if there is no access token presented
|
* @throws Exception\InvalidRequestException Thrown if there is no access token presented
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function determineAccessToken($headersOnly = false)
|
public function determineAccessToken($headersOnly = false)
|
||||||
|
@@ -27,6 +27,7 @@ abstract class AbstractStorage implements StorageInterface
|
|||||||
/**
|
/**
|
||||||
* Set the server
|
* Set the server
|
||||||
* @param \League\OAuth2\Server\AbstractServer $server
|
* @param \League\OAuth2\Server\AbstractServer $server
|
||||||
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setServer(AbstractServer $server)
|
public function setServer(AbstractServer $server)
|
||||||
{
|
{
|
||||||
|
@@ -12,8 +12,6 @@
|
|||||||
namespace League\OAuth2\Server\Storage;
|
namespace League\OAuth2\Server\Storage;
|
||||||
|
|
||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\AbstractTokenEntity;
|
|
||||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,32 +28,32 @@ interface AccessTokenInterface extends StorageInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the scopes for an access token
|
* Get the scopes for an access token
|
||||||
* @param \League\OAuth2\Server\Entity\AbstractTokenEntity $token The access token
|
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token
|
||||||
* @return array Array of \League\OAuth2\Server\Entity\ScopeEntity
|
* @return array Array of \League\OAuth2\Server\Entity\ScopeEntity
|
||||||
*/
|
*/
|
||||||
public function getScopes(AbstractTokenEntity $token);
|
public function getScopes(AccessTokenEntity $token);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new access token
|
* Creates a new access token
|
||||||
* @param string $token The access token
|
* @param string $token The access token
|
||||||
* @param integer $expireTime The expire time expressed as a unix timestamp
|
* @param integer $expireTime The expire time expressed as a unix timestamp
|
||||||
* @param string|integer $sessionId The session ID
|
* @param string|integer $sessionId The session ID
|
||||||
* @return \League\OAuth2\Server\Entity\AccessToken
|
* @return \League\OAuth2\Server\Entity\AccessTokenEntity
|
||||||
*/
|
*/
|
||||||
public function create($token, $expireTime, $sessionId);
|
public function create($token, $expireTime, $sessionId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Associate a scope with an acess token
|
* Associate a scope with an acess token
|
||||||
* @param \League\OAuth2\Server\Entity\AbstractTokenEntity $token The access token
|
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token
|
||||||
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope
|
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function associateScope(AbstractTokenEntity $token, ScopeEntity $scope);
|
public function associateScope(AccessTokenEntity $token, ScopeEntity $scope);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an access token
|
* Delete an access token
|
||||||
* @param \League\OAuth2\Server\Entity\AbstractTokenEntity $token The access token to delete
|
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $token The access token to delete
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function delete(AbstractTokenEntity $token);
|
public function delete(AccessTokenEntity $token);
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ interface ClientInterface extends StorageInterface
|
|||||||
* @param string $clientSecret The client's secret (default = "null")
|
* @param string $clientSecret The client's secret (default = "null")
|
||||||
* @param string $redirectUri The client's redirect URI (default = "null")
|
* @param string $redirectUri The client's redirect URI (default = "null")
|
||||||
* @param string $grantType The grant type used (default = "null")
|
* @param string $grantType The grant type used (default = "null")
|
||||||
* @return League\OAuth2\Server\Entity\ClientEntity
|
* @return \League\OAuth2\Server\Entity\ClientEntity
|
||||||
*/
|
*/
|
||||||
public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null);
|
public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null);
|
||||||
|
|
||||||
|
@@ -13,8 +13,8 @@ namespace League\OAuth2\Server\Storage;
|
|||||||
|
|
||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Session storage interface
|
* Session storage interface
|
||||||
@@ -54,7 +54,7 @@ interface SessionInterface extends StorageInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Associate a scope with a session
|
* Associate a scope with a session
|
||||||
* @param \League\OAuth2\Server\Entity\SessionEntity $scope The scope
|
* @param \League\OAuth2\Server\Entity\SessionEntity $session The session
|
||||||
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope
|
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace League\OAuth2\Server\TokenType;
|
namespace League\OAuth2\Server\TokenType;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use League\OAuth2\Server\AbstractServer;
|
use League\OAuth2\Server\AbstractServer;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
|
|
||||||
@@ -36,29 +35,27 @@ abstract class AbstractTokenType
|
|||||||
protected $session;
|
protected $session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the server
|
* {@inheritdoc}
|
||||||
* @param \League\OAuth2\Server\AbstractServer $server
|
|
||||||
*/
|
*/
|
||||||
public function setServer(AbstractServer $server)
|
public function setServer(AbstractServer $server)
|
||||||
{
|
{
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the session entity
|
* {@inheritdoc}
|
||||||
* @param \League\OAuth2\Server\Entity\SessionEntity $session
|
|
||||||
*/
|
*/
|
||||||
public function setSession(SessionEntity $session)
|
public function setSession(SessionEntity $session)
|
||||||
{
|
{
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a key/value response pair
|
* {@inheritdoc}
|
||||||
* @param string $key
|
|
||||||
* @param mixed $value
|
|
||||||
*/
|
*/
|
||||||
public function setParam($key, $value)
|
public function setParam($key, $value)
|
||||||
{
|
{
|
||||||
@@ -66,19 +63,10 @@ abstract class AbstractTokenType
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a key from the response array
|
* {@inheritdoc}
|
||||||
* @param string $key
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public function getParam($key)
|
public function getParam($key)
|
||||||
{
|
{
|
||||||
return isset($this->response[$key]) ? $this->response[$key] : null;
|
return isset($this->response[$key]) ? $this->response[$key] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine the access token in the authorization header
|
|
||||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
abstract public function determineAccessTokenInHeader(Request $request);
|
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,7 @@ class Bearer extends AbstractTokenType implements TokenTypeInterface
|
|||||||
$return = [
|
$return = [
|
||||||
'access_token' => $this->getParam('access_token'),
|
'access_token' => $this->getParam('access_token'),
|
||||||
'token_type' => 'Bearer',
|
'token_type' => 'Bearer',
|
||||||
'expires_in' => $this->getParam('expires_in')
|
'expires_in' => $this->getParam('expires_in'),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!is_null($this->getParam('refresh_token'))) {
|
if (!is_null($this->getParam('refresh_token'))) {
|
||||||
|
@@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
namespace League\OAuth2\Server\TokenType;
|
namespace League\OAuth2\Server\TokenType;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\AbstractServer;
|
||||||
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
interface TokenTypeInterface
|
interface TokenTypeInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -18,4 +22,38 @@ interface TokenTypeInterface
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function generateResponse();
|
public function generateResponse();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the server
|
||||||
|
* @param \League\OAuth2\Server\AbstractServer $server
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setServer(AbstractServer $server);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a key/value response pair
|
||||||
|
* @param string $key
|
||||||
|
* @param mixed $value
|
||||||
|
*/
|
||||||
|
public function setParam($key, $value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a key from the response array
|
||||||
|
* @param string $key
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getParam($key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \League\OAuth2\Server\Entity\SessionEntity $session
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setSession(SessionEntity $session);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the access token in the authorization header
|
||||||
|
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function determineAccessTokenInHeader(Request $request);
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,6 @@ class DefaultAlgorithm implements KeyAlgorithmInterface
|
|||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $len);
|
return substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,7 @@ class RedirectUri
|
|||||||
* @param string $queryDelimeter The query string delimeter (default: "?")
|
* @param string $queryDelimeter The query string delimeter (default: "?")
|
||||||
* @return string The updated URI
|
* @return string The updated URI
|
||||||
*/
|
*/
|
||||||
public static function make($uri, $params = array(), $queryDelimeter = '?')
|
public static function make($uri, $params = [], $queryDelimeter = '?')
|
||||||
{
|
{
|
||||||
$uri .= (strstr($uri, $queryDelimeter) === false) ? $queryDelimeter : '&';
|
$uri .= (strstr($uri, $queryDelimeter) === false) ? $queryDelimeter : '&';
|
||||||
|
|
||||||
|
@@ -6,4 +6,4 @@ response:
|
|||||||
headers:
|
headers:
|
||||||
-
|
-
|
||||||
key: Location
|
key: Location
|
||||||
valueRegex: /http:\/\/example.com\/redirect\?code=([a-zA-Z0-9]*)/
|
valueRegex: /http:\/\/example.com\/redirect\?code=([a-zA-Z0-9]*)/
|
||||||
|
@@ -64,4 +64,4 @@ response:
|
|||||||
valueRegex: /([a-zA-Z0-9]*)/
|
valueRegex: /([a-zA-Z0-9]*)/
|
||||||
-
|
-
|
||||||
key: token_type
|
key: token_type
|
||||||
value: Bearer
|
value: Bearer
|
||||||
|
@@ -85,4 +85,4 @@ response:
|
|||||||
valueRegex: /([a-zA-Z0-9]*)/
|
valueRegex: /([a-zA-Z0-9]*)/
|
||||||
-
|
-
|
||||||
key: token_type
|
key: token_type
|
||||||
value: Bearer
|
value: Bearer
|
||||||
|
@@ -13,4 +13,4 @@ response:
|
|||||||
value: "invalid_request"
|
value: "invalid_request"
|
||||||
-
|
-
|
||||||
key: message
|
key: message
|
||||||
value: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"access token\" parameter."
|
value: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"access token\" parameter."
|
||||||
|
@@ -13,4 +13,4 @@ response:
|
|||||||
value: "access_denied"
|
value: "access_denied"
|
||||||
-
|
-
|
||||||
key: message
|
key: message
|
||||||
value: "The resource owner or authorization server denied the request."
|
value: "The resource owner or authorization server denied the request."
|
||||||
|
@@ -17,4 +17,4 @@ response:
|
|||||||
value: "access_denied"
|
value: "access_denied"
|
||||||
-
|
-
|
||||||
key: message
|
key: message
|
||||||
value: "The resource owner or authorization server denied the request."
|
value: "The resource owner or authorization server denied the request."
|
||||||
|
@@ -23,4 +23,4 @@ response:
|
|||||||
value: iamgod
|
value: iamgod
|
||||||
-
|
-
|
||||||
key: client_id
|
key: client_id
|
||||||
value: testclient
|
value: testclient
|
||||||
|
@@ -19,4 +19,4 @@ response:
|
|||||||
value: iamgod
|
value: iamgod
|
||||||
-
|
-
|
||||||
key: client_id
|
key: client_id
|
||||||
value: testclient
|
value: testclient
|
||||||
|
@@ -29,4 +29,4 @@ response:
|
|||||||
value: Phil Sturgeon
|
value: Phil Sturgeon
|
||||||
-
|
-
|
||||||
key: 1.photo
|
key: 1.photo
|
||||||
valueType: string
|
valueType: string
|
||||||
|
@@ -29,4 +29,4 @@ response:
|
|||||||
value: Phil Sturgeon
|
value: Phil Sturgeon
|
||||||
-
|
-
|
||||||
key: 1.email
|
key: 1.email
|
||||||
valueType: string
|
valueType: string
|
||||||
|
@@ -10,7 +10,7 @@ class AbstractServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$server = new StubAbstractServer();
|
$server = new StubAbstractServer();
|
||||||
$var = 0;
|
$var = 0;
|
||||||
$server->addEventListener('event.name', function() use ($var) {
|
$server->addEventListener('event.name', function () use ($var) {
|
||||||
$var++;
|
$var++;
|
||||||
$this->assertSame(1, $var);
|
$this->assertSame(1, $var);
|
||||||
});
|
});
|
||||||
@@ -18,11 +18,9 @@ class AbstractServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($server->getRequest() instanceof \Symfony\Component\HttpFoundation\Request);
|
$this->assertTrue($server->getRequest() instanceof \Symfony\Component\HttpFoundation\Request);
|
||||||
$this->assertTrue($server->getEventEmitter() instanceof \League\Event\Emitter);
|
$this->assertTrue($server->getEventEmitter() instanceof \League\Event\Emitter);
|
||||||
|
|
||||||
|
|
||||||
$server2 = new StubAbstractServer();
|
$server2 = new StubAbstractServer();
|
||||||
$server2->setRequest((new \Symfony\Component\HttpFoundation\Request));
|
$server2->setRequest((new \Symfony\Component\HttpFoundation\Request()));
|
||||||
$server2->setEventEmitter(1);
|
$server2->setEventEmitter(1);
|
||||||
$this->assertTrue($server2->getRequest() instanceof \Symfony\Component\HttpFoundation\Request);
|
$this->assertTrue($server2->getRequest() instanceof \Symfony\Component\HttpFoundation\Request);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,17 +5,17 @@ namespace LeagueTests;
|
|||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use League\OAuth2\Server\Grant\GrantTypeInterface;
|
use League\OAuth2\Server\Grant\GrantTypeInterface;
|
||||||
use League\OAuth2\Server\Storage\ScopeInterface;
|
use League\OAuth2\Server\Storage\ScopeInterface;
|
||||||
use \Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
class AuthorizationServerTest extends \PHPUnit_Framework_TestCase
|
class AuthorizationServerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testSetGet()
|
public function testSetGet()
|
||||||
{
|
{
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$server->requireScopeParam(true);
|
$server->requireScopeParam(true);
|
||||||
$server->requireStateParam(true);
|
$server->requireStateParam(true);
|
||||||
$server->setDefaultScope('foobar');
|
$server->setDefaultScope('foobar');
|
||||||
$server->setScopeDelimeter(',');
|
$server->setScopeDelimiter(',');
|
||||||
$server->setAccessTokenTTL(1);
|
$server->setAccessTokenTTL(1);
|
||||||
|
|
||||||
$grant = M::mock('League\OAuth2\Server\Grant\GrantTypeInterface');
|
$grant = M::mock('League\OAuth2\Server\Grant\GrantTypeInterface');
|
||||||
@@ -36,14 +36,14 @@ class AuthorizationServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($server->stateParamRequired());
|
$this->assertTrue($server->stateParamRequired());
|
||||||
$this->assertTrue($server->getScopeStorage() instanceof ScopeInterface);
|
$this->assertTrue($server->getScopeStorage() instanceof ScopeInterface);
|
||||||
$this->assertEquals('foobar', $server->getDefaultScope());
|
$this->assertEquals('foobar', $server->getDefaultScope());
|
||||||
$this->assertEquals(',', $server->getScopeDelimeter());
|
$this->assertEquals(',', $server->getScopeDelimiter());
|
||||||
$this->assertEquals(1, $server->getAccessTokenTTL());
|
$this->assertEquals(1, $server->getAccessTokenTTL());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInvalidGrantType()
|
public function testInvalidGrantType()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidGrantException');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidGrantException');
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$server->getGrantType('foobar');
|
$server->getGrantType('foobar');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ class AuthorizationServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$_POST['grant_type'] = 'foobar';
|
$_POST['grant_type'] = 'foobar';
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
|
|
||||||
$this->assertTrue($server->issueAccessToken());
|
$this->assertTrue($server->issueAccessToken());
|
||||||
@@ -66,7 +66,7 @@ class AuthorizationServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testIssueAccessTokenEmptyGrantType()
|
public function testIssueAccessTokenEmptyGrantType()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$this->assertTrue($server->issueAccessToken());
|
$this->assertTrue($server->issueAccessToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ class AuthorizationServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$_POST['grant_type'] = 'foobar';
|
$_POST['grant_type'] = 'foobar';
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$this->assertTrue($server->issueAccessToken());
|
$this->assertTrue($server->issueAccessToken());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if (! @include_once __DIR__ . '/../../vendor/autoload.php') {
|
if (! @include_once __DIR__.'/../../vendor/autoload.php') {
|
||||||
exit("You must set up the project dependencies, run the following commands:\n> wget http://getcomposer.org/composer.phar\n> php composer.phar install\n");
|
exit("You must set up the project dependencies, run the following commands:\n> wget http://getcomposer.org/composer.phar\n> php composer.phar install\n");
|
||||||
}
|
}
|
||||||
|
@@ -3,12 +3,12 @@
|
|||||||
namespace LeagueTests\Entity;
|
namespace LeagueTests\Entity;
|
||||||
|
|
||||||
use LeagueTests\Stubs\StubAbstractTokenEntity;
|
use LeagueTests\Stubs\StubAbstractTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use \Mockery as M;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
|
use Mockery as M;
|
||||||
|
|
||||||
class AbstractTokenTest extends \PHPUnit_Framework_TestCase
|
class AbstractTokenEntityTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testSetGet()
|
public function testSetGet()
|
||||||
{
|
{
|
||||||
@@ -93,7 +93,7 @@ class AbstractTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$scopes = [
|
$scopes = [
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'scope1', 'description' => 'foo']),
|
(new ScopeEntity($server))->hydrate(['id' => 'scope1', 'description' => 'foo']),
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'scope2', 'description' => 'bar'])
|
(new ScopeEntity($server))->hydrate(['id' => 'scope2', 'description' => 'bar']),
|
||||||
];
|
];
|
||||||
|
|
||||||
$result = $method->invokeArgs($entity, [$scopes]);
|
$result = $method->invokeArgs($entity, [$scopes]);
|
||||||
|
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace LeagueTests\Entity;
|
namespace LeagueTests\Entity;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
use Mockery as M;
|
||||||
use \Mockery as M;
|
|
||||||
|
|
||||||
class AccessTokenTest extends \PHPUnit_Framework_TestCase
|
class AccessTokenEntityTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testSave()
|
public function testSave()
|
||||||
{
|
{
|
||||||
@@ -20,7 +20,7 @@ class AccessTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
|
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
namespace LeagueTests\Entity;
|
namespace LeagueTests\Entity;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
|
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
use Mockery as M;
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
|
||||||
use \Mockery as M;
|
|
||||||
|
|
||||||
class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
class AuthCodeEntityTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testSetGet()
|
public function testSetGet()
|
||||||
{
|
{
|
||||||
@@ -37,7 +37,7 @@ class AuthCodeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$authCodeStorage->shouldReceive('associateScope');
|
$authCodeStorage->shouldReceive('associateScope');
|
||||||
$authCodeStorage->shouldReceive('setServer');
|
$authCodeStorage->shouldReceive('setServer');
|
||||||
$authCodeStorage->shouldReceive('getScopes')->andReturn([
|
$authCodeStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$server->shouldReceive('getAuthCodeStorage')->andReturn($authCodeStorage);
|
$server->shouldReceive('getAuthCodeStorage')->andReturn($authCodeStorage);
|
||||||
|
@@ -3,9 +3,9 @@
|
|||||||
namespace LeagueTests\Entity;
|
namespace LeagueTests\Entity;
|
||||||
|
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use \Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
class ClientTest extends \PHPUnit_Framework_TestCase
|
class ClientEntityTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testSetGet()
|
public function testSetGet()
|
||||||
{
|
{
|
||||||
@@ -14,7 +14,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
'id' => 'foobar',
|
'id' => 'foobar',
|
||||||
'secret' => 'barfoo',
|
'secret' => 'barfoo',
|
||||||
'name' => 'Test Client',
|
'name' => 'Test Client',
|
||||||
'redirectUri' => 'http://foo/bar'
|
'redirectUri' => 'http://foo/bar',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals('foobar', $client->getId());
|
$this->assertEquals('foobar', $client->getId());
|
||||||
|
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace LeagueTests\Entity;
|
namespace LeagueTests\Entity;
|
||||||
|
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
|
||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||||
use \Mockery as M;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
|
use Mockery as M;
|
||||||
|
|
||||||
class RefreshTokenEntityTest extends \PHPUnit_Framework_TestCase
|
class RefreshTokenEntityTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@@ -55,7 +55,7 @@ class RefreshTokenEntityTest extends \PHPUnit_Framework_TestCase
|
|||||||
(new AccessTokenEntity($server))->setId('foobar')
|
(new AccessTokenEntity($server))->setId('foobar')
|
||||||
);
|
);
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$server->shouldReceive('getAccessTokenStorage')->andReturn($accessTokenStorage);
|
$server->shouldReceive('getAccessTokenStorage')->andReturn($accessTokenStorage);
|
||||||
|
@@ -3,16 +3,16 @@
|
|||||||
namespace LeagueTests\Entity;
|
namespace LeagueTests\Entity;
|
||||||
|
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
use \Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
class ScopeTest extends \PHPUnit_Framework_TestCase
|
class ScopeEntityTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testSetGet()
|
public function testSetGet()
|
||||||
{
|
{
|
||||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||||
$scope = (new ScopeEntity($server))->hydrate([
|
$scope = (new ScopeEntity($server))->hydrate([
|
||||||
'id' => 'foobar',
|
'id' => 'foobar',
|
||||||
'description' => 'barfoo'
|
'description' => 'barfoo',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals('foobar', $scope->getId());
|
$this->assertEquals('foobar', $scope->getId());
|
||||||
|
@@ -2,15 +2,15 @@
|
|||||||
|
|
||||||
namespace LeagueTests\Entity;
|
namespace LeagueTests\Entity;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
use \Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
class SessionTest extends \PHPUnit_Framework_TestCase
|
class SessionEntityTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testSetGet()
|
public function testSetGet()
|
||||||
{
|
{
|
||||||
@@ -60,7 +60,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$scopes = [
|
$scopes = [
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'scope1']),
|
(new ScopeEntity($server))->hydrate(['id' => 'scope1']),
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'scope2'])
|
(new ScopeEntity($server))->hydrate(['id' => 'scope2']),
|
||||||
];
|
];
|
||||||
|
|
||||||
$result = $method->invokeArgs($entity, [$scopes]);
|
$result = $method->invokeArgs($entity, [$scopes]);
|
||||||
@@ -132,7 +132,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
|
|||||||
$sessionStorage->shouldReceive('associateScope');
|
$sessionStorage->shouldReceive('associateScope');
|
||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
$sessionStorage->shouldReceive('getScopes')->andReturn([
|
$sessionStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$server->shouldReceive('getSessionStorage')->andReturn($sessionStorage);
|
$server->shouldReceive('getSessionStorage')->andReturn($sessionStorage);
|
||||||
|
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
namespace LeagueTests;
|
namespace LeagueTests;
|
||||||
|
|
||||||
use \Mockery as M;
|
use League\OAuth2\Server\Exception\OAuthException;
|
||||||
|
|
||||||
class OAuthExceptionTest extends \PHPUnit_Framework_TestCase
|
class OAuthExceptionTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testGetHttpHeaders()
|
public function testGetHttpHeaders()
|
||||||
{
|
{
|
||||||
$exception = new \League\OAuth2\Server\Exception\OAuthException();
|
$exception = new OAuthException();
|
||||||
|
|
||||||
$exception->httpStatusCode = 400;
|
$exception->httpStatusCode = 400;
|
||||||
$this->assertSame($exception->getHttpHeaders(), ['HTTP/1.1 400 Bad Request']);
|
$this->assertSame($exception->getHttpHeaders(), ['HTTP/1.1 400 Bad Request']);
|
||||||
@@ -25,7 +25,7 @@ class OAuthExceptionTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testShouldRedirect()
|
public function testShouldRedirect()
|
||||||
{
|
{
|
||||||
$exception = new \League\OAuth2\Server\Exception\OAuthException();
|
$exception = new OAuthException();
|
||||||
$exception->redirectUri = 'http://example.com/';
|
$exception->redirectUri = 'http://example.com/';
|
||||||
$exception->errorType = 'Error';
|
$exception->errorType = 'Error';
|
||||||
$this->assertTrue($exception->shouldRedirect());
|
$this->assertTrue($exception->shouldRedirect());
|
||||||
|
@@ -2,21 +2,21 @@
|
|||||||
|
|
||||||
namespace LeagueTests\Grant;
|
namespace LeagueTests\Grant;
|
||||||
|
|
||||||
use League\OAuth2\Server\Grant;
|
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
|
||||||
use League\OAuth2\Server\Exception\InvalidRequestException;
|
|
||||||
use LeagueTests\Stubs\StubAbstractGrant;
|
use LeagueTests\Stubs\StubAbstractGrant;
|
||||||
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
|
use League\OAuth2\Server\Exception\InvalidRequestException;
|
||||||
|
use League\OAuth2\Server\Grant;
|
||||||
use Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testSetGet()
|
public function testSetGet()
|
||||||
{
|
{
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
|
|
||||||
$grant = new StubAbstractGrant;
|
$grant = new StubAbstractGrant();
|
||||||
$grant->setIdentifier('foobar');
|
$grant->setIdentifier('foobar');
|
||||||
$grant->setAccessTokenTTL(300);
|
$grant->setAccessTokenTTL(300);
|
||||||
$grant->setAuthorizationServer($server);
|
$grant->setAuthorizationServer($server);
|
||||||
@@ -31,14 +31,14 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||||
|
|
||||||
$grant = new StubAbstractGrant;
|
$grant = new StubAbstractGrant();
|
||||||
$reflectedGrant = new \ReflectionClass('LeagueTests\Stubs\StubAbstractGrant');
|
$reflectedGrant = new \ReflectionClass('LeagueTests\Stubs\StubAbstractGrant');
|
||||||
$method = $reflectedGrant->getMethod('formatScopes');
|
$method = $reflectedGrant->getMethod('formatScopes');
|
||||||
$method->setAccessible(true);
|
$method->setAccessible(true);
|
||||||
|
|
||||||
$scopes = [
|
$scopes = [
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'scope1', 'description' => 'foo']),
|
(new ScopeEntity($server))->hydrate(['id' => 'scope1', 'description' => 'foo']),
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'scope2', 'description' => 'bar'])
|
(new ScopeEntity($server))->hydrate(['id' => 'scope2', 'description' => 'bar']),
|
||||||
];
|
];
|
||||||
|
|
||||||
$result = $method->invokeArgs($grant, [$scopes]);
|
$result = $method->invokeArgs($grant, [$scopes]);
|
||||||
@@ -51,7 +51,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testValidateScopes()
|
public function testValidateScopes()
|
||||||
{
|
{
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
@@ -61,14 +61,14 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$server->setScopeStorage($scopeStorage);
|
$server->setScopeStorage($scopeStorage);
|
||||||
|
|
||||||
$grant = new StubAbstractGrant;
|
$grant = new StubAbstractGrant();
|
||||||
$grant->setAuthorizationServer($server);
|
$grant->setAuthorizationServer($server);
|
||||||
|
|
||||||
$client = (new ClientEntity($server))->hydrate(['id' => 'testapp']);
|
$client = (new ClientEntity($server))->hydrate(['id' => 'testapp']);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
[
|
[
|
||||||
'foo' => (new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
'foo' => (new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
],
|
],
|
||||||
$grant->validateScopes('foo', $client)
|
$grant->validateScopes('foo', $client)
|
||||||
);
|
);
|
||||||
@@ -81,11 +81,11 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$server->requireScopeParam(true);
|
$server->requireScopeParam(true);
|
||||||
$server->setScopeStorage($scopeStorage);
|
$server->setScopeStorage($scopeStorage);
|
||||||
|
|
||||||
$grant = new StubAbstractGrant;
|
$grant = new StubAbstractGrant();
|
||||||
$grant->setAuthorizationServer($server);
|
$grant->setAuthorizationServer($server);
|
||||||
|
|
||||||
$client = (new ClientEntity($server))->hydrate(['id' => 'testapp']);
|
$client = (new ClientEntity($server))->hydrate(['id' => 'testapp']);
|
||||||
@@ -101,10 +101,10 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
$scopeStorage->shouldReceive('get')->andReturn(null);
|
$scopeStorage->shouldReceive('get')->andReturn(null);
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$server->setScopeStorage($scopeStorage);
|
$server->setScopeStorage($scopeStorage);
|
||||||
|
|
||||||
$grant = new StubAbstractGrant;
|
$grant = new StubAbstractGrant();
|
||||||
$grant->setAuthorizationServer($server);
|
$grant->setAuthorizationServer($server);
|
||||||
|
|
||||||
$client = (new ClientEntity($server))->hydrate(['id' => 'testapp']);
|
$client = (new ClientEntity($server))->hydrate(['id' => 'testapp']);
|
||||||
@@ -114,7 +114,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testValidateScopesDefaultScope()
|
public function testValidateScopesDefaultScope()
|
||||||
{
|
{
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
@@ -127,7 +127,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$server->setScopeStorage($scopeStorage);
|
$server->setScopeStorage($scopeStorage);
|
||||||
$server->setDefaultScope('foo');
|
$server->setDefaultScope('foo');
|
||||||
|
|
||||||
$grant = new StubAbstractGrant;
|
$grant = new StubAbstractGrant();
|
||||||
$grant->setAuthorizationServer($server);
|
$grant->setAuthorizationServer($server);
|
||||||
|
|
||||||
$client = (new ClientEntity($server))->hydrate(['id' => 'testapp']);
|
$client = (new ClientEntity($server))->hydrate(['id' => 'testapp']);
|
||||||
@@ -137,7 +137,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testValidateScopesDefaultScopeArray()
|
public function testValidateScopesDefaultScopeArray()
|
||||||
{
|
{
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
$scopeStorage->shouldReceive('setServer');
|
$scopeStorage->shouldReceive('setServer');
|
||||||
@@ -150,7 +150,7 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$server->setScopeStorage($scopeStorage);
|
$server->setScopeStorage($scopeStorage);
|
||||||
$server->setDefaultScope(['foo', 'bar']);
|
$server->setDefaultScope(['foo', 'bar']);
|
||||||
|
|
||||||
$grant = new StubAbstractGrant;
|
$grant = new StubAbstractGrant();
|
||||||
$grant->setAuthorizationServer($server);
|
$grant->setAuthorizationServer($server);
|
||||||
|
|
||||||
$client = (new ClientEntity($server))->hydrate(['id' => 'testapp']);
|
$client = (new ClientEntity($server))->hydrate(['id' => 'testapp']);
|
||||||
|
@@ -2,21 +2,21 @@
|
|||||||
|
|
||||||
namespace LeagueTests\Grant;
|
namespace LeagueTests\Grant;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
|
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
||||||
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
|
use League\OAuth2\Server\Exception\InvalidRequestException;
|
||||||
use League\OAuth2\Server\Grant\AuthCodeGrant;
|
use League\OAuth2\Server\Grant\AuthCodeGrant;
|
||||||
use League\OAuth2\Server\Grant\RefreshTokenGrant;
|
use League\OAuth2\Server\Grant\RefreshTokenGrant;
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
|
||||||
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
|
||||||
use League\OAuth2\Server\Exception\InvalidRequestException;
|
|
||||||
use Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testSetAuthTokenTTL()
|
public function testSetAuthTokenTTL()
|
||||||
{
|
{
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
$grant->setAuthTokenTTL(100);
|
$grant->setAuthTokenTTL(100);
|
||||||
|
|
||||||
$class = new \ReflectionClass($grant);
|
$class = new \ReflectionClass($grant);
|
||||||
@@ -30,25 +30,24 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$_GET = [];
|
$_GET = [];
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
|
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$grant->checkAuthorizeParams();
|
$grant->checkAuthorizeParams();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCheckAuthoriseParamsMissingRedirectUri()
|
public function testCheckAuthoriseParamsMissingRedirectUri()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
$this->setExpectedException('League\OAuth2\Server\Exception\InvalidRequestException');
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$_GET = [
|
$_GET = [
|
||||||
'client_id' => 'testapp'
|
'client_id' => 'testapp',
|
||||||
];
|
];
|
||||||
|
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$grant->checkAuthorizeParams();
|
$grant->checkAuthorizeParams();
|
||||||
@@ -61,11 +60,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$_GET = [
|
$_GET = [
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'response_type' => 'code'
|
'response_type' => 'code',
|
||||||
];
|
];
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
|
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -83,9 +82,9 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$_GET = [
|
$_GET = [
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'redirect_uri' => 'http://foo/bar'
|
'redirect_uri' => 'http://foo/bar',
|
||||||
];
|
];
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -94,7 +93,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
|
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
$server->requireStateParam(true);
|
$server->requireStateParam(true);
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
@@ -107,9 +106,9 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$_GET = [
|
$_GET = [
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'redirect_uri' => 'http://foo/bar'
|
'redirect_uri' => 'http://foo/bar',
|
||||||
];
|
];
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -118,7 +117,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
|
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$grant->checkAuthorizeParams();
|
$grant->checkAuthorizeParams();
|
||||||
@@ -131,9 +130,9 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$_GET = [
|
$_GET = [
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'response_type' => 'foobar'
|
'response_type' => 'foobar',
|
||||||
];
|
];
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -142,7 +141,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
|
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$grant->checkAuthorizeParams();
|
$grant->checkAuthorizeParams();
|
||||||
@@ -156,11 +155,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'response_type' => 'code',
|
'response_type' => 'code',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'scope' => 'foo'
|
'scope' => 'foo',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -197,11 +196,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'response_type' => 'code',
|
'response_type' => 'code',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'scope' => 'foo'
|
'scope' => 'foo',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -213,7 +212,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
$sessionStorage->shouldReceive('associateScope');
|
$sessionStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@@ -221,7 +220,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@@ -249,11 +248,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testNewAuthoriseRequest()
|
public function testNewAuthoriseRequest()
|
||||||
{
|
{
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$client = (new ClientEntity($server))->hydrate(['id' => 'testapp']);
|
$client = (new ClientEntity($server))->hydrate(['id' => 'testapp']);
|
||||||
$scope = (new ScopeEntity($server))->hydrate(['id' => 'foo']);
|
$scope = (new ScopeEntity($server))->hydrate(['id' => 'foo']);
|
||||||
|
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
@@ -284,12 +283,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$_POST['grant_type'] = 'authorization_code';
|
$_POST['grant_type'] = 'authorization_code';
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$server->issueAccessToken();
|
$server->issueAccessToken();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCompleteFlowMissingClientSecret()
|
public function testCompleteFlowMissingClientSecret()
|
||||||
@@ -298,11 +296,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
'client_id' => 'testapp'
|
'client_id' => 'testapp',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$server->issueAccessToken();
|
$server->issueAccessToken();
|
||||||
@@ -315,11 +313,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar'
|
'client_secret' => 'foobar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$server->issueAccessToken();
|
$server->issueAccessToken();
|
||||||
@@ -333,11 +331,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'redirect_uri' => 'http://foo/bar'
|
'redirect_uri' => 'http://foo/bar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -357,11 +355,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'redirect_uri' => 'http://foo/bar'
|
'redirect_uri' => 'http://foo/bar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -406,11 +404,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'code' => 'foobar'
|
'code' => 'foobar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -455,11 +453,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'code' => 'foobar'
|
'code' => 'foobar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -506,11 +504,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'code' => 'foobar'
|
'code' => 'foobar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -555,11 +553,11 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'code' => 'foo'
|
'code' => 'foo',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -581,7 +579,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
(new SessionEntity($server))->setId('foobar')
|
(new SessionEntity($server))->setId('foobar')
|
||||||
);
|
);
|
||||||
$sessionStorage->shouldReceive('getScopes')->andReturn([
|
$sessionStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||||
@@ -589,7 +587,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
@@ -605,7 +603,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
(new AuthCodeEntity($server))->setId('foobar')->setRedirectUri('http://foo/bar')->setExpireTime(time() + 300)
|
(new AuthCodeEntity($server))->setId('foobar')->setRedirectUri('http://foo/bar')->setExpireTime(time() + 300)
|
||||||
);
|
);
|
||||||
$authCodeStorage->shouldReceive('getScopes')->andReturn([
|
$authCodeStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$server->setClientStorage($clientStorage);
|
$server->setClientStorage($clientStorage);
|
||||||
@@ -625,12 +623,12 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'code' => 'foo'
|
'code' => 'foo',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new AuthCodeGrant;
|
$grant = new AuthCodeGrant();
|
||||||
$rtgrant = new RefreshTokenGrant;
|
$rtgrant = new RefreshTokenGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -652,7 +650,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
(new SessionEntity($server))->setId('foobar')
|
(new SessionEntity($server))->setId('foobar')
|
||||||
);
|
);
|
||||||
$sessionStorage->shouldReceive('getScopes')->andReturn([
|
$sessionStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||||
@@ -660,7 +658,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
|
||||||
@@ -676,7 +674,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
(new AuthCodeEntity($server))->setId('foobar')->setRedirectUri('http://foo/bar')->setExpireTime(time() + 300)
|
(new AuthCodeEntity($server))->setId('foobar')->setRedirectUri('http://foo/bar')->setExpireTime(time() + 300)
|
||||||
);
|
);
|
||||||
$authCodeStorage->shouldReceive('getScopes')->andReturn([
|
$authCodeStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||||
|
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace LeagueTests\Grant;
|
namespace LeagueTests\Grant;
|
||||||
|
|
||||||
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
|
||||||
use Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
||||||
@@ -17,12 +17,11 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$_POST['grant_type'] = 'client_credentials';
|
$_POST['grant_type'] = 'client_credentials';
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new ClientCredentialsGrant;
|
$grant = new ClientCredentialsGrant();
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$server->issueAccessToken();
|
$server->issueAccessToken();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCompleteFlowMissingClientSecret()
|
public function testCompleteFlowMissingClientSecret()
|
||||||
@@ -31,11 +30,11 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'client_credentials',
|
'grant_type' => 'client_credentials',
|
||||||
'client_id' => 'testapp'
|
'client_id' => 'testapp',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new ClientCredentialsGrant;
|
$grant = new ClientCredentialsGrant();
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$server->issueAccessToken();
|
$server->issueAccessToken();
|
||||||
@@ -48,11 +47,11 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'client_credentials',
|
'grant_type' => 'client_credentials',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar'
|
'client_secret' => 'foobar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new ClientCredentialsGrant;
|
$grant = new ClientCredentialsGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -72,11 +71,11 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'grant_type' => 'client_credentials',
|
'grant_type' => 'client_credentials',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'scope' => 'foo'
|
'scope' => 'foo',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new ClientCredentialsGrant;
|
$grant = new ClientCredentialsGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -112,11 +111,11 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'client_credentials',
|
'grant_type' => 'client_credentials',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar'
|
'client_secret' => 'foobar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new ClientCredentialsGrant;
|
$grant = new ClientCredentialsGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -160,11 +159,11 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'grant_type' => 'client_credentials',
|
'grant_type' => 'client_credentials',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'scope' => 'foo'
|
'scope' => 'foo',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new ClientCredentialsGrant;
|
$grant = new ClientCredentialsGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -176,7 +175,7 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||||
(new SessionEntity($server))->setId('foobar')
|
(new SessionEntity($server))->setId('foobar')
|
||||||
@@ -187,7 +186,7 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@@ -214,16 +213,16 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'grant_type' => 'client_credentials',
|
'grant_type' => 'client_credentials',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'scope' => 'foo'
|
'scope' => 'foo',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new ClientCredentialsGrant;
|
$grant = new ClientCredentialsGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
$clientStorage->shouldReceive('get')->andThrow(
|
$clientStorage->shouldReceive('get')->andThrow(
|
||||||
new \League\OAuth2\Server\Exception\UnauthorizedClientException
|
new \League\OAuth2\Server\Exception\UnauthorizedClientException()
|
||||||
);
|
);
|
||||||
|
|
||||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||||
|
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace LeagueTests\Grant;
|
namespace LeagueTests\Grant;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
use League\OAuth2\Server\Grant\PasswordGrant;
|
use League\OAuth2\Server\Grant\PasswordGrant;
|
||||||
use League\OAuth2\Server\Grant\RefreshTokenGrant;
|
use League\OAuth2\Server\Grant\RefreshTokenGrant;
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
|
||||||
use Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
||||||
@@ -18,12 +18,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$_POST['grant_type'] = 'password';
|
$_POST['grant_type'] = 'password';
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new PasswordGrant;
|
$grant = new PasswordGrant();
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$server->issueAccessToken();
|
$server->issueAccessToken();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCompleteFlowMissingClientSecret()
|
public function testCompleteFlowMissingClientSecret()
|
||||||
@@ -32,11 +31,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'password',
|
'grant_type' => 'password',
|
||||||
'client_id' => 'testapp'
|
'client_id' => 'testapp',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new PasswordGrant;
|
$grant = new PasswordGrant();
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$server->issueAccessToken();
|
$server->issueAccessToken();
|
||||||
@@ -49,11 +48,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'password',
|
'grant_type' => 'password',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar'
|
'client_secret' => 'foobar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new PasswordGrant;
|
$grant = new PasswordGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -72,11 +71,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'password',
|
'grant_type' => 'password',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar'
|
'client_secret' => 'foobar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new PasswordGrant;
|
$grant = new PasswordGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -115,11 +114,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'grant_type' => 'password',
|
'grant_type' => 'password',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'username' => 'foo'
|
'username' => 'foo',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new PasswordGrant;
|
$grant = new PasswordGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -159,11 +158,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'username' => 'foo',
|
'username' => 'foo',
|
||||||
'password' => 'foobar'
|
'password' => 'foobar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new PasswordGrant;
|
$grant = new PasswordGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -204,11 +203,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'username' => 'foo',
|
'username' => 'foo',
|
||||||
'password' => 'foobar',
|
'password' => 'foobar',
|
||||||
'scope' => 'foo'
|
'scope' => 'foo',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new PasswordGrant;
|
$grant = new PasswordGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -251,11 +250,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'username' => 'username',
|
'username' => 'username',
|
||||||
'password' => 'password'
|
'password' => 'password',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new PasswordGrant;
|
$grant = new PasswordGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -301,11 +300,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'scope' => 'foo',
|
'scope' => 'foo',
|
||||||
'username' => 'username',
|
'username' => 'username',
|
||||||
'password' => 'password'
|
'password' => 'password',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new PasswordGrant;
|
$grant = new PasswordGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -317,7 +316,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
$sessionStorage->shouldReceive('associateScope');
|
$sessionStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@@ -325,7 +324,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@@ -355,11 +354,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'scope' => 'foo',
|
'scope' => 'foo',
|
||||||
'username' => 'username',
|
'username' => 'username',
|
||||||
'password' => 'password'
|
'password' => 'password',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new PasswordGrant;
|
$grant = new PasswordGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -371,7 +370,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||||
(new SessionEntity($server))->setId('foobar')
|
(new SessionEntity($server))->setId('foobar')
|
||||||
@@ -382,7 +381,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@@ -416,11 +415,11 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'scope' => 'foo',
|
'scope' => 'foo',
|
||||||
'username' => 'username',
|
'username' => 'username',
|
||||||
'password' => 'password'
|
'password' => 'password',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new PasswordGrant;
|
$grant = new PasswordGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -432,7 +431,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$sessionStorage->shouldReceive('setServer');
|
$sessionStorage->shouldReceive('setServer');
|
||||||
$sessionStorage->shouldReceive('create')->andreturn(123);
|
$sessionStorage->shouldReceive('create')->andreturn(123);
|
||||||
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
$sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||||
(new SessionEntity($server))->setId('foobar')
|
(new SessionEntity($server))->setId('foobar')
|
||||||
@@ -443,7 +442,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@@ -469,7 +468,7 @@ class PasswordGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
});
|
});
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$server->addGrantType(new RefreshTokenGrant);
|
$server->addGrantType(new RefreshTokenGrant());
|
||||||
$response = $server->issueAccessToken();
|
$response = $server->issueAccessToken();
|
||||||
|
|
||||||
$this->assertTrue(array_key_exists('access_token', $response));
|
$this->assertTrue(array_key_exists('access_token', $response));
|
||||||
|
@@ -2,20 +2,20 @@
|
|||||||
|
|
||||||
namespace LeagueTests\Grant;
|
namespace LeagueTests\Grant;
|
||||||
|
|
||||||
use League\OAuth2\Server\Grant\RefreshTokenGrant;
|
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
|
||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
|
||||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||||
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
|
use League\OAuth2\Server\Grant\RefreshTokenGrant;
|
||||||
use Mockery as M;
|
use Mockery as M;
|
||||||
|
|
||||||
class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testSetRefreshTokenTTL()
|
public function testSetRefreshTokenTTL()
|
||||||
{
|
{
|
||||||
$grant = new RefreshTokenGrant;
|
$grant = new RefreshTokenGrant();
|
||||||
$grant->setRefreshTokenTTL(86400);
|
$grant->setRefreshTokenTTL(86400);
|
||||||
|
|
||||||
$property = new \ReflectionProperty($grant, 'refreshTokenTTL');
|
$property = new \ReflectionProperty($grant, 'refreshTokenTTL');
|
||||||
@@ -30,8 +30,8 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$_POST['grant_type'] = 'refresh_token';
|
$_POST['grant_type'] = 'refresh_token';
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new RefreshTokenGrant;
|
$grant = new RefreshTokenGrant();
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$server->issueAccessToken();
|
$server->issueAccessToken();
|
||||||
@@ -43,11 +43,11 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'refresh_token',
|
'grant_type' => 'refresh_token',
|
||||||
'client_id' => 'testapp'
|
'client_id' => 'testapp',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new RefreshTokenGrant;
|
$grant = new RefreshTokenGrant();
|
||||||
|
|
||||||
$server->addGrantType($grant);
|
$server->addGrantType($grant);
|
||||||
$server->issueAccessToken();
|
$server->issueAccessToken();
|
||||||
@@ -60,11 +60,11 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$_POST = [
|
$_POST = [
|
||||||
'grant_type' => 'refresh_token',
|
'grant_type' => 'refresh_token',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar'
|
'client_secret' => 'foobar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new RefreshTokenGrant;
|
$grant = new RefreshTokenGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -86,8 +86,8 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new RefreshTokenGrant;
|
$grant = new RefreshTokenGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -118,11 +118,11 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'grant_type' => 'refresh_token',
|
'grant_type' => 'refresh_token',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'refresh_token' => 'meh'
|
'refresh_token' => 'meh',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new RefreshTokenGrant;
|
$grant = new RefreshTokenGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -152,11 +152,11 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'grant_type' => 'refresh_token',
|
'grant_type' => 'refresh_token',
|
||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'refresh_token' => 'refresh_token'
|
'refresh_token' => 'refresh_token',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new RefreshTokenGrant;
|
$grant = new RefreshTokenGrant();
|
||||||
|
|
||||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||||
$clientStorage->shouldReceive('setServer');
|
$clientStorage->shouldReceive('setServer');
|
||||||
@@ -180,7 +180,7 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('delete');
|
$accessTokenStorage->shouldReceive('delete');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@@ -221,11 +221,11 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'refresh_token' => 'refresh_token',
|
'refresh_token' => 'refresh_token',
|
||||||
'scope' => 'foo'
|
'scope' => 'foo',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new RefreshTokenGrant;
|
$grant = new RefreshTokenGrant();
|
||||||
|
|
||||||
$oldSession = (new SessionEntity($server))->associateScope((new ScopeEntity($server))->hydrate(['id' => 'foo']));
|
$oldSession = (new SessionEntity($server))->associateScope((new ScopeEntity($server))->hydrate(['id' => 'foo']));
|
||||||
|
|
||||||
@@ -251,7 +251,7 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('delete');
|
$accessTokenStorage->shouldReceive('delete');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
@@ -292,11 +292,11 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'client_id' => 'testapp',
|
'client_id' => 'testapp',
|
||||||
'client_secret' => 'foobar',
|
'client_secret' => 'foobar',
|
||||||
'refresh_token' => 'refresh_token',
|
'refresh_token' => 'refresh_token',
|
||||||
'scope' => 'blah'
|
'scope' => 'blah',
|
||||||
];
|
];
|
||||||
|
|
||||||
$server = new AuthorizationServer;
|
$server = new AuthorizationServer();
|
||||||
$grant = new RefreshTokenGrant;
|
$grant = new RefreshTokenGrant();
|
||||||
|
|
||||||
$oldSession = (new SessionEntity($server))->associateScope((new ScopeEntity($server))->hydrate(['id' => 'foo']));
|
$oldSession = (new SessionEntity($server))->associateScope((new ScopeEntity($server))->hydrate(['id' => 'foo']));
|
||||||
|
|
||||||
@@ -322,7 +322,7 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenStorage->shouldReceive('delete');
|
$accessTokenStorage->shouldReceive('delete');
|
||||||
$accessTokenStorage->shouldReceive('create');
|
$accessTokenStorage->shouldReceive('create');
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo'])
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
]);
|
]);
|
||||||
$accessTokenStorage->shouldReceive('associateScope');
|
$accessTokenStorage->shouldReceive('associateScope');
|
||||||
|
|
||||||
|
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace LeagueTests;
|
namespace LeagueTests;
|
||||||
|
|
||||||
use League\OAuth2\Server\ResourceServer;
|
|
||||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||||
use League\OAuth2\Server\Entity\SessionEntity;
|
|
||||||
use League\OAuth2\Server\Entity\ClientEntity;
|
use League\OAuth2\Server\Entity\ClientEntity;
|
||||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||||
use \Mockery as M;
|
use League\OAuth2\Server\Entity\SessionEntity;
|
||||||
|
use League\OAuth2\Server\ResourceServer;
|
||||||
|
use Mockery as M;
|
||||||
|
|
||||||
class ResourceServerTest extends \PHPUnit_Framework_TestCase
|
class ResourceServerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@@ -77,7 +77,7 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$request = new \Symfony\Component\HttpFoundation\Request();
|
$request = new \Symfony\Component\HttpFoundation\Request();
|
||||||
$request->headers = new \Symfony\Component\HttpFoundation\ParameterBag([
|
$request->headers = new \Symfony\Component\HttpFoundation\ParameterBag([
|
||||||
'HTTP_AUTHORIZATION' => 'Bearer'
|
'HTTP_AUTHORIZATION' => 'Bearer',
|
||||||
]);
|
]);
|
||||||
$server->setRequest($request);
|
$server->setRequest($request);
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$server->setIdKey('at');
|
$server->setIdKey('at');
|
||||||
|
|
||||||
$server->addEventListener('session.owner', function($event) {
|
$server->addEventListener('session.owner', function ($event) {
|
||||||
$this->assertTrue($event->getSession() instanceof \League\OAuth2\Server\Entity\SessionEntity);
|
$this->assertTrue($event->getSession() instanceof \League\OAuth2\Server\Entity\SessionEntity);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'bar'])
|
(new ScopeEntity($server))->hydrate(['id' => 'bar']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||||
@@ -160,7 +160,7 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$request = new \Symfony\Component\HttpFoundation\Request();
|
$request = new \Symfony\Component\HttpFoundation\Request();
|
||||||
$request->headers = new \Symfony\Component\HttpFoundation\ParameterBag([
|
$request->headers = new \Symfony\Component\HttpFoundation\ParameterBag([
|
||||||
'Authorization' => 'Bearer abcdef'
|
'Authorization' => 'Bearer abcdef',
|
||||||
]);
|
]);
|
||||||
$server->setRequest($request);
|
$server->setRequest($request);
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$server->setIdKey('at');
|
$server->setIdKey('at');
|
||||||
|
|
||||||
$server->addEventListener('session.owner', function($event) {
|
$server->addEventListener('session.owner', function ($event) {
|
||||||
$this->assertTrue($event->getSession() instanceof \League\OAuth2\Server\Entity\SessionEntity);
|
$this->assertTrue($event->getSession() instanceof \League\OAuth2\Server\Entity\SessionEntity);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
(new ScopeEntity($server))->hydrate(['id' => 'foo']),
|
||||||
(new ScopeEntity($server))->hydrate(['id' => 'bar'])
|
(new ScopeEntity($server))->hydrate(['id' => 'bar']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||||
@@ -217,7 +217,7 @@ class ResourceServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$request = new \Symfony\Component\HttpFoundation\Request();
|
$request = new \Symfony\Component\HttpFoundation\Request();
|
||||||
$request->headers = new \Symfony\Component\HttpFoundation\ParameterBag([
|
$request->headers = new \Symfony\Component\HttpFoundation\ParameterBag([
|
||||||
'Authorization' => 'Bearer abcdef'
|
'Authorization' => 'Bearer abcdef',
|
||||||
]);
|
]);
|
||||||
$server->setRequest($request);
|
$server->setRequest($request);
|
||||||
|
|
||||||
|
@@ -2,19 +2,19 @@
|
|||||||
|
|
||||||
namespace LeagueTests\Storage;
|
namespace LeagueTests\Storage;
|
||||||
|
|
||||||
use LeagueTests\Stubs\StubAbstractStorage;
|
|
||||||
use LeagueTests\Stubs\StubAbstractServer;
|
use LeagueTests\Stubs\StubAbstractServer;
|
||||||
|
use LeagueTests\Stubs\StubAbstractStorage;
|
||||||
|
|
||||||
class AdapterStorageTest extends \PHPUnit_Framework_TestCase
|
class AbstractStorageTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testSetGet()
|
public function testSetGet()
|
||||||
{
|
{
|
||||||
$storage = new StubAbstractStorage;
|
$storage = new StubAbstractStorage();
|
||||||
|
|
||||||
$reflector = new \ReflectionClass($storage);
|
$reflector = new \ReflectionClass($storage);
|
||||||
$setMethod = $reflector->getMethod('setServer');
|
$setMethod = $reflector->getMethod('setServer');
|
||||||
$setMethod->setAccessible(true);
|
$setMethod->setAccessible(true);
|
||||||
$setMethod->invokeArgs($storage, [new StubAbstractServer]);
|
$setMethod->invokeArgs($storage, [new StubAbstractServer()]);
|
||||||
$getMethod = $reflector->getMethod('getServer');
|
$getMethod = $reflector->getMethod('getServer');
|
||||||
$getMethod->setAccessible(true);
|
$getMethod->setAccessible(true);
|
||||||
|
|
||||||
|
@@ -4,5 +4,5 @@ namespace LeagueTests\Stubs;
|
|||||||
|
|
||||||
class StubAbstractServer extends \League\OAuth2\Server\AbstractServer
|
class StubAbstractServer extends \League\OAuth2\Server\AbstractServer
|
||||||
{
|
{
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
@@ -4,5 +4,5 @@ namespace LeagueTests\Stubs;
|
|||||||
|
|
||||||
class StubAbstractStorage extends \League\OAuth2\Server\Storage\AbstractStorage
|
class StubAbstractStorage extends \League\OAuth2\Server\Storage\AbstractStorage
|
||||||
{
|
{
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
@@ -2,17 +2,17 @@
|
|||||||
|
|
||||||
namespace LeagueTests\Stubs;
|
namespace LeagueTests\Stubs;
|
||||||
|
|
||||||
use \League\OAuth2\Server\Entity\AbstractTokenEntity;
|
use League\OAuth2\Server\Entity\AbstractTokenEntity;
|
||||||
|
|
||||||
class StubAbstractTokenEntity extends AbstractTokenEntity
|
class StubAbstractTokenEntity extends AbstractTokenEntity
|
||||||
{
|
{
|
||||||
public function expire()
|
public function expire()
|
||||||
{
|
{
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save()
|
public function save()
|
||||||
{
|
{
|
||||||
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,9 +8,9 @@ class RedirectUriTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
public function testMake()
|
public function testMake()
|
||||||
{
|
{
|
||||||
$v1 = RedirectUri::make('https://foobar/', array('foo'=>'bar'));
|
$v1 = RedirectUri::make('https://foobar/', ['foo' => 'bar']);
|
||||||
$v2 = RedirectUri::make('https://foobar/', array('foo'=>'bar'), '#');
|
$v2 = RedirectUri::make('https://foobar/', ['foo' => 'bar'], '#');
|
||||||
$v3 = RedirectUri::make('https://foobar/', array('foo'=>'bar', 'bar' => 'foo'));
|
$v3 = RedirectUri::make('https://foobar/', ['foo' => 'bar', 'bar' => 'foo']);
|
||||||
|
|
||||||
$this->assertEquals('https://foobar/?foo=bar', $v1);
|
$this->assertEquals('https://foobar/?foo=bar', $v1);
|
||||||
$this->assertEquals('https://foobar/#foo=bar', $v2);
|
$this->assertEquals('https://foobar/#foo=bar', $v2);
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace LeagueTests\util;
|
namespace LeagueTests\util;
|
||||||
|
|
||||||
use \League\OAuth2\Server\Util\SecureKey;
|
use League\OAuth2\Server\Util\SecureKey;
|
||||||
|
|
||||||
class SecureKeyTest extends \PHPUnit_Framework_TestCase
|
class SecureKeyTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@@ -26,8 +26,7 @@ class SecureKeyTest extends \PHPUnit_Framework_TestCase
|
|||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('generate')
|
->method('generate')
|
||||||
->with(11)
|
->with(11)
|
||||||
->will($this->returnValue($result))
|
->will($this->returnValue($result));
|
||||||
;
|
|
||||||
|
|
||||||
SecureKey::setAlgorithm($algorithm);
|
SecureKey::setAlgorithm($algorithm);
|
||||||
$this->assertSame($algorithm, SecureKey::getAlgorithm());
|
$this->assertSame($algorithm, SecureKey::getAlgorithm());
|
||||||
|
Reference in New Issue
Block a user