Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['8.1', '8.2', '8.3']
php-version: ['8.2', '8.3', '8.4']
db-type: [sqlite, mysql, pgsql]
prefer-lowest: ['']

Expand Down Expand Up @@ -59,22 +59,22 @@ jobs:
fi
- name: Setup problem matchers for PHPUnit
if: matrix.php-version == '8.1' && matrix.db-type == 'mysql'
if: matrix.php-version == '8.2' && matrix.db-type == 'mysql'
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run PHPUnit
run: |
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp?encoding=utf8'; fi
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:postgres@127.0.0.1/postgres'; fi
if [[ ${{ matrix.php-version }} == '8.1' ]]; then
if [[ ${{ matrix.php-version }} == '8.2' ]]; then
export CODECOVERAGE=1 && vendor/bin/phpunit --display-deprecations --display-incomplete --display-skipped --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi
- name: Submit code coverage
if: matrix.php-version == '8.1'
if: matrix.php-version == '8.2'
uses: codecov/codecov-action@v5

cs-stan:
Expand All @@ -87,7 +87,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
extensions: mbstring, intl, apcu
coverage: none

Expand Down
17 changes: 13 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@
"source": "https://github.com/CakeDC/cakephp-api"
},
"require": {
"php": ">=8.1",
"php": ">=8.2",
"ext-json": "*",
"cakephp/cakephp": "^5.0",
"cakedc/users": "^15.1",
"cakephp/cakephp": "^5.1",
"cakedc/users": "^16.0",
"lcobucci/jwt": "^5.5.0",
"firebase/php-jwt": "^6.3"
"firebase/php-jwt": "^6.3 || ^7.0"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^4.5",
"cweagans/composer-patches": "^1.7",
"endroid/qr-code": "^4",
"google/recaptcha": "@stable",
"laminas/laminas-diactoros": "^3.0",
Expand All @@ -59,9 +60,17 @@
}
},
"prefer-stable": true,
"extra": {
"patches": {
"league/flysystem-vfs": {
"Fix null passed to str_replace in PHP 8.1+": "patches/flysystem-vfs-null-str-replace.patch"
}
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"cweagans/composer-patches": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
Expand Down
8 changes: 5 additions & 3 deletions config/Migrations/20180313201241_initial_jwt_auth.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/**
* Copyright 2018 - 2020, Cake Development Corporation (https://www.cakedc.com)
*
Expand All @@ -9,11 +11,11 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

use Migrations\AbstractMigration;
use Migrations\BaseMigration;

class InitialJwtAuth extends AbstractMigration
class InitialJwtAuth extends BaseMigration
{
public function change()
public function change(): void
{
$this->table('jwt_refresh_tokens', ['id' => false, 'primary_key' => ['id']])
->addColumn('id', 'uuid', [
Expand Down
8 changes: 5 additions & 3 deletions config/Migrations/20231003201241_auth_store.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/**
* Copyright 2018 - 2020, Cake Development Corporation (https://www.cakedc.com)
*
Expand All @@ -9,11 +11,11 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

use Migrations\AbstractMigration;
use Migrations\BaseMigration;

class AuthStore extends AbstractMigration
class AuthStore extends BaseMigration
{
public function change()
public function change(): void
{
$this->table('auth_store', ['id' => false, 'primary_key' => ['id']])
->addColumn('id', 'string', [
Expand Down
11 changes: 11 additions & 0 deletions patches/flysystem-vfs-null-str-replace.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/src/VfsAdapter.php
+++ b/src/VfsAdapter.php
@@ -106,7 +106,7 @@ class VfsAdapter extends Local
protected function wrapPath($path)
{
$scheme = $this->vfs->scheme().'://';
- $path = str_replace($scheme, null, $path);
+ $path = str_replace($scheme, '', $path ?? '');

return $scheme.$path;
}
40 changes: 27 additions & 13 deletions src/ApiInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,39 @@ class ApiInitializer implements AuthorizationServiceProviderInterface
public function getAuthenticationService(): AuthenticationService
{
$service = new AuthenticationService();
$service->loadIdentifier('Authentication.JwtSubject', []);
$service->loadIdentifier('Authentication.Password', [
'resolver' => [
'className' => 'Authentication.Orm',
'userModel' => 'CakeDC/Users.Users',
'finder' => 'active',
],
]);

$service->loadAuthenticator('Authentication.Session', [
'sessionKey' => 'Auth',
'identifier' => [
'Authentication.Password' => [
'resolver' => [
'className' => 'Authentication.Orm',
'userModel' => 'CakeDC/Users.Users',
'finder' => 'active',
],
],
],
]);
$service->loadAuthenticator('CakeDC/Auth.Form', [
// 'sessionKey' => 'Auth',
'identifier' => [
'Authentication.Password' => [
'resolver' => [
'className' => 'Authentication.Orm',
'userModel' => 'CakeDC/Users.Users',
'finder' => 'active',
],
],
],
]);

$service->loadIdentifier('Authentication.Token', [
'dataField' => 'token',
'tokenField' => 'api_token',
]);
$service->loadAuthenticator('Authentication.Token', [
'queryParam' => 'token',
'identifier' => [
'Authentication.Token' => [
'dataField' => 'token',
'tokenField' => 'api_token',
],
],
]);

$service->loadAuthenticator('Authentication.Jwt', [
Expand All @@ -66,6 +77,9 @@ public function getAuthenticationService(): AuthenticationService
'algorithm' => 'HS512',
'returnPayload' => false,
'secretKey' => Configure::read('Api.Jwt.AccessToken.secret'),
'identifier' => [
'Authentication.JwtSubject' => [],
],
]);

return $service;
Expand Down
99 changes: 99 additions & 0 deletions src/ApiPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);

/**
* Copyright 2016 - 2019, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2016 - 2019, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

namespace CakeDC\Api;

use Cake\Console\CommandCollection;
use Cake\Core\BasePlugin;
use Cake\Core\Configure;
use Cake\Core\ContainerInterface;
use CakeDC\Api\Command\ServiceRoutesCommand;

/**
* Api plugin
*/
class ApiPlugin extends BasePlugin
{
protected array $middlewares = [];

/**
* @inheritDoc
*/
public function routes($routes): void
{
$middlewares = Configure::read('Api.Middleware', []);
foreach ($middlewares as $alias => $middleware) {
$class = $middleware['class'];
if (array_key_exists('request', $middleware)) {
$requestClass = $middleware['request'];
$request = new $requestClass();
if (array_key_exists('method', $middleware)) {
$request = $request->{$middleware['method']}();
}
if (array_key_exists('params', $middleware)) {
$options = $middleware['params'];
$this->registerMiddleware($routes, $alias, new $class($request, $options));
} else {
$this->registerMiddleware($routes, $alias, new $class($request));
}
} else {
if (array_key_exists('params', $middleware)) {
$options = $middleware['params'];
$this->registerMiddleware($routes, $alias, new $class($options));
} else {
$this->registerMiddleware($routes, $alias, new $class());
}
}
}

parent::routes($routes);
}

/**
* Middleware registrator and holder.
*
* @param \Cake\Routing\RouteBuilder $routes Routes.
* @param string $alias Middleware alias.
* @param string $class Middleware class instance.
* @return void
*/
protected function registerMiddleware($routes, $alias, $class)
{
$routes->registerMiddleware($alias, $class);
$this->middlewares[$alias] = $class;
}

/**
* Register container services for this plugin.
*
* @param \Cake\Core\ContainerInterface $container The container to add services to.
* @return void
*/
public function services(ContainerInterface $container): void
{
if (array_key_exists('apiParser', $this->middlewares)) {
$this->middlewares['apiParser']->setContainer($container);
}
}

/**
* Add console commands for the plugin.
*
* @param \Cake\Console\CommandCollection $commands The command collection to update
* @return \Cake\Console\CommandCollection
*/
public function console(CommandCollection $commands): CommandCollection
{
return $commands->add('service routes', ServiceRoutesCommand::class);
}
}
4 changes: 2 additions & 2 deletions src/Model/Entity/AuthStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*
* @property string $id
* @property array|null $store
* @property \Cake\I18n\FrozenTime $created
* @property \Cake\I18n\FrozenTime $modified
* @property \Cake\I18n\DateTime $created
* @property \Cake\I18n\DateTime $modified
*/
class AuthStore extends Entity
{
Expand Down
Loading
Loading