Skip to content

Commit

Permalink
Feat/migrate to 80 (#24)
Browse files Browse the repository at this point in the history
* add generated tables

* add generated tables

* update engine repositories

* fix service calls

* fix location finder and routing parser

* fix dispatcher

* fix resolver

* remove annotation reader

* move documentation logic into resource listing

* add type hint

* update generated table

* update services

* update provider

* update framework

* update controller

* update backend view

* update auth

* update actions

* update views

* update

* fix tests

* update views

* update actions

* update actions

* update actions

* fix test cases

* update

* update wording

* update auth url

* update schema

* update deps

* update mailer

* fix test case

* fix smtp test

* return 201 response

* fix test case

* fix preview test

* skip generate table test

* fix worker
  • Loading branch information
chriskapp committed Jan 17, 2022
1 parent d7a8d99 commit 1bf3131
Show file tree
Hide file tree
Showing 549 changed files with 13,444 additions and 6,422 deletions.
32 changes: 16 additions & 16 deletions composer.json
Expand Up @@ -15,27 +15,27 @@
"psalm": "@php vendor/vimeo/psalm/psalm"
},
"require": {
"php": ">=7.4",
"psx/framework": "^5.0",
"php": ">=8.0",
"psx/framework": "^6.0",
"psx/openssl": "^2.0",
"psx/cloudevents": "^0.1",
"fusio/cli": "^0.2",
"fusio/model": "^0.1",
"fusio/engine": "^4.0",
"fusio/adapter-file": "^4.0",
"fusio/adapter-graphql": "^4.0",
"fusio/adapter-http": "^4.0",
"fusio/adapter-php": "^4.0",
"fusio/adapter-smtp": "^4.0",
"fusio/adapter-soap": "^4.0",
"fusio/adapter-sql": "^4.0",
"fusio/adapter-util": "^4.0",
"fusio/adapter-cli": "^0.1",
"fusio/adapter-fcgi": "^4.0",
"fusio/cli": "^1.0",
"fusio/model": "^1.0",
"fusio/engine": "^5.0",
"fusio/adapter-file": "^5.0",
"fusio/adapter-graphql": "^5.0",
"fusio/adapter-http": "^5.0",
"fusio/adapter-php": "^5.0",
"fusio/adapter-smtp": "^5.0",
"fusio/adapter-soap": "^5.0",
"fusio/adapter-sql": "^5.0",
"fusio/adapter-util": "^5.0",
"fusio/adapter-cli": "^5.0",
"fusio/adapter-fcgi": "^5.0",
"firebase/php-jwt": "^5.0",
"swiftmailer/swiftmailer": "^6.2",
"doctrine/migrations": "^2.3",
"symfony/filesystem": "^4.0|^5.0",
"symfony/mailer": "^6.0",
"packaged/thrift": "^0.13"
},
"require-dev": {
Expand Down
13 changes: 3 additions & 10 deletions src/Authorization/Action/GetWhoami.php
Expand Up @@ -38,23 +38,16 @@
*/
class GetWhoami extends ActionAbstract
{
/**
* @var View\User
*/
private $table;

/**
* @var Config
*/
private $config;
private View\User $table;
private Config $config;

public function __construct(TableManagerInterface $tableManager, Config $config)
{
$this->table = $tableManager->getTable(View\User::class);
$this->config = $config;
}

public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context)
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
{
return $this->table->getEntity(
$context->getUser()->getId(),
Expand Down
17 changes: 5 additions & 12 deletions src/Authorization/Action/Revoke.php
Expand Up @@ -41,23 +41,16 @@
*/
class Revoke extends ActionAbstract
{
/**
* @var Service\App\Token
*/
private $appTokenService;

/**
* @var Table\App\Token
*/
private $table;
private Service\App\Token $appTokenService;
private Table\App\Token $table;

public function __construct(Service\App\Token $appTokenService, TableManagerInterface $tableManager)
{
$this->appTokenService = $appTokenService;
$this->table = $tableManager->getTable(Table\App\Token::class);
}

public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context)
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
{
if ($request instanceof HttpRequest) {
$token = $this->getTokenByHttp($request);
Expand All @@ -83,8 +76,8 @@ private function getTokenByHttp(HttpRequest $request): ?string
{
$header = $request->getHeader('Authorization');
$parts = explode(' ', $header, 2);
$type = isset($parts[0]) ? $parts[0] : null;
$token = isset($parts[1]) ? $parts[1] : null;
$type = $parts[0] ?? null;
$token = $parts[1] ?? null;

if ($type !== 'Bearer') {
throw new StatusCode\BadRequestException('Invalid token type');
Expand Down
54 changes: 10 additions & 44 deletions src/Authorization/AuthorizationCode.php
Expand Up @@ -28,6 +28,7 @@
use PSX\Oauth2\Authorization\Exception\InvalidClientException;
use PSX\Oauth2\Authorization\Exception\InvalidGrantException;
use PSX\Oauth2\Authorization\Exception\InvalidScopeException;
use PSX\Oauth2\Grant;

/**
* AuthorizationCode
Expand All @@ -38,61 +39,26 @@
*/
class AuthorizationCode extends AuthorizationCodeAbstract
{
/**
* @var \Fusio\Impl\Service\App\Code
*/
private $appCodeService;
private Service\App\Token $appTokenService;
private Service\Scope $scopeService;
private Table\App\Code $appCodeTable;
private string $expireToken;

/**
* @var \Fusio\Impl\Service\Scope
*/
private $scopeService;

/**
* @var \Fusio\Impl\Service\App\Token
*/
private $appTokenService;

/**
* @var \Fusio\Impl\Table\App\Code
*/
private $appCodeTable;

/**
* @var string
*/
private $expireToken;

/**
* @param \Fusio\Impl\Service\App\Code $appCodeService
* @param \Fusio\Impl\Service\App\Token $appTokenService
* @param \Fusio\Impl\Service\Scope $scopeService
* @param \Fusio\Impl\Table\App\Code $appCodeTable
* @param string $expireToken
*/
public function __construct(Service\App\Code $appCodeService, Service\App\Token $appTokenService, Service\Scope $scopeService, Table\App\Code $appCodeTable, string $expireToken)
public function __construct(Service\App\Token $appTokenService, Service\Scope $scopeService, Table\App\Code $appCodeTable, string $expireToken)
{
$this->appCodeService = $appCodeService;
$this->appTokenService = $appTokenService;
$this->scopeService = $scopeService;
$this->appCodeTable = $appCodeTable;
$this->expireToken = $expireToken;
}

/**
* @param \PSX\Framework\Oauth2\Credentials $credentials
* @param string $code
* @param string $redirectUri
* @param string $clientId
* @return \PSX\Oauth2\AccessToken
*/
protected function generate(Credentials $credentials, $code, $redirectUri, $clientId)
protected function generate(Credentials $credentials, Grant\AuthorizationCode $grant)
{
$code = $this->appCodeTable->getCodeByRequest(
$credentials->getClientId(),
$credentials->getClientSecret(),
$code,
$redirectUri ?: ''
$grant->getCode(),
$grant->getRedirectUri()
);

if (empty($code)) {
Expand All @@ -116,7 +82,7 @@ protected function generate(Credentials $credentials, $code, $redirectUri, $clie
$code['app_id'],
$code['user_id'],
$scopes,
isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1',
$_SERVER['REMOTE_ADDR'] ?? '127.0.0.1',
new \DateInterval($this->expireToken)
);
}
Expand Down
51 changes: 10 additions & 41 deletions src/Authorization/ClientCredentials.php
Expand Up @@ -23,12 +23,11 @@

use Fusio\Impl\Service;
use Fusio\Impl\Table;
use Fusio\Impl\Table\App;
use PSX\Framework\Oauth2\Credentials;
use PSX\Framework\Oauth2\GrantType\ClientCredentialsAbstract;
use PSX\Oauth2\Authorization\Exception\InvalidClientException;
use PSX\Oauth2\Authorization\Exception\InvalidGrantException;
use PSX\Oauth2\Authorization\Exception\InvalidScopeException;
use PSX\Oauth2\Grant;
use PSX\Sql\Condition;

/**
Expand All @@ -40,38 +39,12 @@
*/
class ClientCredentials extends ClientCredentialsAbstract
{
/**
* @var \Fusio\Impl\Service\App\Token
*/
private $appTokenService;
private Service\App\Token $appTokenService;
private Service\Scope $scopeService;
private Service\User $userService;
private Table\App $appTable;
private string $expireToken;

/**
* @var \Fusio\Impl\Service\Scope
*/
private $scopeService;

/**
* @var \Fusio\Impl\Service\User
*/
private $userService;

/**
* @var \Fusio\Impl\Table\App
*/
private $appTable;

/**
* @var string
*/
private $expireToken;

/**
* @param \Fusio\Impl\Service\App\Token $appTokenService
* @param \Fusio\Impl\Service\Scope $scopeService
* @param \Fusio\Impl\Service\User $userService
* @param \Fusio\Impl\Table\App $appTable
* @param string $expireToken
*/
public function __construct(Service\App\Token $appTokenService, Service\Scope $scopeService, Service\User $userService, Table\App $appTable, string $expireToken)
{
$this->appTokenService = $appTokenService;
Expand All @@ -81,12 +54,7 @@ public function __construct(Service\App\Token $appTokenService, Service\Scope $s
$this->expireToken = $expireToken;
}

/**
* @param \PSX\Framework\Oauth2\Credentials $credentials
* @param string $scope
* @return \PSX\Oauth2\AccessToken
*/
protected function generate(Credentials $credentials, $scope)
protected function generate(Credentials $credentials, Grant\ClientCredentials $grant)
{
// check whether the credentials contain an app key and secret
$app = $this->getApp($credentials->getClientId(), $credentials->getClientSecret());
Expand All @@ -103,6 +71,7 @@ protected function generate(Credentials $credentials, $scope)
throw new InvalidClientException('Unknown credentials');
}

$scope = $grant->getScope();
if (empty($scope)) {
// as fallback simply use all scopes assigned to the user
$scope = implode(',', $this->userService->getAvailableScopes($userId));
Expand All @@ -119,7 +88,7 @@ protected function generate(Credentials $credentials, $scope)
$appId === null ? 1 : $appId,
$userId,
$scopes,
isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1',
$_SERVER['REMOTE_ADDR'] ?? '127.0.0.1',
new \DateInterval($this->expireToken)
);
}
Expand All @@ -131,7 +100,7 @@ private function getApp(string $appKey, string $appSecret)
$condition->equals('app_secret', $appSecret);
$condition->equals('status', Table\App::STATUS_ACTIVE);

$app = $this->appTable->getOneBy($condition);
$app = $this->appTable->findOneBy($condition);
if (empty($app)) {
return null;
}
Expand Down
52 changes: 11 additions & 41 deletions src/Authorization/Password.php
Expand Up @@ -25,9 +25,11 @@
use Fusio\Impl\Table;
use PSX\Framework\Oauth2\Credentials;
use PSX\Framework\Oauth2\GrantType\PasswordAbstract;
use PSX\Oauth2\AccessToken;
use PSX\Oauth2\Authorization\Exception\InvalidClientException;
use PSX\Oauth2\Authorization\Exception\InvalidGrantException;
use PSX\Oauth2\Authorization\Exception\InvalidScopeException;
use PSX\Oauth2\Grant;
use PSX\Sql\Condition;

/**
Expand All @@ -39,38 +41,12 @@
*/
class Password extends PasswordAbstract
{
/**
* @var \Fusio\Impl\Service\App\Token
*/
private $appTokenService;
private Service\App\Token $appTokenService;
private Service\Scope $scopeService;
private Service\User $userService;
private Table\App $appTable;
private string $expireToken;

/**
* @var \Fusio\Impl\Service\Scope
*/
private $scopeService;

/**
* @var \Fusio\Impl\Service\User
*/
private $userService;

/**
* @var \Fusio\Impl\Table\App
*/
private $appTable;

/**
* @var string
*/
private $expireToken;

/**
* @param \Fusio\Impl\Service\App\Token $appTokenService
* @param \Fusio\Impl\Service\Scope $scopeService
* @param \Fusio\Impl\Service\User $userService
* @param \Fusio\Impl\Table\App $appTable
* @param string $expireToken
*/
public function __construct(Service\App\Token $appTokenService, Service\Scope $scopeService, Service\User $userService, Table\App $appTable, string $expireToken)
{
$this->appTokenService = $appTokenService;
Expand All @@ -80,31 +56,25 @@ public function __construct(Service\App\Token $appTokenService, Service\Scope $s
$this->expireToken = $expireToken;
}

/**
* @param \PSX\Framework\Oauth2\Credentials $credentials
* @param string $username
* @param string $password
* @param string $scope
* @return \PSX\Oauth2\AccessToken
*/
protected function generate(Credentials $credentials, $username, $password, $scope)
protected function generate(Credentials $credentials, Grant\Password $grant): AccessToken
{
$condition = new Condition();
$condition->equals('app_key', $credentials->getClientId());
$condition->equals('app_secret', $credentials->getClientSecret());
$condition->equals('status', Table\App::STATUS_ACTIVE);

$app = $this->appTable->getOneBy($condition);
$app = $this->appTable->findOneBy($condition);
if (empty($app)) {
throw new InvalidClientException('Unknown credentials');
}

// check user
$userId = $this->userService->authenticateUser($username, $password);
$userId = $this->userService->authenticateUser($grant->getUsername(), $grant->getPassword());
if (empty($userId)) {
throw new InvalidGrantException('Unknown user');
}

$scope = $grant->getScope();
if (empty($scope)) {
// as fallback simply use all scopes assigned to the user
$scope = implode(',', $this->userService->getAvailableScopes($userId));
Expand Down

0 comments on commit 1bf3131

Please sign in to comment.