Giter Club home page Giter Club logo

oe_authentication's Introduction

OpenEuropa Authentication

Build Status Packagist

The OpenEuropa Authentication module allows authentication against EU Login, the European Commission login service.

Table of contents:

Requirements

This module requires the following modules:

Installation

The recommended way of installing the OpenEuropa Authentication module is via Composer.

composer require openeuropa/oe_authentication

Enable the module

In order to enable the module in your project run:

./vendor/bin/drush en oe_authentication

EU Login service parameters are already set by default when installing the module. Please refer to the EU Login documentation for the available options that can be specified. You can see Project setup section on how to override these parameters.

Configuration

EU Login service parameters are already set by default when installing the module. Please refer to the EU Login documentation for the available options that can be specified. You can see Project setup section on how to override these parameters.

Settings overrides

In the Drupal settings.php you can override CAS parameters such as the ones below, corresponding to the cas.settings and oe_authentication.settings configuration objects.

$config['cas.settings']['server']['hostname'] = 'authentication';
$config['cas.settings']['server']['port'] = '7002';
$config['cas.settings']['server']['path'] = '/cas';
$config['oe_authentication.settings']['register_path'] = 'register';
$config['oe_authentication.settings']['validation_path'] = 'TicketValidationService';

By default, the development setup is configured via Task Runner to use the demo CAS server provided in the docker-compose.yml.dist, i.e. https://authentication:7002.

If you want to test the module with the actual EU Login service, comment out all the lines above in your settings.php and clear the cache.

Account Handling & Auto Registration

The module enables the option that if a user attempts to login with an account that is not already registered, the account will automatically be created.

See the Cas module for more information.

Forced Login

The module enables the Forced Login feature to force anonymous users to authenticate via CAS when they hit all or some of the pages on your site.

See the Cas module for more information.

SSL Verification Setting

The EU Login Authentication server must be accessed over HTTPS and the drupal site will verify the SSL/TLS certificate of the server to be sure it is authentic.

For development, you can configure the module to disable this verification:

$config['cas.settings']['server']['verify'] = '2';

NOTE: DO NOT USE IN PRODUCTION!

See the Cas module for more information.

Proxy

You can configure the module to "Initialize this client as a proxy" which allows authentication requests to 3rd party services (e.g. ePOETRY).

$config['cas.settings']['proxy']['initialize'] = TRUE;

See the Cas module for more information.

Development

The OpenEuropa Authentication project contains all the necessary code and tools for an effective development process, such as:

  • All PHP development dependencies (Drupal core included) are required by composer.json
  • Project setup and installation can be easily handled thanks to the integration with the Task Runner project.
  • All system requirements are containerized using Docker Composer
  • A mock server for testing.

Project setup

Download all required PHP code by running:

composer install

This will build a fully functional Drupal test site in the ./build directory that can be used to develop and showcase the module's functionality.

Before setting up and installing the site make sure to customize default configuration values by copying runner.yml.dist to ./runner.yml and overriding relevant properties.

This command will also:

  • This will symlink the module in the proper directory within the test site and perform token substitution in test configuration files such as behat.yml.dist.
  • Setup Drush and Drupal's settings using values from ./runner.yml.dist. This includes adding parameters for EULogin
  • Setup PHPUnit and Behat configuration files using values from ./runner.yml.dist

After a successful setup install the site by running:

./vendor/bin/run drupal:site-install

This will:

  • Install the test site
  • Enable the OpenEuropa Authentication module

Using Docker Compose

Alternatively, you can build a development site using Docker and Docker Compose with the provided configuration.

Docker provides the necessary services and tools such as a web server and a database server to get the site running, regardless of your local host configuration.

Requirements:

Configuration

By default, Docker Compose reads two files, a docker-compose.yml and an optional docker-compose.override.yml file. By convention, the docker-compose.yml contains your base configuration and it's provided by default. The override file, as its name implies, can contain configuration overrides for existing services or entirely new services. If a service is defined in both files, Docker Compose merges the configurations.

Find more information on Docker Compose extension mechanism on the official Docker Compose documentation.

Usage

To start, run:

docker-compose up

It's advised to not daemonize docker-compose so you can turn it off (CTRL+C) quickly when you're done working. However, if you'd like to daemonize it, you have to add the flag -d:

