From e3fd4a62d9b23b121038b8b2e6f910f557d31e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=84kwav?= Date: Sun, 2 Jul 2017 13:23:12 +0200 Subject: [PATCH] Fallowed the advises given by @Malou https://github.com/Ekwav/UF_OAUTH2-SERVER/commit/0aa946a4363317004146aac97b58a50f86e78dd4 --- composer.json | 6 +++--- routes/routes.php | 20 +++++++++---------- src/Controller/ApiAuthController.php | 12 +++++------ .../v002/OAuthPersonalAccessClients.php | 2 +- .../Migrations/v002/OauthAccessTokens.php | 2 +- .../Migrations/v002/OauthAuthCodes.php | 2 +- src/Database/Migrations/v002/OauthClients.php | 2 +- .../Migrations/v002/OauthRefreshTokens.php | 2 +- src/Database/Migrations/v002/OauthScopes.php | 4 ++-- src/Database/Models/OauthClients.php | 2 +- src/Database/Models/Scopes.php | 2 +- src/Database/Models/apps.php | 2 +- src/Database/Models/tokens.php | 2 +- src/OAuth2/AccessTokenEntity.php | 4 ++-- src/OAuth2/AccessTokenRepository.php | 6 +++--- src/OAuth2/AuthCodeEntity.php | 4 ++-- src/OAuth2/AuthCodeRepository.php | 6 +++--- src/OAuth2/ClientEntity.php | 4 ++-- src/OAuth2/ClientRepository.php | 4 ++-- src/OAuth2/ImplicitGrant.php | 6 +++--- src/OAuth2/RefreshTokenEntity.php | 4 ++-- src/OAuth2/RefreshTokenRepository.php | 6 +++--- src/OAuth2/ScopeEntity.php | 4 ++-- src/OAuth2/ScopeRepository.php | 10 +++++----- src/OAuth2/UserEntity.php | 6 +++--- src/OAuth2/UserRepository.php | 6 +++--- src/ServicesProvider/ServicesProvider.php | 20 +++++++++---------- 27 files changed, 75 insertions(+), 75 deletions(-) diff --git a/composer.json b/composer.json index 3638001..76c0435 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "ekwav/uf_oauth2_server", - "type": "sprinkle", + "type": "userfrosting-sprinkle", "description": "OAuth2 Api module for UserFrosting.", "keywords": ["OAuth2", "Server", "userfrosting"], "homepage": "https://github.com/Ekwav/UF_OAUTH2-SERVER", @@ -17,10 +17,10 @@ }, "autoload": { "psr-4": { - "UserFrosting\\Sprinkle\\Api\\": "src/" + "UserFrosting\\Sprinkle\\OAuth2Server\\": "src/" } }, "extra": { - "installer-name": "Api" + "installer-name": "OAuth2Server" } } diff --git a/routes/routes.php b/routes/routes.php index 312a96f..8bd8bd3 100644 --- a/routes/routes.php +++ b/routes/routes.php @@ -3,23 +3,23 @@ use League\OAuth2\Server\Middleware\ResourceServerMiddleware; -$app->get('/authorize/{client_id}/{response_type}/{scope}', 'UserFrosting\Sprinkle\Api\Controller\ApiAuthController:authorizePage')->add('authGuard'); -$app->get('/oauth', 'UserFrosting\Sprinkle\Api\Controller\ApiAuthController:authorizePage')->add('authGuard'); -$app->get('/finish_authorize', 'UserFrosting\Sprinkle\Api\Controller\ApiAuthController:finish_authorize')->add('authGuard'); +$app->get('/authorize/{client_id}/{response_type}/{scope}', 'UserFrosting\Sprinkle\OAuth2Server\Controller\ApiAuthController:authorizePage')->add('authGuard'); +$app->get('/oauth', 'UserFrosting\Sprinkle\OAuth2Server\Controller\ApiAuthController:authorizePage')->add('authGuard'); +$app->get('/finish_authorize', 'UserFrosting\Sprinkle\OAuth2Server\Controller\ApiAuthController:finish_authorize')->add('authGuard'); -//$app->get('/oauth2/change', 'UserFrosting\Sprinkle\Api\Controller\ApiAuthController:oAuth2ChangeRequest'); -$app->get('/apps', 'UserFrosting\Sprinkle\Api\Controller\ApiAuthController:renderClients')->add('authGuard'); -$app->get('/app/new', 'UserFrosting\Sprinkle\Api\Controller\ApiAuthController:renderAddNewClient')->add('authGuard'); -//$app->get('/app/new/scope', 'UserFrosting\Sprinkle\Api\Controller\ApiAuthController:newScope'); +//$app->get('/oauth2/change', 'UserFrosting\Sprinkle\OAuth2Server\Controller\ApiAuthController:oAuth2ChangeRequest'); +$app->get('/apps', 'UserFrosting\Sprinkle\OAuth2Server\Controller\ApiAuthController:renderClients')->add('authGuard'); +$app->get('/app/new', 'UserFrosting\Sprinkle\OAuth2Server\Controller\ApiAuthController:renderAddNewClient')->add('authGuard'); +//$app->get('/app/new/scope', 'UserFrosting\Sprinkle\OAuth2Server\Controller\ApiAuthController:newScope'); -$app->post('/authorize_vertify', 'UserFrosting\Sprinkle\Api\Controller\ApiAuthController:validateAuthRequest')->add('authGuard'); -$app->post('/app/new', 'UserFrosting\Sprinkle\Api\Controller\ApiAuthController:addNewClient')->add('authGuard'); +$app->post('/authorize_vertify', 'UserFrosting\Sprinkle\OAuth2Server\Controller\ApiAuthController:validateAuthRequest')->add('authGuard'); +$app->post('/app/new', 'UserFrosting\Sprinkle\OAuth2Server\Controller\ApiAuthController:addNewClient')->add('authGuard'); // This is a test api endpoint to try it :) // IMPORTANT! YOU NEED TO ADD ALL YOUR API ENDPOINTS TO THE CSRF.BLACKLIST IN YOUR config file // OTHERWISE THE CSRF MIDDLEWARE WILL BLOCK THEM! You can find an example in the README -$app->post('/api/userinfo', 'UserFrosting\Sprinkle\Api\Controller\ApiAuthController:getUserInfo')->add(new ResourceServerMiddleware($this->ci->ResourceServer)); +$app->post('/api/userinfo', 'UserFrosting\Sprinkle\OAuth2Server\Controller\ApiAuthController:getUserInfo')->add(new ResourceServerMiddleware($this->ci->ResourceServer)); ?> diff --git a/src/Controller/ApiAuthController.php b/src/Controller/ApiAuthController.php index cfe7a62..ee4e56d 100644 --- a/src/Controller/ApiAuthController.php +++ b/src/Controller/ApiAuthController.php @@ -6,18 +6,18 @@ * @copyright Copyright (c) 2017 Ekwav (Coflnet) * @license -ask me if you want to distribute my code, only thing that you are not allowed to chang is the Powered by Coflnet :) */ -namespace UserFrosting\Sprinkle\Api\Controller; +namespace UserFrosting\Sprinkle\OAuth2Server\Controller; use UserFrosting\Sprinkle\Core\Controller\SimpleController; use League\OAuth2\Server\Exception\OAuthServerException; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use UserFrosting\Sprinkle\Api\OAuth2\RefreshTokenRepository; -use UserFrosting\Sprinkle\Api\OAuth2\UserRepository; -use UserFrosting\Sprinkle\Api\OAuth2\UserEntity; +use UserFrosting\Sprinkle\OAuth2Server\OAuth2\RefreshTokenRepository; +use UserFrosting\Sprinkle\OAuth2Server\OAuth2\UserRepository; +use UserFrosting\Sprinkle\OAuth2Server\OAuth2\UserEntity; use UserFrosting\Sprinkle\Core\Facades\Debug; -use UserFrosting\Sprinkle\Api\Database\Models\Scopes; -use UserFrosting\Sprinkle\Api\Database\Models\OauthClients; +use UserFrosting\Sprinkle\OAuth2Server\Database\Models\Scopes; +use UserFrosting\Sprinkle\OAuth2Server\Database\Models\OauthClients; use UserFrosting\Fortress\RequestDataTransformer; use UserFrosting\Fortress\RequestSchema; use UserFrosting\Fortress\ServerSideValidator; diff --git a/src/Database/Migrations/v002/OAuthPersonalAccessClients.php b/src/Database/Migrations/v002/OAuthPersonalAccessClients.php index 0785829..f1355a5 100644 --- a/src/Database/Migrations/v002/OAuthPersonalAccessClients.php +++ b/src/Database/Migrations/v002/OAuthPersonalAccessClients.php @@ -4,7 +4,7 @@ * * @link https://github.com/Ekwav/UF_OAUTH2-SERVER */ -namespace UserFrosting\Sprinkle\Api\Database\Migrations\v002; +namespace UserFrosting\Sprinkle\OAuth2Server\Database\Migrations\v002; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; diff --git a/src/Database/Migrations/v002/OauthAccessTokens.php b/src/Database/Migrations/v002/OauthAccessTokens.php index d91253f..7514afa 100644 --- a/src/Database/Migrations/v002/OauthAccessTokens.php +++ b/src/Database/Migrations/v002/OauthAccessTokens.php @@ -4,7 +4,7 @@ * * @link https://github.com/Ekwav/UF_OAUTH2-SERVER */ -namespace UserFrosting\Sprinkle\Api\Database\Migrations\v002; +namespace UserFrosting\Sprinkle\OAuth2Server\Database\Migrations\v002; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; diff --git a/src/Database/Migrations/v002/OauthAuthCodes.php b/src/Database/Migrations/v002/OauthAuthCodes.php index 1716170..7786405 100644 --- a/src/Database/Migrations/v002/OauthAuthCodes.php +++ b/src/Database/Migrations/v002/OauthAuthCodes.php @@ -4,7 +4,7 @@ * * @link https://github.com/Ekwav/UF_OAUTH2-SERVER */ -namespace UserFrosting\Sprinkle\Api\Database\Migrations\v002; +namespace UserFrosting\Sprinkle\OAuth2Server\Database\Migrations\v002; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; diff --git a/src/Database/Migrations/v002/OauthClients.php b/src/Database/Migrations/v002/OauthClients.php index e978471..02e8377 100644 --- a/src/Database/Migrations/v002/OauthClients.php +++ b/src/Database/Migrations/v002/OauthClients.php @@ -4,7 +4,7 @@ * * @link https://github.com/Ekwav/UF_OAUTH2-SERVER */ -namespace UserFrosting\Sprinkle\Api\Database\Migrations\v002; +namespace UserFrosting\Sprinkle\OAuth2Server\Database\Migrations\v002; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; diff --git a/src/Database/Migrations/v002/OauthRefreshTokens.php b/src/Database/Migrations/v002/OauthRefreshTokens.php index bcfcd44..10bb055 100644 --- a/src/Database/Migrations/v002/OauthRefreshTokens.php +++ b/src/Database/Migrations/v002/OauthRefreshTokens.php @@ -4,7 +4,7 @@ * * @link https://github.com/Ekwav/UF_OAUTH2-SERVER */ -namespace UserFrosting\Sprinkle\Api\Database\Migrations\v002; +namespace UserFrosting\Sprinkle\OAuth2Server\Database\Migrations\v002; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; diff --git a/src/Database/Migrations/v002/OauthScopes.php b/src/Database/Migrations/v002/OauthScopes.php index 03cffee..354da49 100644 --- a/src/Database/Migrations/v002/OauthScopes.php +++ b/src/Database/Migrations/v002/OauthScopes.php @@ -4,12 +4,12 @@ * * @link https://github.com/Ekwav/UF_OAUTH2-SERVER */ -namespace UserFrosting\Sprinkle\Api\Database\Migrations\v002; +namespace UserFrosting\Sprinkle\OAuth2Server\Database\Migrations\v002; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Builder; use UserFrosting\System\Bakery\Migration; -use UserFrosting\Sprinkle\Api\Database\Models\Scopes; +use UserFrosting\Sprinkle\OAuth2Server\Database\Models\Scopes; /** * Scopes table migration diff --git a/src/Database/Models/OauthClients.php b/src/Database/Models/OauthClients.php index 58a3e74..d0375a3 100644 --- a/src/Database/Models/OauthClients.php +++ b/src/Database/Models/OauthClients.php @@ -1,5 +1,5 @@ setUserIdentifier($userIdentifier); return $accessToken; } -} \ No newline at end of file +} diff --git a/src/OAuth2/AuthCodeEntity.php b/src/OAuth2/AuthCodeEntity.php index efd2734..f0ec6f5 100644 --- a/src/OAuth2/AuthCodeEntity.php +++ b/src/OAuth2/AuthCodeEntity.php @@ -6,7 +6,7 @@ * * @link https://github.com/thephpleague/oauth2-server */ -namespace UserFrosting\Sprinkle\Api\OAuth2; +namespace UserFrosting\Sprinkle\OAuth2Server\OAuth2; use League\OAuth2\Server\Entities\AuthCodeEntityInterface; use League\OAuth2\Server\Entities\Traits\AuthCodeTrait; use League\OAuth2\Server\Entities\Traits\EntityTrait; @@ -14,4 +14,4 @@ class AuthCodeEntity implements AuthCodeEntityInterface { use EntityTrait, TokenEntityTrait, AuthCodeTrait; -} \ No newline at end of file +} diff --git a/src/OAuth2/AuthCodeRepository.php b/src/OAuth2/AuthCodeRepository.php index 6f856ee..fde38bf 100644 --- a/src/OAuth2/AuthCodeRepository.php +++ b/src/OAuth2/AuthCodeRepository.php @@ -6,10 +6,10 @@ * * @link https://github.com/thephpleague/oauth2-server */ -namespace UserFrosting\Sprinkle\Api\OAuth2; +namespace UserFrosting\Sprinkle\OAuth2Server\OAuth2; use League\OAuth2\Server\Entities\AuthCodeEntityInterface; use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface; -use UserFrosting\Sprinkle\Api\OAuth2\AuthCodeEntity; +use UserFrosting\Sprinkle\OAuth2Server\OAuth2\AuthCodeEntity; class AuthCodeRepository implements AuthCodeRepositoryInterface { /** @@ -40,4 +40,4 @@ public function getNewAuthCode() { return new AuthCodeEntity(); } -} \ No newline at end of file +} diff --git a/src/OAuth2/ClientEntity.php b/src/OAuth2/ClientEntity.php index 969ba00..c175d17 100644 --- a/src/OAuth2/ClientEntity.php +++ b/src/OAuth2/ClientEntity.php @@ -6,7 +6,7 @@ * * @link https://github.com/thephpleague/oauth2-server */ -namespace UserFrosting\Sprinkle\Api\OAuth2; +namespace UserFrosting\Sprinkle\OAuth2Server\OAuth2; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\Traits\ClientTrait; use League\OAuth2\Server\Entities\Traits\EntityTrait; @@ -21,4 +21,4 @@ public function setRedirectUri($uri) { $this->redirectUri = $uri; } -} \ No newline at end of file +} diff --git a/src/OAuth2/ClientRepository.php b/src/OAuth2/ClientRepository.php index 071a388..f48d21d 100644 --- a/src/OAuth2/ClientRepository.php +++ b/src/OAuth2/ClientRepository.php @@ -6,9 +6,9 @@ * * @link https://github.com/thephpleague/oauth2-server */ -namespace UserFrosting\Sprinkle\Api\OAuth2; +namespace UserFrosting\Sprinkle\OAuth2Server\OAuth2; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; -use UserFrosting\Sprinkle\Api\OAuth2\ClientEntity; +use UserFrosting\Sprinkle\OAuth2Server\OAuth2\ClientEntity; class ClientRepository implements ClientRepositoryInterface { /** diff --git a/src/OAuth2/ImplicitGrant.php b/src/OAuth2/ImplicitGrant.php index 067356c..0c1f5a2 100644 --- a/src/OAuth2/ImplicitGrant.php +++ b/src/OAuth2/ImplicitGrant.php @@ -7,7 +7,7 @@ * @link https://github.com/thephpleague/oauth2-server */ -namespace UserFrosting\Sprinkle\Api\OAuth2; +namespace UserFrosting\Sprinkle\OAuth2Server\OAuth2; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\UserEntityInterface; @@ -132,13 +132,13 @@ public function validateAuthorizationRequest(ServerRequestInterface $request) if ( is_string($client->getRedirectUri()) && (strcmp($client->getRedirectUri(), $redirectUri) !== 0) - ) { + ) { $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request)); throw OAuthServerException::invalidClient(); } elseif ( is_array($client->getRedirectUri()) && in_array($redirectUri, $client->getRedirectUri()) === false - ) { + ) { $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request)); throw OAuthServerException::invalidClient(); } diff --git a/src/OAuth2/RefreshTokenEntity.php b/src/OAuth2/RefreshTokenEntity.php index 79e7774..d534e42 100644 --- a/src/OAuth2/RefreshTokenEntity.php +++ b/src/OAuth2/RefreshTokenEntity.php @@ -6,11 +6,11 @@ * * @link https://github.com/thephpleague/oauth2-server */ -namespace UserFrosting\Sprinkle\Api\OAuth2; +namespace UserFrosting\Sprinkle\OAuth2Server\OAuth2; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; use League\OAuth2\Server\Entities\Traits\EntityTrait; use League\OAuth2\Server\Entities\Traits\RefreshTokenTrait; class RefreshTokenEntity implements RefreshTokenEntityInterface { use RefreshTokenTrait, EntityTrait; -} \ No newline at end of file +} diff --git a/src/OAuth2/RefreshTokenRepository.php b/src/OAuth2/RefreshTokenRepository.php index 4186c59..e2939e7 100644 --- a/src/OAuth2/RefreshTokenRepository.php +++ b/src/OAuth2/RefreshTokenRepository.php @@ -7,11 +7,11 @@ * @link https://github.com/thephpleague/oauth2-server */ -namespace UserFrosting\Sprinkle\Api\OAuth2; +namespace UserFrosting\Sprinkle\OAuth2Server\OAuth2; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; -use UserFrosting\Sprinkle\Api\OAuth2\RefreshTokenEntity; +use UserFrosting\Sprinkle\OAuth2Server\OAuth2\RefreshTokenEntity; class RefreshTokenRepository implements RefreshTokenRepositoryInterface { @@ -46,4 +46,4 @@ public function getNewRefreshToken() { return new RefreshTokenEntity(); } -} \ No newline at end of file +} diff --git a/src/OAuth2/ScopeEntity.php b/src/OAuth2/ScopeEntity.php index c4613f7..b5d6036 100644 --- a/src/OAuth2/ScopeEntity.php +++ b/src/OAuth2/ScopeEntity.php @@ -6,7 +6,7 @@ * * @link https://github.com/thephpleague/oauth2-server */ -namespace UserFrosting\Sprinkle\Api\OAuth2; +namespace UserFrosting\Sprinkle\OAuth2Server\OAuth2; use League\OAuth2\Server\Entities\ScopeEntityInterface; use League\OAuth2\Server\Entities\Traits\EntityTrait; class ScopeEntity implements ScopeEntityInterface @@ -16,4 +16,4 @@ public function jsonSerialize() { return $this->getIdentifier(); } -} \ No newline at end of file +} diff --git a/src/OAuth2/ScopeRepository.php b/src/OAuth2/ScopeRepository.php index 4628e87..1ce9c54 100644 --- a/src/OAuth2/ScopeRepository.php +++ b/src/OAuth2/ScopeRepository.php @@ -7,11 +7,11 @@ * @link https://github.com/thephpleague/oauth2-server */ -namespace UserFrosting\Sprinkle\Api\OAuth2; +namespace UserFrosting\Sprinkle\OAuth2Server\OAuth2; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; -use UserFrosting\Sprinkle\Api\OAuth2\ScopeEntity; +use UserFrosting\Sprinkle\OAuth2Server\OAuth2\ScopeEntity; use UserFrosting\Sprinkle\Core\Facades\Debug; class ScopeRepository implements ScopeRepositoryInterface @@ -28,8 +28,8 @@ public function __construct($scope) } array_flip($scopes); } - - + + public function getScopeEntityByIdentifier($scopeIdentifier) { $scope = new ScopeEntity(); @@ -56,4 +56,4 @@ public function finalizeScopes( return $scopes; } -} \ No newline at end of file +} diff --git a/src/OAuth2/UserEntity.php b/src/OAuth2/UserEntity.php index 5970b2b..e4311b8 100644 --- a/src/OAuth2/UserEntity.php +++ b/src/OAuth2/UserEntity.php @@ -6,7 +6,7 @@ * * @link https://github.com/thephpleague/oauth2-server */ -namespace UserFrosting\Sprinkle\Api\OAuth2; +namespace UserFrosting\Sprinkle\OAuth2Server\OAuth2; use League\OAuth2\Server\Entities\UserEntityInterface; use Interop\Container\ContainerInterface; use Illuminate\Database\Capsule\Manager as Capsule; @@ -46,9 +46,9 @@ public function __construct($userID) { $this->userID = $userID; } - + public function getIdentifier() { return $this->userID; } -} \ No newline at end of file +} diff --git a/src/OAuth2/UserRepository.php b/src/OAuth2/UserRepository.php index 1a659ee..5cf0f54 100644 --- a/src/OAuth2/UserRepository.php +++ b/src/OAuth2/UserRepository.php @@ -7,11 +7,11 @@ * @link https://github.com/thephpleague/oauth2-server */ -namespace UserFrosting\Sprinkle\Api\OAuth2; +namespace UserFrosting\Sprinkle\OAuth2Server\OAuth2; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Repositories\UserRepositoryInterface; -use UserFrosting\Sprinkle\Api\OAuth2\UserEntity; +use UserFrosting\Sprinkle\OAuth2Server\OAuth2\UserEntity; class UserRepository implements UserRepositoryInterface { @@ -30,4 +30,4 @@ public function getUserEntityByUserCredentials( return; } -} \ No newline at end of file +} diff --git a/src/ServicesProvider/ServicesProvider.php b/src/ServicesProvider/ServicesProvider.php index 0354827..0c8e1e9 100644 --- a/src/ServicesProvider/ServicesProvider.php +++ b/src/ServicesProvider/ServicesProvider.php @@ -1,27 +1,27 @@