mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-01 08:23:03 +05:30
First commit of relational example
This commit is contained in:
parent
81e9e7364b
commit
c5aee31405
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,5 +5,6 @@
|
||||
/testing
|
||||
/examples/relational/vendor
|
||||
/examples/relational/config/oauth2.sqlite3
|
||||
/examples/relational/composer.lock
|
||||
/examples/nosql/vendor
|
||||
/examples/nosql/config/oauth2.sqlite3
|
25
examples/relational/Model/Users.php
Normal file
25
examples/relational/Model/Users.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace RelationalExample\Model;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class Users
|
||||
{
|
||||
public function get($username = null)
|
||||
{
|
||||
$query = Capsule::table('users')->select(['username', 'name', 'email', 'photo']);
|
||||
|
||||
if ($username !== null) {
|
||||
$query->where('username', '=', $username);
|
||||
}
|
||||
|
||||
$result = $query->get();
|
||||
|
||||
if (count($result) > 0) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
93
examples/relational/Storage/AccessTokenStorage.php
Normal file
93
examples/relational/Storage/AccessTokenStorage.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
class AccessTokenStorage extends Adapter implements AccessTokenInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($token)
|
||||
{
|
||||
$result = Capsule::table('oauth_access_tokens')
|
||||
->where('access_token', $token)
|
||||
->where('expire_time', '>=', time())
|
||||
->get();
|
||||
|
||||
if (count($result) === 1) {
|
||||
$token = new AccessTokenEntity($this->server);
|
||||
$token->setExpireTime($result[0]['expire_time']);
|
||||
$token->setToken($result[0]['access_token']);
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getByRefreshToken(RefreshTokenEntity $refreshToken)
|
||||
{
|
||||
die(var_dump(__METHOD__, func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getScopes(AbstractTokenEntity $token)
|
||||
{
|
||||
$result = Capsule::table('oauth_access_token_scopes')
|
||||
->select(['oauth_scopes.id', 'oauth_scopes.description'])
|
||||
->join('oauth_scopes', 'oauth_access_token_scopes.scope', '=', 'oauth_scopes.id')
|
||||
->where('access_token', $token->getToken())
|
||||
->get();
|
||||
|
||||
$response = [];
|
||||
|
||||
if (count($result) > 0) {
|
||||
foreach ($result as $row) {
|
||||
$scope = new ScopeEntity($this->server);
|
||||
$scope->setId($row['id']);
|
||||
$scope->setDescription($row['description']);
|
||||
$response[] = $scope;
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function create($token, $expireTime, $sessionId)
|
||||
{
|
||||
die(var_dump(__METHOD__, func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function associateScope(AbstractTokenEntity $token, ScopeEntity $scope)
|
||||
{
|
||||
die(var_dump(__METHOD__, func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete(AbstractTokenEntity $token)
|
||||
{
|
||||
die(var_dump(__METHOD__, func_get_args()));
|
||||
}
|
||||
}
|
17
examples/relational/Storage/AuthCodeStorage.php
Normal file
17
examples/relational/Storage/AuthCodeStorage.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace RelationalExample\Storage;
|
||||
|
||||
use League\OAuth2\Server\Storage\AuthCodeInterface;
|
||||
use League\OAuth2\Server\Storage\Adapter;
|
||||
|
||||
class AuthCodeStorage extends Adapter implements AuthCodeInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($token)
|
||||
{
|
||||
die(var_dump(__METHOD__, func_get_args()));
|
||||
}
|
||||
}
|
41
examples/relational/Storage/ClientStorage.php
Normal file
41
examples/relational/Storage/ClientStorage.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace RelationalExample\Storage;
|
||||
|
||||
use League\OAuth2\Server\Storage\ClientInterface;
|
||||
use League\OAuth2\Server\Storage\Adapter;
|
||||
use League\OAuth2\Server\Entity\ClientEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class ClientStorage extends Adapter implements ClientInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null)
|
||||
{
|
||||
die(var_dump(__METHOD__, func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBySession(SessionEntity $session)
|
||||
{
|
||||
$result = Capsule::table('oauth_clients')
|
||||
->select(['oauth_clients.id', 'oauth_clients.name'])
|
||||
->join('oauth_sessions', 'oauth_clients.id', '=', 'oauth_sessions.client_id')
|
||||
->where('oauth_sessions.id', $session->getId())
|
||||
->get();
|
||||
|
||||
if (count($result) === 1) {
|
||||
$client = new ClientEntity($this->server);
|
||||
$client->setId($result[0]['id']);
|
||||
$client->setName($result[0]['name']);
|
||||
|
||||
return $client;
|
||||
}
|
||||
}
|
||||
}
|
33
examples/relational/Storage/RefreshTokenStorage.php
Normal file
33
examples/relational/Storage/RefreshTokenStorage.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace RelationalExample\Storage;
|
||||
|
||||
use League\OAuth2\Server\Storage\RefreshTokenInterface;
|
||||
use League\OAuth2\Server\Storage\Adapter;
|
||||
|
||||
class RefreshTokenStorage extends Adapter implements RefreshTokenInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($token)
|
||||
{
|
||||
die(var_dump(__METHOD__, func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function create($token, $expireTime, $accessToken)
|
||||
{
|
||||
die(var_dump(__METHOD__, func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($token)
|
||||
{
|
||||
die(var_dump(__METHOD__, func_get_args()));
|
||||
}
|
||||
}
|
17
examples/relational/Storage/ScopeStorage.php
Normal file
17
examples/relational/Storage/ScopeStorage.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace RelationalExample\Storage;
|
||||
|
||||
use League\OAuth2\Server\Storage\ScopeInterface;
|
||||
use League\OAuth2\Server\Storage\Adapter;
|
||||
|
||||
class ScopeStorage extends Adapter implements ScopeInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($scope, $grantType = null)
|
||||
{
|
||||
die(var_dump(__METHOD__, func_get_args()));
|
||||
}
|
||||
}
|
78
examples/relational/Storage/SessionStorage.php
Normal file
78
examples/relational/Storage/SessionStorage.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace RelationalExample\Storage;
|
||||
|
||||
use League\OAuth2\Server\Storage\SessionInterface;
|
||||
use League\OAuth2\Server\Storage\Adapter;
|
||||
use League\OAuth2\Server\Entity\AccessTokenEntity;
|
||||
use League\OAuth2\Server\Entity\AuthCodeEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
class SessionStorage extends Adapter implements SessionInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($token)
|
||||
{
|
||||
die(var_dump(__METHOD__, func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getByAccessToken(AccessTokenEntity $accessToken)
|
||||
{
|
||||
$result = Capsule::table('oauth_sessions')
|
||||
->select(['oauth_sessions.id', 'oauth_sessions.owner_type', 'oauth_sessions.owner_id', 'oauth_sessions.client_id', 'oauth_sessions.client_redirect_uri'])
|
||||
->join('oauth_access_tokens', 'oauth_access_tokens.session_id', '=', 'oauth_sessions.id')
|
||||
->where('oauth_access_tokens.access_token', $accessToken->getToken())
|
||||
->get();
|
||||
|
||||
if (count($result) === 1) {
|
||||
// die(var_dump($result));
|
||||
$session = new SessionEntity($this->server);
|
||||
$session->setId($result[0]['id']);
|
||||
$session->setOwner($result[0]['owner_type'], $result[0]['owner_id']);
|
||||
|
||||
return $session;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getByAuthCode(AuthCodeEntity $authCode)
|
||||
{
|
||||
die(var_dump(__METHOD__, func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getScopes(SessionEntity $session)
|
||||
{
|
||||
die(var_dump(__CLASS__.'::'.__METHOD__, func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function create($ownerType, $ownerId, $clientId, $clientRedirectUri = null)
|
||||
{
|
||||
die(var_dump(__CLASS__.'::'.__METHOD__, func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function associateScope(SessionEntity $session, ScopeEntity $scope)
|
||||
{
|
||||
die(var_dump(__CLASS__.'::'.__METHOD__, func_get_args()));
|
||||
}
|
||||
}
|
121
examples/relational/api.php
Normal file
121
examples/relational/api.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace OAuth2Server\RelationalExample;
|
||||
|
||||
use \Orno\Http\Request;
|
||||
use \Orno\Http\Response;
|
||||
use \Orno\Http\JsonResponse;
|
||||
use \Orno\Http\Exception\NotFoundException;
|
||||
use \League\OAuth2\Server\ResourceServer;
|
||||
use \RelationalExample\Storage;
|
||||
use \RelationalExample\Model;
|
||||
|
||||
include __DIR__.'/vendor/autoload.php';
|
||||
|
||||
// Routing setup
|
||||
$request = (new Request)->createFromGlobals();
|
||||
$router = new \Orno\Route\RouteCollection;
|
||||
$router->setStrategy(\Orno\Route\RouteStrategyInterface::RESTFUL_STRATEGY);
|
||||
|
||||
// Set up the OAuth 2.0 resource server
|
||||
$sessionStorage = new Storage\SessionStorage();
|
||||
$accessTokenStorage = new Storage\AccessTokenStorage();
|
||||
$clientStorage = new Storage\ClientStorage();
|
||||
$scopeStorage = new Storage\ScopeStorage();
|
||||
|
||||
$server = new ResourceServer(
|
||||
$sessionStorage,
|
||||
$accessTokenStorage,
|
||||
$clientStorage,
|
||||
$scopeStorage
|
||||
);
|
||||
|
||||
$server->setRequest($request);
|
||||
|
||||
// Check that access token is present
|
||||
try {
|
||||
$server->isValidRequest(false);
|
||||
} catch (\League\OAuth2\Server\Exception\OAuthException $e) {
|
||||
|
||||
foreach ($e->getHttpHeaders() as $header) {
|
||||
header($header);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'error' => $e->errorType,
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
// GET /tokeninfo
|
||||
$router->get('/tokeninfo', function (Request $request) use ($server) {
|
||||
|
||||
$token = [
|
||||
'owner_id' => $server->getOwnerId(),
|
||||
'owner_type' => $server->getOwnerType(),
|
||||
'access_token' => $server->getAccessToken(),
|
||||
'client_id' => $server->getClientId(),
|
||||
'scopes' => $server->getScopes()
|
||||
];
|
||||
|
||||
return new JsonResponse($token);
|
||||
|
||||
});
|
||||
|
||||
// GET /users
|
||||
$router->get('/users', function (Request $request) use ($server) {
|
||||
|
||||
$results = (new Model\Users())->get();
|
||||
|
||||
$users = [];
|
||||
|
||||
foreach ($results as $result) {
|
||||
$user = [
|
||||
'username' => $result['username'],
|
||||
'name' => $result['name']
|
||||
];
|
||||
|
||||
if ($server->hasScope('email')) {
|
||||
$user['email'] = $result['email'];
|
||||
}
|
||||
|
||||
if ($server->hasScope('photo')) {
|
||||
$user['photo'] = $result['photo'];
|
||||
}
|
||||
|
||||
$users[] = $user;
|
||||
}
|
||||
|
||||
return new JsonResponse($users);
|
||||
});
|
||||
|
||||
// GET /users/{username}
|
||||
$router->get('/users/{username}', function (Request $request, $args) use ($server) {
|
||||
|
||||
$result = (new Model\Users())->get($args['username']);
|
||||
|
||||
if (count($result) === 0) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
$user = [
|
||||
'username' => $result[0]['username'],
|
||||
'name' => $result[0]['name']
|
||||
];
|
||||
|
||||
if ($server->hasScope('email')) {
|
||||
$user['email'] = $result[0]['email'];
|
||||
}
|
||||
|
||||
if ($server->hasScope('photo')) {
|
||||
$user['photo'] = $result[0]['photo'];
|
||||
}
|
||||
|
||||
return new JsonResponse($user);
|
||||
});
|
||||
|
||||
$dispatcher = $router->getDispatcher();
|
||||
$response = $dispatcher->dispatch($request->getMethod(), $request->getPathInfo());
|
||||
$response->send();
|
15
examples/relational/composer.json
Normal file
15
examples/relational/composer.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"require": {
|
||||
"illuminate/database": "4.1.*",
|
||||
"orno/route": "1.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"League\\OAuth2\\Server\\": "../../src/",
|
||||
"RelationalExample\\": "."
|
||||
},
|
||||
"files": [
|
||||
"config/db.php"
|
||||
]
|
||||
}
|
||||
}
|
559
examples/relational/composer.lock
generated
Normal file
559
examples/relational/composer.lock
generated
Normal file
@ -0,0 +1,559 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
|
||||
],
|
||||
"hash": "abcfdbc3594f0666218cab21fbbf0829",
|
||||
"packages": [
|
||||
{
|
||||
"name": "fzaninotto/faker",
|
||||
"version": "v1.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/fzaninotto/Faker.git",
|
||||
"reference": "1d143fd8caf4d264602450bc01d7484af788706b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/1d143fd8caf4d264602450bc01d7484af788706b",
|
||||
"reference": "1d143fd8caf4d264602450bc01d7484af788706b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.3.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Faker": "src/",
|
||||
"Faker\\PHPUnit": "test/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "François Zaninotto"
|
||||
}
|
||||
],
|
||||
"description": "Faker is a PHP library that generates fake data for you.",
|
||||
"keywords": [
|
||||
"data",
|
||||
"faker",
|
||||
"fixtures"
|
||||
],
|
||||
"time": "2013-12-16 21:56:48"
|
||||
},
|
||||
{
|
||||
"name": "illuminate/container",
|
||||
"version": "v4.1.28",
|
||||
"target-dir": "Illuminate/Container",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/illuminate/container.git",
|
||||
"reference": "51d590fd7e301f56c567459a26343a8288330f69"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/illuminate/container/zipball/51d590fd7e301f56c567459a26343a8288330f69",
|
||||
"reference": "51d590fd7e301f56c567459a26343a8288330f69",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "4.0.*"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.1-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Illuminate\\Container": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylorotwell@gmail.com",
|
||||
"homepage": "https://github.com/taylorotwell",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"time": "2014-03-22 20:29:54"
|
||||
},
|
||||
{
|
||||
"name": "illuminate/database",
|
||||
"version": "v4.1.28",
|
||||
"target-dir": "Illuminate/Database",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/illuminate/database.git",
|
||||
"reference": "c84f39734c6bfe7fbf694ff8dc33d15605553de2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/illuminate/database/zipball/c84f39734c6bfe7fbf694ff8dc33d15605553de2",
|
||||
"reference": "c84f39734c6bfe7fbf694ff8dc33d15605553de2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/container": "4.1.*",
|
||||
"illuminate/events": "4.1.*",
|
||||
"illuminate/support": "4.1.*",
|
||||
"nesbot/carbon": "1.*",
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"illuminate/cache": "4.1.*",
|
||||
"illuminate/console": "4.1.*",
|
||||
"illuminate/filesystem": "4.1.*",
|
||||
"illuminate/pagination": "4.1.*",
|
||||
"illuminate/support": "4.1.*",
|
||||
"mockery/mockery": "0.9.*",
|
||||
"phpunit/phpunit": "4.0.*"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.1-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Illuminate\\Database": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylorotwell@gmail.com",
|
||||
"homepage": "https://github.com/taylorotwell",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"keywords": [
|
||||
"database",
|
||||
"laravel",
|
||||
"orm",
|
||||
"sql"
|
||||
],
|
||||
"time": "2014-04-11 20:10:04"
|
||||
},
|
||||
{
|
||||
"name": "illuminate/events",
|
||||
"version": "v4.1.28",
|
||||
"target-dir": "Illuminate/Events",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/illuminate/events.git",
|
||||
"reference": "ef6ae5962134a35667f24349bc2c9b8ad1e20c8b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/illuminate/events/zipball/ef6ae5962134a35667f24349bc2c9b8ad1e20c8b",
|
||||
"reference": "ef6ae5962134a35667f24349bc2c9b8ad1e20c8b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/container": "4.1.*",
|
||||
"illuminate/support": "4.1.*",
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "0.9.*",
|
||||
"phpunit/phpunit": "4.0.*"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.1-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Illuminate\\Events": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylorotwell@gmail.com",
|
||||
"homepage": "https://github.com/taylorotwell",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"time": "2014-03-22 20:12:48"
|
||||
},
|
||||
{
|
||||
"name": "illuminate/support",
|
||||
"version": "v4.1.28",
|
||||
"target-dir": "Illuminate/Support",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/illuminate/support.git",
|
||||
"reference": "69b248f240719e8d764ee6ec0384819fa57d60bb"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/illuminate/support/zipball/69b248f240719e8d764ee6ec0384819fa57d60bb",
|
||||
"reference": "69b248f240719e8d764ee6ec0384819fa57d60bb",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"jeremeamia/superclosure": "1.0.*",
|
||||
"mockery/mockery": "0.9.*",
|
||||
"patchwork/utf8": "1.1.*",
|
||||
"phpunit/phpunit": "4.0.*"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.1-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Illuminate\\Support": ""
|
||||
},
|
||||
"files": [
|
||||
"Illuminate/Support/helpers.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylorotwell@gmail.com",
|
||||
"homepage": "https://github.com/taylorotwell",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"time": "2014-03-22 20:29:54"
|
||||
},
|
||||
{
|
||||
"name": "nesbot/carbon",
|
||||
"version": "1.8.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/briannesbitt/Carbon.git",
|
||||
"reference": "21c4cb4301969c7d85aee8a62eefdfa881413af0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/21c4cb4301969c7d85aee8a62eefdfa881413af0",
|
||||
"reference": "21c4cb4301969c7d85aee8a62eefdfa881413af0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "3.7.*"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Carbon": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Brian Nesbitt",
|
||||
"email": "brian@nesbot.com",
|
||||
"homepage": "http://nesbot.com"
|
||||
}
|
||||
],
|
||||
"description": "A simple API extension for DateTime.",
|
||||
"homepage": "https://github.com/briannesbitt/Carbon",
|
||||
"keywords": [
|
||||
"date",
|
||||
"datetime",
|
||||
"time"
|
||||
],
|
||||
"time": "2014-01-07 05:10:44"
|
||||
},
|
||||
{
|
||||
"name": "nikic/fast-route",
|
||||
"version": "v0.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nikic/FastRoute.git",
|
||||
"reference": "29c5bf70254d8ce59414646de3e9e43aafc9735e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/nikic/FastRoute/zipball/29c5bf70254d8ce59414646de3e9e43aafc9735e",
|
||||
"reference": "29c5bf70254d8ce59414646de3e9e43aafc9735e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/bootstrap.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nikita Popov",
|
||||
"email": "nikic@php.net"
|
||||
}
|
||||
],
|
||||
"description": "Fast request router for PHP",
|
||||
"keywords": [
|
||||
"router",
|
||||
"routing"
|
||||
],
|
||||
"time": "2014-03-04 15:05:38"
|
||||
},
|
||||
{
|
||||
"name": "orno/di",
|
||||
"version": "v2.0.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/orno/di.git",
|
||||
"reference": "e8d29523da316125e67a6d39d477da90dc7be656"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/orno/di/zipball/e8d29523da316125e67a6d39d477da90dc7be656",
|
||||
"reference": "e8d29523da316125e67a6d39d477da90dc7be656",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4"
|
||||
},
|
||||
"suggest": {
|
||||
"orno/cache": "Enables caching of reflection based resolution",
|
||||
"orno/config": "Allows useage of config files rather than interacting with the container directly"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Orno\\Di": "src/",
|
||||
"OrnoTest": "tests/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Phil Bennett",
|
||||
"email": "philipobenito@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "Orno Di is a small but powerful dependency injection container with automatic resolution of dependencies.",
|
||||
"keywords": [
|
||||
"container",
|
||||
"dependency",
|
||||
"di",
|
||||
"injection",
|
||||
"orno"
|
||||
],
|
||||
"time": "2014-04-03 08:23:38"
|
||||
},
|
||||
{
|
||||
"name": "orno/http",
|
||||
"version": "v1.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/orno/http.git",
|
||||
"reference": "65d37f6f92f3357c234a592fdd57b2f54c2ef514"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/orno/http/zipball/65d37f6f92f3357c234a592fdd57b2f54c2ef514",
|
||||
"reference": "65d37f6f92f3357c234a592fdd57b2f54c2ef514",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4",
|
||||
"symfony/http-foundation": "2.*"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Orno\\Http\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Phil Bennett",
|
||||
"email": "philipobenito@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "A wrapper for Symfony\\HttpFoundation with some encapsulation and convenience methods.",
|
||||
"homepage": "http://github.com/orno/http",
|
||||
"keywords": [
|
||||
"http",
|
||||
"orno",
|
||||
"request",
|
||||
"response"
|
||||
],
|
||||
"time": "2014-03-05 10:22:10"
|
||||
},
|
||||
{
|
||||
"name": "orno/route",
|
||||
"version": "v1.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/orno/route.git",
|
||||
"reference": "af2aee8314e6e700b4d69dc61f5c67ae030741e9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/orno/route/zipball/af2aee8314e6e700b4d69dc61f5c67ae030741e9",
|
||||
"reference": "af2aee8314e6e700b4d69dc61f5c67ae030741e9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"nikic/fast-route": "0.1.*",
|
||||
"orno/di": "2.*",
|
||||
"orno/http": "1.*",
|
||||
"php": ">=5.4"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Orno\\Route\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Phil Bennett",
|
||||
"email": "hello@happyaccidents.me"
|
||||
}
|
||||
],
|
||||
"description": "Fast routing package combining Nikita Popov's FastRoute and Orno\\Di to provide route dispatching to dependency injected controllers.",
|
||||
"keywords": [
|
||||
"FastRoute",
|
||||
"di",
|
||||
"dispatcher",
|
||||
"orno",
|
||||
"route"
|
||||
],
|
||||
"time": "2014-04-13 13:46:11"
|
||||
},
|
||||
{
|
||||
"name": "symfony/http-foundation",
|
||||
"version": "v2.4.4",
|
||||
"target-dir": "Symfony/Component/HttpFoundation",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/HttpFoundation.git",
|
||||
"reference": "22c4dee84271ad0cd08d19f26d89f2878e11159b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/22c4dee84271ad0cd08d19f26d89f2878e11159b",
|
||||
"reference": "22c4dee84271ad0cd08d19f26d89f2878e11159b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/expression-language": "~2.4"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Symfony\\Component\\HttpFoundation\\": ""
|
||||
},
|
||||
"classmap": [
|
||||
"Symfony/Component/HttpFoundation/Resources/stubs"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com",
|
||||
"homepage": "http://fabien.potencier.org",
|
||||
"role": "Lead Developer"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "http://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony HttpFoundation Component",
|
||||
"homepage": "http://symfony.com",
|
||||
"time": "2014-04-18 21:02:05"
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
|
||||
],
|
||||
"aliases": [
|
||||
|
||||
],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [
|
||||
|
||||
],
|
||||
"platform": [
|
||||
|
||||
],
|
||||
"platform-dev": [
|
||||
|
||||
]
|
||||
}
|
18
examples/relational/config/db.php
Normal file
18
examples/relational/config/db.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace RelationalExample\Config;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
include __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
$capsule = new Capsule;
|
||||
|
||||
$capsule->addConnection([
|
||||
'driver' => 'sqlite',
|
||||
'database' => __DIR__.'/oauth2.sqlite3',
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci'
|
||||
]);
|
||||
|
||||
$capsule->setAsGlobal();
|
235
examples/relational/config/init.php
Normal file
235
examples/relational/config/init.php
Normal file
@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
namespace RelationalExample\Config;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
include __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
@unlink(__DIR__.'/oauth2.sqlite3');
|
||||
touch(__DIR__.'/oauth2.sqlite3');
|
||||
|
||||
Capsule::statement('PRAGMA foreign_keys = ON');
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
print 'Creating users table'.PHP_EOL;
|
||||
|
||||
Capsule::schema()->create('users', function ($table) {
|
||||
$table->increments('id');
|
||||
$table->string('username');
|
||||
$table->string('password');
|
||||
$table->string('name');
|
||||
$table->string('email');
|
||||
$table->string('photo');
|
||||
});
|
||||
|
||||
Capsule::table('users')->insert([
|
||||
'username' => 'alexbilbie',
|
||||
'password' => password_hash('whisky', PASSWORD_DEFAULT),
|
||||
'name' => 'Alex Bilbie',
|
||||
'email' => 'hello@alexbilbie.com',
|
||||
'photo' => 'https://s.gravatar.com/avatar/14902eb1dac66b8458ebbb481d80f0a3'
|
||||
]);
|
||||
|
||||
Capsule::table('users')->insert([
|
||||
'username' => 'philsturgeon',
|
||||
'password' => password_hash('cider', PASSWORD_DEFAULT),
|
||||
'name' => 'Phil Sturgeon',
|
||||
'email' => 'email@philsturgeon.co.uk',
|
||||
'photo' => 'https://s.gravatar.com/avatar/14df293d6c5cd6f05996dfc606a6a951'
|
||||
]);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
print 'Creating clients table'.PHP_EOL;
|
||||
|
||||
Capsule::schema()->create('oauth_clients', function ($table) {
|
||||
$table->string('id');
|
||||
$table->string('secret');
|
||||
$table->string('name');
|
||||
$table->primary('id');
|
||||
});
|
||||
|
||||
Capsule::table('oauth_clients')->insert([
|
||||
'id' => 'testclient',
|
||||
'secret' => 'secret',
|
||||
'name' => 'Test Client'
|
||||
]);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
print 'Creating scopes table'.PHP_EOL;
|
||||
|
||||
Capsule::schema()->create('oauth_scopes', function ($table) {
|
||||
$table->string('id');
|
||||
$table->string('description');
|
||||
$table->primary('id');
|
||||
});
|
||||
|
||||
Capsule::table('oauth_scopes')->insert([
|
||||
'id' => 'basic',
|
||||
'description' => 'Basic details about your account'
|
||||
]);
|
||||
|
||||
Capsule::table('oauth_scopes')->insert([
|
||||
'id' => 'email',
|
||||
'description' => 'Your email address'
|
||||
]);
|
||||
|
||||
Capsule::table('oauth_scopes')->insert([
|
||||
'id' => 'photo',
|
||||
'description' => 'Your photo'
|
||||
]);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
print 'Creating sessions table'.PHP_EOL;
|
||||
|
||||
Capsule::schema()->create('oauth_sessions', function ($table) {
|
||||
$table->increments('id');
|
||||
$table->string('owner_type');
|
||||
$table->string('owner_id');
|
||||
$table->string('client_id');
|
||||
$table->string('client_redirect_uri')->nullable();
|
||||
|
||||
$table->foreign('client_id')->references('id')->on('oauth_clients')->onDelete('cascade');
|
||||
});
|
||||
|
||||
Capsule::table('oauth_sessions')->insert([
|
||||
'owner_type' => 'client',
|
||||
'owner_id' => 'testclient',
|
||||
'client_id' => 'testclient'
|
||||
]);
|
||||
|
||||
Capsule::table('oauth_sessions')->insert([
|
||||
'owner_type' => 'user',
|
||||
'owner_id' => '1',
|
||||
'client_id' => 'testclient'
|
||||
]);
|
||||
|
||||
Capsule::table('oauth_sessions')->insert([
|
||||
'owner_type' => 'user',
|
||||
'owner_id' => '2',
|
||||
'client_id' => 'testclient'
|
||||
]);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
print 'Creating access tokens table'.PHP_EOL;
|
||||
|
||||
Capsule::schema()->create('oauth_access_tokens', function ($table) {
|
||||
$table->string('access_token')->primary();
|
||||
$table->integer('session_id');
|
||||
$table->integer('expire_time');
|
||||
|
||||
$table->foreign('session_id')->references('id')->on('oauth_sessions')->onDelete('cascade');
|
||||
});
|
||||
|
||||
Capsule::table('oauth_access_tokens')->insert([
|
||||
'access_token' => 'iamgod',
|
||||
'session_id' => '1',
|
||||
'expire_time' => time() + 86400
|
||||
]);
|
||||
|
||||
Capsule::table('oauth_access_tokens')->insert([
|
||||
'access_token' => 'iamalex',
|
||||
'session_id' => '2',
|
||||
'expire_time' => time() + 86400
|
||||
]);
|
||||
|
||||
Capsule::table('oauth_access_tokens')->insert([
|
||||
'access_token' => 'iamphil',
|
||||
'session_id' => '3',
|
||||
'expire_time' => time() + 86400
|
||||
]);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
print 'Creating refresh tokens table'.PHP_EOL;
|
||||
|
||||
Capsule::schema()->create('oauth_refresh_tokens', function ($table) {
|
||||
$table->string('refresh_token')->primary();
|
||||
$table->integer('session_id');
|
||||
$table->integer('expire_time');
|
||||
$table->string('access_token');
|
||||
|
||||
$table->foreign('session_id')->references('id')->on('oauth_sessions')->onDelete('cascade');
|
||||
$table->foreign('access_token')->references('id')->on('oauth_access_tokens')->onDelete('cascade');
|
||||
});
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
print 'Creating auth codes table'.PHP_EOL;
|
||||
|
||||
Capsule::schema()->create('oauth_auth_codes', function ($table) {
|
||||
$table->string('auth_code')->primary();
|
||||
$table->integer('session_id');
|
||||
$table->integer('expire_time');
|
||||
|
||||
$table->foreign('session_id')->references('id')->on('oauth_sessions')->onDelete('cascade');
|
||||
});
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
print 'Creating oauth access token scopes table'.PHP_EOL;
|
||||
|
||||
Capsule::schema()->create('oauth_access_token_scopes', function ($table) {
|
||||
$table->increments('id');
|
||||
$table->string('access_token');
|
||||
$table->string('scope');
|
||||
|
||||
$table->foreign('access_token')->references('access_token')->on('oauth_access_tokens')->onDelete('cascade');
|
||||
$table->foreign('scope')->references('id')->on('oauth_scopes')->onDelete('cascade');
|
||||
});
|
||||
|
||||
Capsule::table('oauth_access_token_scopes')->insert([
|
||||
'access_token' => 'iamgod',
|
||||
'scope' => 'basic'
|
||||
]);
|
||||
|
||||
Capsule::table('oauth_access_token_scopes')->insert([
|
||||
'access_token' => 'iamgod',
|
||||
'scope' => 'email'
|
||||
]);
|
||||
|
||||
Capsule::table('oauth_access_token_scopes')->insert([
|
||||
'access_token' => 'iamgod',
|
||||
'scope' => 'photo'
|
||||
]);
|
||||
|
||||
Capsule::table('oauth_access_token_scopes')->insert([
|
||||
'access_token' => 'iamphil',
|
||||
'scope' => 'email'
|
||||
]);
|
||||
|
||||
Capsule::table('oauth_access_token_scopes')->insert([
|
||||
'access_token' => 'iamalex',
|
||||
'scope' => 'photo'
|
||||
]);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
print 'Creating oauth auth code scopes table'.PHP_EOL;
|
||||
|
||||
Capsule::schema()->create('oauth_auth_code_scopes', function ($table) {
|
||||
$table->increments('id');
|
||||
$table->string('auth_code');
|
||||
$table->string('scope');
|
||||
|
||||
$table->foreign('auth_code')->references('auth_code')->on('oauth_auth_codes')->onDelete('cascade');
|
||||
$table->foreign('scope')->references('id')->on('oauth_scopes')->onDelete('cascade');
|
||||
});
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
print 'Creating oauth session scopes table'.PHP_EOL;
|
||||
|
||||
Capsule::schema()->create('oauth_session_scopes', function ($table) {
|
||||
$table->increments('id');
|
||||
$table->string('session_id');
|
||||
$table->string('scope');
|
||||
|
||||
$table->foreign('session_id')->references('id')->on('oauth_sessions')->onDelete('cascade');
|
||||
$table->foreign('scope')->references('id')->on('oauth_scopes')->onDelete('cascade');
|
||||
});
|
@ -11,7 +11,7 @@
|
||||
</whitelist>
|
||||
</filter>
|
||||
<logging>
|
||||
<log type="coverage-text" target="php://stdout" title="thephpleague/oauth2-server" charset="UTF-8" yui="true" highlight="true" lowUpperBound="60" highLowerBound="90"/>
|
||||
<!-- <log type="coverage-text" target="php://stdout" title="thephpleague/oauth2-server" charset="UTF-8" yui="true" highlight="true" lowUpperBound="60" highLowerBound="90"/> -->
|
||||
<log type="coverage-html" target="build/coverage" title="thephpleague/oauth2-server" charset="UTF-8" yui="true" highlight="true" lowUpperBound="60" highLowerBound="90"/>
|
||||
</logging>
|
||||
</phpunit>
|
||||
|
Loading…
Reference in New Issue
Block a user