Skip to content

Commit

Permalink
Road to version 2 - Refactor and rewrite most of the library (#33)
Browse files Browse the repository at this point in the history
* chore: Bump dev dependencies.

* refactor: Remove `request` property, pass it to each methods instead.

* chore: Update `composer.json` - Remove uneeded dev dependency.

* docs: Update documentation.

* tests: Update tests accordingly.

* refactor: Use `loophp/psr17` dependency.

* refactor: Remove dependency to `monolog/monolog`.

* refactor: Merge `Handler` and `Service`.

* refactor: Get rid of `Introspector`.

* refactor: Make it PSR15 compatible.

* refactor: Add more exceptions and update minor things here and there.

* tests: Restore tests and update them according to latest changes.

* refactor: Merge `ProxyValidate` and `ServiceValidate`.

* refactor: Simplify configuration and reorganize code.

* Fix `ServiceValidate` handler, restore `ProxyValidation` and update tests accordingly.

* refactor: Simplify and rewrite handlers.

* Update `CasResponseBuilder` to allow more granular customizations.

* Fix `ProxyCallback`.

* fix: Update `proxyCallback` handler, add note and fix test.

* tests: Add missing tests, improve coverage.

* chore: Require Psr17 stuff.

* refactor: Add response factories.

* refactor: Update factories, add interfaces.

* Make sure `text/xml` can be converted.

This is the kind of Content-Type header that EU Login is sending.

* refactor: Fix Proxy handling.

* Update Exception handling and PHPDoc.

* Update documentation and URI parameter handling.

BREAKING CHANGE: yes

* Sync `.editorconfig` with `ecphp/php-library-template`.

* Add more handler exceptions and fix an issue in the Service Validate, make it throws when the PGT is not available.

* Update documentation pages.
  • Loading branch information
drupol committed May 2, 2022
1 parent 643b216 commit 3504b64
Show file tree
Hide file tree
Showing 81 changed files with 3,207 additions and 3,826 deletions.
5 changes: 1 addition & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@

root = true

[*.{php,inc,module}]
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.{json,json.dist,yml,yml.dist}]
indent_size = 4
16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"ext-json": "*",
"ext-libxml": "*",
"ext-simplexml": "*",
"ergebnis/http-method": "^2.2",
"league/uri-components": "^2",
"loophp/psr17": "^1.0",
"openlss/lib-array2xml": "^1.0",
"psr/cache": "^1.0.1 || ^2 || ^3",
"psr/http-client": "^1.0",
Expand All @@ -24,22 +26,27 @@
"psr/http-factory-implementation": "^1",
"psr/http-message": "^1.0",
"psr/http-message-implementation": "^1",
"psr/log": "^1.1 || ^2 || ^3"
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0"
},
"require-dev": {
"ext-xdebug": "*",
"ecphp/php-conventions": "^1",
"friends-of-phpspec/phpspec-code-coverage": "^6.0.0",
"infection/infection": "^0.23 || ^0.24",
"infection/phpspec-adapter": "^0.1.2",
"monolog/monolog": "^1.0 || ^2.0",
"nyholm/psr7": "^1.4",
"nyholm/psr7-server": "^1.0.0",
"phpspec/phpspec": "^7",
"phpstan/phpstan-strict-rules": "^0.12 || ^1.0",
"phpstan/phpstan-strict-rules": "^1",
"symfony/cache": "^5.2",
"symfony/http-client": "^5.2"
},
"provide": {
"psr/http-server-handler-implementation": "^1.0"
},
"suggest": {
"nyholm/psr7": "A super lightweight PSR-7 implementation"
},
"autoload": {
"psr-4": {
"EcPhp\\CasLib\\": "./src/"
Expand All @@ -64,7 +71,6 @@
"changelog-unreleased": "docker-compose run auto_changelog -c .auto-changelog -u",
"changelog-version": "docker-compose run auto_changelog -c .auto-changelog -v",
"grumphp": "./vendor/bin/grumphp run",
"phpinsights": "./vendor/bin/phpinsights analyse src/",
"phpspec": "./vendor/bin/phpspec run"
}
}
16 changes: 10 additions & 6 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ CAS Lib