docker-compose up -d

Then:

docker-compose exec web composer install
docker-compose exec web ./vendor/bin/run drupal:site-install

To be able to interact with the EULogin Mock Service container you need to add the internal container hostname to the hosts file in your OS.

echo "127.0.1.1       authentication" >> /etc/hosts

Using default configuration, the development site files should be available in the build directory and the development site should be available at: http://127.0.0.1:8080/build.

Running the tests

To run the grumphp checks:

docker-compose exec web ./vendor/bin/grumphp run

To run the phpunit tests:

docker-compose exec web ./vendor/bin/phpunit

To run the behat tests:

docker-compose exec web ./vendor/bin/behat

Troubleshooting

Disable Drupal 8 caching

Manually disabling Drupal 8 caching is a laborious process that is well described here.

Alternatively you can use the following Drupal Console commands to disable/enable Drupal 8 caching:

./vendor/bin/drupal site:mode dev  # Disable all caches.
./vendor/bin/drupal site:mode prod # Enable all caches.

Note: to fully disable Twig caching the following additional manual steps are required:

  1. Open ./build/sites/default/services.yml
  2. Set cache: false in twig.config: property. E.g.:
parameters:
  twig.config:
    cache: false
  1. Rebuild Drupal cache: ./vendor/bin/drush cr

This is due to the following Drupal Console issue.

Contributing

Please read the full documentation for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the available versions, see the tags on this repository.

oe_authentication's People

Contributors

22alexandra avatar aarongilmartinez avatar abel-santos-corral avatar ademarco avatar aritomelo avatar brummbar avatar claudiu-cristea avatar drupol avatar escuriola avatar hernani avatar idimopoulos avatar imanoleguskiza avatar nagyad avatar netlooker avatar richardcanoe avatar saidatom avatar sandervd avatar sergepavle avatar upchuk avatar voidtek avatar yenyasinn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oe_authentication's Issues

Destination parameters prevents redirection to registration page

If we open a node with comments as anonymous user we will see the links including
the registration link with url: http://web/en/user/register?destination=node/1%23comment-form
User will be redirect back to the node page.

  1. You need to drop destination from request or we can send the response instead of passing further
  2. You need to take into account "destination" parameter and pass it here
    https://ecas.ec.europa.eu/cas/eim/external/register.cgi?service=

Rendering user information

Define and implement what information needs to be rendered about a user by default and how to do so.

Possible scenarios:

  • Content author information
  • User page

Bulk Add EU Login Users by email

Bulk Add EU Login Users currently allows to specify usernames.

Screenshot from 2021-08-24 17-13-47

Would it be possible to enter emails that are registered in EU login to become system users?
Also could we use this for creating NEW users in EU Logid Identity Provider in case their email does not exist?

Redirect loop if front page is /user/login

Steps to reproduce:

  • Enable oe_authentication with forced login.
  • Leave front page as "/user/login" - this is the default from core/modules/system/config/install/system.site.yml.
  • Attempt to login as an inactive user, or login with a non-existent user, and have it be auto-created as inactive.

Expected:
Not sure what we expect :)

Actual:
EU Login redirects to frontpage, Drupal refuses to login the inactive user, Drupal redirects back to EU Login, EU Login redirects back to Drupal frontpage, etc.

Workaround:
As a site builder, simply avoid having front page = /user/login.

Solution:
As maintainers of this module, we simply need to push site builders to change the default front page.
Perhaps having this issue here is good enough.

Registering users when admin approval is required

Currently, when a new user is register after a successful EU Login, if the site policy is to require admin approval, the account will be blocked. This should be configurable. For example some projects might consider that users registered via EU Login are safe and there's no need for approval.

Proposal

Add a new setting Block newly created users if the site requires admin approval on new account registering (find a better wording!). This should default to TRUE in order to ensure BC.

Problems after removing methods to cancel accounts

This module is removing methods to cancel accounts for most users in a hook. The super user (uid 1) can still chose one of these removed methods.

If the selected method is one of the forbidden ones and users have the permission "Cancel own user account", when a user tries to cancel its account we'll see a PHP error (notice) in dblog reports:

Notice: Undefined index: user_cancel_reassign in Drupal\user\Form\UserCancelForm->getDescription() (line 70 of /var/www/html/build/core/modules/user/src/Form/UserCancelForm.php)

