├── .github └── workflows │ └── tests.yml ├── LICENSE ├── README.md ├── composer.json └── src ├── Event.php ├── Exception.php └── MiddlewareInterface.php /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: tests 2 | 3 | on: push 4 | 5 | jobs: 6 | tests: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | php: ['8.0', '8.1'] 11 | steps: 12 | - uses: actions/checkout@v2 13 | - name: Install PHP 14 | uses: shivammathur/setup-php@v2 15 | with: 16 | php-version: ${{ matrix.php }} 17 | extensions: phalcon5 18 | tools: composer:v2 19 | - name: Validate composer.json and composer.lock 20 | run: composer validate 21 | - name: Install dependencies 22 | run: composer install --prefer-dist --no-progress 23 | - name: Run Codeception tests 24 | run: vendor/bin/codecept run 25 | - name: RUN PHP Code Sniffer 26 | run: vendor/bin/phpcs src/ --standard=psr2 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2023 Sid Roberts 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `Sid\Phalcon\AuthMiddleware` 2 | 3 | Auth Middleware component for Phalcon. 4 | 5 | 6 | 7 | [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/SidRoberts/phalcon-authmiddleware/tests.yml?style=for-the-badge)](https://github.com/SidRoberts/phalcon-authmiddleware/actions) 8 | [![GitHub release](https://img.shields.io/github/release/SidRoberts/phalcon-authmiddleware.svg?style=for-the-badge)]() 9 | 10 | [![GitHub issues](https://img.shields.io/github/issues-raw/SidRoberts/phalcon-authmiddleware.svg?style=for-the-badge)](https://github.com/SidRoberts/phalcon-authmiddleware/issues) 11 | [![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/SidRoberts/phalcon-authmiddleware.svg?style=for-the-badge)](https://github.com/SidRoberts/phalcon-authmiddleware/pulls) 12 | 13 | 14 | 15 | ## Version Requirements 16 | 17 | [![](https://img.shields.io/badge/Phalcon-%3E%3D%205.0.0-76C39B?style=for-the-badge)]() 18 | 19 | [![](https://img.shields.io/badge/PHP-%3E%3D%208.0.0-777BB3?style=for-the-badge)]() 20 | 21 | 22 | 23 | ## Installing 24 | 25 | Install using Composer: 26 | 27 | ```bash 28 | composer require sidroberts/phalcon-authmiddleware 29 | ``` 30 | 31 | 32 | 33 | ## Documentation 34 | 35 | See the [Wiki](https://github.com/SidRoberts/phalcon-authmiddleware/wiki). 36 | 37 | 38 | 39 | ## License 40 | 41 | Licensed under the MIT License. 42 | © [Sid Roberts](https://github.com/SidRoberts) 43 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sidroberts/phalcon-authmiddleware", 3 | "description": "Auth Middleware component for Phalcon.", 4 | "type": "library", 5 | "license": "MIT", 6 | 7 | "authors": [ 8 | { 9 | "name": "Sid Roberts", 10 | "email": "sid@sidroberts.co.uk", 11 | "homepage": "https://sidroberts.co.uk", 12 | "role": "Developer" 13 | } 14 | ], 15 | 16 | "support": { 17 | "source": "https://github.com/SidRoberts/phalcon-authmiddleware", 18 | "issues": "https://github.com/SidRoberts/phalcon-authmiddleware/issues", 19 | "wiki": "https://github.com/SidRoberts/phalcon-authmiddleware/wiki" 20 | }, 21 | 22 | 23 | 24 | "require": { 25 | "php": "~8.0", 26 | 27 | "ext-phalcon": "~5.0" 28 | }, 29 | 30 | "require-dev": { 31 | "codeception/codeception": "~5.0", 32 | "codeception/module-asserts": "~2.0", 33 | 34 | "squizlabs/php_codesniffer": "~3.4" 35 | }, 36 | 37 | 38 | 39 | "autoload": { 40 | "psr-4": { 41 | "Sid\\Phalcon\\AuthMiddleware\\": "src/" 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Event.php: -------------------------------------------------------------------------------- 1 | annotations->getMethod( 16 | $dispatcher->getHandlerClass(), 17 | $dispatcher->getActiveMethod() 18 | ); 19 | 20 | if (!$methodAnnotations->has("AuthMiddleware")) { 21 | return true; 22 | } 23 | 24 | foreach ($methodAnnotations->getAll("AuthMiddleware") as $annotation) { 25 | $class = $annotation->getArgument(0); 26 | 27 | $authMiddleware = new $class(); 28 | 29 | if (!($authMiddleware instanceof MiddlewareInterface)) { 30 | throw new Exception( 31 | "Not an auth middleware." 32 | ); 33 | } 34 | 35 | 36 | 37 | $result = $authMiddleware->authenticate(); 38 | 39 | /* 40 | * Multi-middleware mode 41 | */ 42 | if ($result === false) { 43 | return $result; 44 | } 45 | } 46 | 47 | return true; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Exception.php: -------------------------------------------------------------------------------- 1 |