CAS Lib, a standard PHP library for `CAS authentication`_.

The Central Authentication Service (CAS) is an Open-Source single sign-on protocol for the web.
Its purpose is to permit a user to access multiple applications while providing their credentials only once.
It also allows web applications to authenticate users without gaining access to a user's security credentials,
such as a password. The name CAS also refers to a software package that implements this protocol.
The Central Authentication Service (CAS) is an Open-Source single sign-on
protocol for the web.
Its purpose is to permit a user to access multiple applications while providing
their credentials only once.
It also allows web applications to authenticate users without gaining access to
a user's security credentials,
such as a password. The name CAS also refers to a software package that
implements this protocol.

For improving the flexibility and in order to maximize it, it is able to
authenticate users and leaves the session handling up to the developer.
Expand All @@ -15,11 +19,11 @@ In order to foster a greater adoption of this library, it has been built
with interoperability in mind. It only uses `PHP Standards
Recommendations`_ interfaces.

- `PSR-3`_ for logging,
- `PSR-4`_ for classes autoloading,
- `PSR-6`_ for caching,
- `PSR-7`_ for HTTP messages (requests, responses),
- `PSR-12`_ for coding standards,
- `PSR-15`_ for HTTP Server Request Handlers,
- `PSR-17`_ for HTTP messages factories,
- `PSR-18`_ for HTTP client.

Expand All @@ -28,11 +32,11 @@ any PHP project, with any framework.

.. _CAS authentication: https://en.wikipedia.org/wiki/Central_Authentication_Service
.. _PHP Standards Recommendations: https://www.php-fig.org/
.. _PSR-3: https://www.php-fig.org/psr/psr-3/
.. _PSR-4: https://www.php-fig.org/psr/psr-4/
.. _PSR-6: https://www.php-fig.org/psr/psr-6/
.. _PSR-7: https://www.php-fig.org/psr/psr-7/
.. _PSR-12: https://www.php-fig.org/psr/psr-12/
.. _PSR-15: https://www.php-fig.org/psr/psr-15/
.. _PSR-17: https://www.php-fig.org/psr/psr-17/
.. _PSR-18: https://www.php-fig.org/psr/psr-18/

Expand Down
25 changes: 5 additions & 20 deletions docs/pages/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,21 @@ Configuration
protocol:
login:
path: /login
allowed_parameters:
- service
- renew
- gateway
default_parameters:
foo: bar
serviceValidate:
path: /p3/serviceValidate
allowed_parameters:
- service
- ticket
- pgtUrl
- renew
- format
default_parameters:
pgtUrl: https://my-app/casProxyCallback
logout:
path: /logout
allowed_parameters:
- service
default_parameters:
service: https://my-app/homepage
proxy:
path: /proxy
allowed_parameters:
- targetService
- pgt
default_parameters:
foo: bar
proxyValidate:
path: /proxyValidate
allowed_parameters:
- service
- ticket
- pgtUrl
default_parameters:
pgtUrl: https://my-app/casProxyCallback
pgtUrl: https://my-app/casProxyCallback
25 changes: 24 additions & 1 deletion docs/pages/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,27 @@ The easiest way to install it is through Composer_
composer require ecphp/cas-lib
.. _Composer: https://getcomposer.org
Based on the context this package is used, you might also need to install
a package which provides `PSR7 implementations`_.

There are `many packages implementing PSR7`_, you can pick the one you prefer,
exemple:

.. code-block:: bash
composer require nyholm/psr7
Next, you'll need an implementation of PSR17_. PSR17 provides the required
factories for the HTTP protocol. In order to facilitate the customizations,
you can either implements your own PSR17 implementation or use `loophp/psr17`_
which provides a default one:

.. code-block:: bash
composer require loophp/psr17
.. _Composer: https://getcomposer.org
.. _PSR7 implementations: https://www.php-fig.org/psr/psr-7/
.. _many packages implementing PSR7: https://packagist.org/providers/psr/http-message-implementation
.. _PSR17: https://www.php-fig.org/psr/psr-17/
.. _`loophp/psr17`: https://github.com/loophp/psr17
13 changes: 4 additions & 9 deletions docs/pages/requirements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Requirements
PHP
---

PHP greater than 7.1 is required for this library.
PHP >= 7.4 is required for this library.

PHP Extensions
--------------
Expand All @@ -24,13 +24,11 @@ class.
+------------------+-----------+---------------------------------+------------------------+
| Dependency | PSR | Implementations | Example package |
+==================+===========+=================================+========================+
| Logger | `PSR-3`_ | `log-implementation`_ | `monolog/monolog`_ |
+------------------+-----------+---------------------------------+------------------------+
| Cache | `PSR-6`_ | `cache-implementation`_ | `symfony/cache`_ |
+------------------+-----------+---------------------------------+------------------------+
| Server request | `PSR-7`_ | `http-message-implementations`_ | `nyholm/psr7-server`_ |
| HTTP Message | `PSR-7`_ | `http-message-implementations`_ | `nyholm/psr7`_ |
+------------------+-----------+---------------------------------+------------------------+
| HTTP factories | `PSR-17`_ | `http-factory-implementations`_ | `nyholm/psr7`_ |
| HTTP Factory | `PSR-17`_ | `http-factory-implementations`_ | `loophp/psr17`_ |
+------------------+-----------+---------------------------------+------------------------+
| HTTP Client | `PSR-18`_ | `http-client-implementations`_ | `symfony/http-client`_ |
+------------------+-----------+---------------------------------+------------------------+
Expand All @@ -46,18 +44,15 @@ You may use custom code for that, but you can also use any of the following pack

.. _zendframework/zend-httphandlerrunner: https://packagist.org/packages/zendframework/zend-httphandlerrunner
.. _http-interop/response-sender: https://packagist.org/packages/http-interop/response-sender
.. _monolog/monolog: https://packagist.org/packages/monolog/monolog
.. _nyholm/psr7-server: https://packagist.org/packages/nyholm/psr7-server
.. _nyholm/psr7: https://packagist.org/packages/nyholm/psr7
.. _loophp/psr17: https://packagist.org/packages/loophp/psr17
.. _symfony/cache: https://packagist.org/packages/symfony/cache
.. _symfony/http-client: https://packagist.org/packages/symfony/http-client
.. _cache-implementation: https://packagist.org/providers/psr/cache-implementation
.. _http-client-implementations: https://packagist.org/providers/psr/http-client-implementation
.. _http-factory-implementations: https://packagist.org/providers/psr/http-factory-implementation
.. _http-message-implementations: https://packagist.org/providers/psr/http-message-implementation
.. _log-implementation: https://packagist.org/providers/psr/log-implementation
.. _PSR-17: https://www.php-fig.org/psr/psr-17/
.. _PSR-18: https://www.php-fig.org/psr/psr-18/
.. _PSR-3: https://www.php-fig.org/psr/psr-3/
.. _PSR-6: https://www.php-fig.org/psr/psr-6/
.. _PSR-7: https://www.php-fig.org/psr/psr-7/
54 changes: 7 additions & 47 deletions docs/pages/tests.rst
Original file line number Diff line number Diff line change
@@ -1,57 +1,17 @@
Tests, code quality and code style
==================================

Every time changes are introduced into the library, `Travis CI`_ and `Github Actions`_
run the tests written with `PHPSpec`_.
Every time changes are introduced into the library, the continuous integration
system run and validate the tests.

`PHPInfection`_ is also triggered used to ensure that your code is properly
tested.
A PHP quality tool, Grumphp_, is used to orchestrate all these tasks at each
commit on the local machine, but also on the continuous integration tool in use.