Removing options to cancel accounts like this, in a hook, is already a problem because in some cases sites will want one of them. In ECIF there is an example where this hook was removed in a local patch. In another project we'll need to do this too now.

I don't know the requirements to remove methods and only allow them to the super user.
I can only suggest to rethink the all approach here.

ECAS new user login and registration not working

Dears,
EU login and registration is not working. When we try to login using a new user, we are unable to login and getting an error message on the screen attached below.
When we checked admin/people page, we don't see an account created. Expected behavior is account should be created after login and new user should be redirected to registration form.

We are using 1.13.0 version of this module.

Can you please check and help.
image

New release plan

The last official release (1.3.0) is now more than a year old and the CAS version is requesting an update which is updated in version 1.4.0 that is in an own branch but hasn't been released to be picked up by composer require as instructed (composer require openeuropa/oe_authentication)

Screenshot from 2021-07-08 15-31-53

Screenshot from 2021-07-08 15-32-07

Are there plans to release the next version?

Streamline the user sanitization function.

On sites with a big number of users (100K+), the user Drush sanitization function from the oe_authentication_user_fields module is trying to load the entire list of users in memory before sanitizating them and that, in turn, depending on the PHP CLI ram limits, might trigger an Out of memory error.

I would propose to change, in the oe_authentication_user_fields/src/Commands/sql/UserSanitizeCommand.php file, the lines:

$users = $this->entityTypeManager->getStorage('user')->loadMultiple();
 foreach ($users as $user) {

to a more memory conservative way as follows:

    /** @var  \Drupal\Core\Entity\EntityTypeManagerInterface $user_storage */
    $user_storage = $this->entityTypeManager->getStorage('user');

    /** @var int[] $user_ids */
    $user_ids = $user_storage->getQuery()->execute();

    foreach ($user_ids as $uid) {
      /** @var \Drupal\user\Entity\User $user */
      $user = $user_storage->load($uid);

Thank you.

Confusing and undocumented `if` statement in route subscriber

While reviewing #85 I found a dubious section of code in RouteSubscriber::alterRoutes() and no comments are given on why this is needed:

    // Replace the core register route controller.
    $route = $collection->get('user.register');
    if ($route instanceof Route) {
      // ...
    }

Why is it here assumed that RouteCollection::get() would return objects which are not Route objects? If this can happen, why would we ignore this silently?

I see from the definition of \Symfony\Component\Routing\RouteCollection::get() that it only returns Route or NULL:

    /**
     * Gets a route by name.
     *
     * @param string $name The route name
     *
     * @return Route|null A Route instance or null when not found
     */
    public function get($name);

I'm not sure if something came up during testing that necessitated this if statement, but it seems more likely that this is just a mistake and the if statement can be simply removed. If is is necessary then we should have some clear documentation on why this can happen, and a test to prove that we handle the case correctly.

Ref. https://github.com/openeuropa/oe_authentication/blame/master/src/Routing/RouteSubscriber.php#L37

This entire class could use an overhaul by the way, there is almost no documentation, except for some comments that explain what the code is doing, but not why.

Replace heavy, proprietary mock CAS server with a lightweight and open source solution

When I follow the instructions I get an error regarding missing credentials when docker-compose attempts to download the authentication container:

$ docker-compose pull
Pulling web            ... done
Pulling mysql          ... done
Pulling selenium       ... done
Pulling authentication ... error

ERROR: for authentication  b'Get https://registry.fpfis.tech.ec.europa.eu/v2/ecas-mock-server/manifests/4.6.0: no basic auth credentials'
ERROR: Get https://registry.fpfis.tech.ec.europa.eu/v2/ecas-mock-server/manifests/4.6.0: no basic auth credentials

Can a container be made that mocks the service using open source software so that it can be made publicly accessible? There are many tools available that can be used to easily mock a REST or SOAP service.

Improve documentation

Add in the README.md:

  • the header of the paragraph concerning Docker.
  • More information concerning the private container euLogin.

Drupal 9 support

The core version if fixed to Drupal 8. Do you plat to add support of Drupal 9 ?

Use oe_authentication with Drupal 9

Hello,
I can see that a Drupal 8 core version is required for this module to install with composer. Will there be any Drupal 9 version of this module?

Thank you,
gb

Request for update of the openeuropa/oe_authentication module

Good morning,

I would like to request an update for the openeuropa/oe_authentication module. Recently, a new version to drupal/cas was released (version 2.3.1), but I noticed that openeuropa/oe_authentication still requires the previous version, 2.2.
image

Therefore, I kindly request that you update the openeuropa/oe_authentication module to make it compatible with the latest version of drupal/cas.

Thank you in advance for your attention, and I look forward to your response.

Best regards,
Cláudia Desidério

Compatibility issues with drush 13.0.0-beta1 and above.

In Drush 13.0.0-beta1 there is a change related to SanitizePluginInterface referenced by UserSanitizeCommand.

SanitizePluginInterface and SanitizeCommands are moved to new namespaces.

Error: Class "Drush\Drupal\Commands\sql\SanitizeCommands" not found in /test/toolkit/web/modules/contrib/oe_authentication/modules/oe_authentication_user_fields/src/Drush/Commands/sql/UserSanitizeCommand.php on line 69 #0 /test/toolkit/vendor/consolidation/annotated-command/src/Attributes/Hook.php(30): ReflectionAttribute->newInstance()

Error when validating ticket: Error Code INVALID_USER: Invalid user: "XXXXXXX" belongs to "SELF_REGISTERED" users while application accepts only "INTERNAL"

Hello, I have a login problem in my local version.
There is error in Drupal log:

Error when validating ticket: Error Code INVALID_USER: Invalid user: "XXXXXXX" belongs to "SELF_REGISTERED" users while application accepts only "INTERNAL" users or users with higher assuresponse received from CAS server:

In settings.php I have
$config['oe_authentication.settings']['assurance_level'] ='LOW';
$config['oe_authentication.settings']['base_url'] = 'https://webgate.ec.europa.eu/cas';

Redirect to user edit page after first login

Hi there,
is there a way to redirected to the user to the user edit page after the very first time login, like on ecas module (D7)?
We need to implement this behavior due to the privacy policy regulations.
Thank you in advance,
Fab

Compatibility with symfony/http-foundation v4.4.44

Cannot be installed with current latest Drupal 9 version.
Please update to be compatible with symfony/http-foundation v4.4.44

  • openeuropa/oe_authentication 1.8.0 requires symfony/http-foundation <=4.4.41
  • latest drupal 9 version of symfony is v4.4.44

Don't create and map user fields. Use cas_attributes instead

When installed, the module creates next base fields for the user entity: field_oe_firstname, field_oe_lastname, field_oe_department, field_oe_organisation. Also, on registering a new Drupal account with data taken from EU Login, it fills those fields with data.

This approach is hard coupled to a specific OE business model, preventing module reusability. The module should not be in business of configuring the user entity fields. That should be deferred to other module, to the parent project or to configuration management (if the fields are converted from base to configurable).

Also there's no way to allow users change data on the site, e.g family name, because everytime they are logging in, data from EU Login is overwriting the local changes.

Proposal

  • Stop adding user base fields.
  • Use cas_attributes module to map and set fields.

Import the user organisation

Initially, on Joinup project, we've been developed some code to sync the user's organisation with the EU Login organisation value. However, lately, our PO decided that Joinup users will manage locally their organisation(s) and the field should not be overwritten by the EU Login attribute.

The sync is not straight because EU Login doesn't provide the organisation name, but the organisation domain. So, the name has to be extracted from the ECAS Schema. Also, a mechanism has to be put in place that is caching locally the ECAS Schema, so that a HTTP request on each login is avoided. But, then, the system need to ensure that the local cached schema is periodically refreshed if there are upstream changes. Finally, from all these constraints, resulted some functionality that we had to drop.

We think that, if such a functionality is required for OE Authentication module, the code that we've built (dropped lately) can be easily adapted with minimum effort. The code is contained in the revert commit: ec-europa/joinup-dev@07c5aa6

UX: Module settings form location may confuse site builders

The CAS module settings are at: /admin/config/people/cas
The OE Authentication settings are at: /admin/config/system/oe_authentication

This is a little bit confusing from a UX perspective, as the 2 modules are very coupled and a site builder would expect to find the settings in proximity.

Proposal

Consider moving OE Authentication settings at /admin/config/people/cas/oe-authentication and add it as tab of the main CAS settings form.

Don't alter routes from the CAS module

For some reason the module is altering the path of the cas.login route to /eulogin. This is breaking the functionality as documented in the CAS module. There is no value in doing this.

The code responsible for this is as follows, as you can see there is no reason given to explain why this breaking change is required:

  protected function alterRoutes(RouteCollection $collection): void {
    // ...

    // Replace the cas callback route controller.
    if ($route = $collection->get('cas.proxyCallback')) {
      $route->setDefaults([
        '_controller' => '\Drupal\oe_authentication\Controller\ProxyCallbackController::callback',
      ]);
    }

    // Replace default cas login route with eulogin one.
    if ($route = $collection->get('cas.login')) {
      $route->setPath('/eulogin');
    }
  }

Also no reason is given for altering the proxyCallback controller.

Please make sure that these paths are made available without breaking the default URLs provided by the CAS module.

Delete user

The client has asked us to delete (not just block) a certain user.
We are using oe_authentication and we have seen that it blocks this possibility.
We wanted to confirm with you if this is a security restriction or if we can create a patch to remove that limitation?
Please can you explain the security reasons for this limitation?
Thanks!

missing modules oe_authentication

When following the installation instructions we fail when enabling the module in a Drupal 8 installation.

$ composer require  openeuropa/pcas
Using version ^0.2.2 for openeuropa/pcas
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Package openeuropa/pcas is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating autoload files
$ composer require openeuropa/oe_authentication
Using version ^0.5.0 for openeuropa/oe_authentication
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Package openeuropa/pcas is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
$ drush en oe_authentication
 
In PmCommands.php line 247:
 
  Unable to install modules oe_authentication due to missing modules oe_authentication.
 
 
pm:enable [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-d|--debug] [-y|--yes] [--no] [--remote-host REMOTE-HOST] [--remote-user REMOTE-USER] [-r|--root ROOT] [-l|--uri URI] [--simulate] [--pipe] [-D|--define DEFINE] [--druplicon] [--notify [NOTIFY]] [--xh-link XH-LINK] [--] <command> [<modules>]...

Do you have any idea what is going wrong?

Best
Ben

2FA and authentication level

Hello,

If we enable the option "Force two factor authentication" from the module settings (/admin/config/system/oe_authentication), we are still able to select the password authentication method from ECAS.
When we do so, we get a vague error in Drupal, which is very confusing for end users:

There was a problem validating your login, please contact a site administrator.

And the Drupal logs contain:

Error when validating ticket: Error Code INVALID_STRENGTH: ticket 'ST--' does not match requested strengths: [PASSWORD_MOBILE_APP, PASSWORD_SOFTWARE_TOKEN, PASSWORD_SMS]

Ideally EULogin should only list applicable login options.
I believe https://citnet.tech.ec.europa.eu/CITnet/confluence/display/IAM/Multi-factor+authentication is related and explains 3 types of authentication methods (basic/medium/high).
Shouldn't the module expose these 3 options (as select?) in settings instead of the "Force two factor authentication" checkbox?

Thank you

You are using an invalid service to access EU Login

Hi,

After installing this module I get the following error:

You are using an invalid service to access EU Login: ['https://d8tst.example.com/casservice?destination=/'] 

Selection_177

Instead of example.com I'm using a functional domain name.

Is there a need to register this website first before it can be used with EU login? I didn't seen any references in the README.md

Update information from EULogin

Currently the information received from eulogin is only updated during the first login.
Decide when this information should be updated (every login, during cron,...) and implement it

Rename base fields

The current base fields are prefixed with "field_". This is confusing since it makes them look like fields that were created through the Field API when they are not.

The goal of the ticket is twofold:

  • Rename the current fields and remove the 'field_' prefix
  • Provide an upgrade path for current users of the component.

External uses should be checked only against 'cas' provider

In \Drupal\oe_authentication\Access\ExternalUserAccessCheck::access() there is this piece of code:

if ($this->authMap->getAll($account->id()) === []) {
  return AccessResult::allowed();
}

Using ::getAll() here is wrong because on a system might offer support for multiple external authentication authorities (social media, Github, OpenID, etc.)

Even if limiting the access to those routes could be useful when using other provider/authority, this module should not make assumptions on behalf them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.