The code style is based on `PSR-12`_ plus a set of custom rules.
Find more about the code style in use in the package `drupol/php-conventions`_.

A PHP quality tool, Grumphp_, is used to orchestrate all these tasks at each commit
on the local machine, but also on the continuous integration tools (Travis, Github actions)

To run the whole tests tasks locally, do
To run the tests locally:

.. code-block:: bash
composer grumphp
or

.. code-block:: bash
./vendor/bin/grumphp run
Here's an example of output that shows all the tasks that are setup in Grumphp and that
will check your code

.. code-block:: bash
$ ./vendor/bin/grumphp run
GrumPHP is sniffing your code!
Running task 1/13: SecurityChecker... ✔
Running task 2/13: Composer... ✔
Running task 3/13: ComposerNormalize... ✔
Running task 4/13: YamlLint... ✔
Running task 5/13: JsonLint... ✔
Running task 6/13: PhpLint... ✔
Running task 7/13: TwigCs... ✔
Running task 8/13: PhpCsAutoFixerV2... ✔
Running task 9/13: PhpCsFixerV2... ✔
Running task 10/13: Phpcs... ✔
Running task 11/13: PhpStan... ✔
Running task 12/13: Phpspec... ✔
Running task 13/13: Infection... ✔
$
.. _PSR-12: https://www.php-fig.org/psr/psr-12/
.. _drupol/php-conventions: https://github.com/drupol/php-conventions
.. _Travis CI: https://travis-ci.org/ecphp/cas-lib/builds
.. _Github Actions: https://github.com/ecphp/cas-lib/actions
.. _PHPSpec: http://www.phpspec.net/
.. _PHPInfection: https://github.com/infection/infection
.. _Grumphp: https://github.com/phpro/grumphp
.. _ecphp/php-conventions: https://github.com/ecphp/php-conventions
.. _Grumphp: https://github.com/phpro/grumphp
18 changes: 11 additions & 7 deletions docs/pages/usage.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
Usage
=====

Apereo_ already provides a demo CAS server without no proxy authentication mechanism enabled.
Apereo_ already provides a demo CAS server without no proxy authentication
mechanism enabled.

In order to test the libraries here, I've setup another `CAS server with Proxy authentication enabled`_ this time.
In order to test the libraries here, I've setup another
`CAS server with Proxy authentication enabled`_ this time.

Feel free to use it for your tests.

.. warning:: If your client application is not hosted on a public server and in HTTPS, this won't work.
.. warning:: If your client application is not hosted on a public server and in
HTTPS, this won't work.

.. tip:: See more on the page :ref:`development`. if you want to have your own local CAS server.
.. tip:: See more on the page :ref:`development`. if you want to have your own
local CAS server.

The test login is `casuser`, password is: `Mellon`

Expand All @@ -24,16 +28,16 @@ Test `the bare PHP demo application`_ now.
Symfony
-------

The CAS Lib library can be used in a Symfony (4 or 5) project through the package `ecphp/cas-bundle`_
The CAS Lib library can be used in a Symfony project through the package `ecphp/cas-bundle`_

Test `the Symfony bundle demo application`_ now.
Test `the Symfony demo application`_ now.

See `the documentation of the ecphp/cas-bundle`_ for more information.

.. _Apereo: https://www.apereo.org/
.. _ecphp/cas-bundle: https://github.com/ecphp/cas-bundle
.. _the documentation of the ecphp/cas-bundle: http://github.com/ecphp/cas-bundle
.. _the Symfony bundle demo application: https://cas-bundle-demo.herokuapp.com/
.. _the Symfony demo application: https://cas-bundle-demo.herokuapp.com/
.. _CAS server with Proxy authentication enabled: https://heroku-cas-server.herokuapp.com/cas/login
.. _drupol/psrcas-client-poc: https://github.com/drupol/psrcas-client-poc/
.. _the bare PHP demo application: https://psrcas-php-demo.herokuapp.com/
Expand Down

0 comments on commit 3504b64

Please sign in to comment.