Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Cannot login to D9 SP #71

Closed
TarxoR opened this issue Apr 3, 2021 · 9 comments
Closed

Cannot login to D9 SP #71

TarxoR opened this issue Apr 3, 2021 · 9 comments
Assignees

Comments

@TarxoR
Copy link

TarxoR commented Apr 3, 2021

Hi,

First of all Thanks for your work on this module.

I am trying to make an install where a Drupal instance works as IdP with another D9 instance working as SP.

Drupal version : 9.1.5
DrupalAuth version 8.x-1.1

The configuration is OK, but upon login :

  • i go to SP website click on Federated Login, which brings me to IDP website
  • i enter username & password and i get the following message :

The website encountered an unexpected error. Please try again later.
Error: Call to a member function setFormClass() on null in field_ui_entity_type_build() (line 74 of ore/modules/field_ui/field_ui.module).
field_ui_entity_type_build(Array) (Line: 129)
Drupal\Core\Entity\EntityTypeManager->findDefinitions() (Line: 175)
Drupal\Core\Plugin\DefaultPluginManager->getDefinitions() (Line: 83)
Drupal\Core\Entity\EntityTypeRepository->getEntityTypeFromClass('Drupal\user\Entity\User') (Line: 487)
Drupal\Core\Entity\EntityBase::load('2') (Line: 156)
SimpleSAML\Module\drupalauth\Auth\Source\External->getUser() (Line: 176)
SimpleSAML\Module\drupalauth\Auth\Source\External->authenticate(Array) (Line: 210)
SimpleSAML\Auth\Source->initLogin(Array, NULL, Array) (Line: 169)
SimpleSAML\Auth\Simple->login(Array) (Line: 357)
SimpleSAML\IdP->authenticate(Array) (Line: 415)
SimpleSAML\IdP->handleAuthenticationRequest(Array) (Line: 492)
SimpleSAML\Module\saml\IdP\SAML2::receiveAuthnRequest(Object) (Line: 26)

I went through the installation process + config multiple times.

Thank you in advance for your help/guidance.

@RoSk0
Copy link
Collaborator

RoSk0 commented Apr 4, 2021

Thanks for reporting this. I will try to replicate that, but it doesn't look like the problem is in this module.

Have a look at https://github.com/drupal/core/blob/9.1.5/modules/field_ui/field_ui.module#L74:

$entity_types['field_config']->setFormClass('edit', 'Drupal\field_ui\Form\FieldConfigEditForm');

Hm, however it maybe that Drupal haven't booted properly...

@RoSk0 RoSk0 self-assigned this Apr 4, 2021
@TarxoR
Copy link
Author

TarxoR commented Apr 4, 2021

Hello again,

you can replicate by creating a second index.php (vendor/simplesamlphp/simplesamlphp/www/index2.php)

boot Drupal then try to directly load user User::load(1); this will fail as it needs to be in context of drupal.

if you change dir before User::load, it will work.

I will try to find a better, proper solution and get back to you if successful.

@RoSk0
Copy link
Collaborator

RoSk0 commented Apr 4, 2021

I tried to replicate but setting up d9 9.2.x idp and d9 sp . Works as designed.

you can replicate by creating a second index.php (vendor/simplesamlphp/simplesamlphp/www/index2.php)

If you modified any of the files are on your own.

@RoSk0 RoSk0 closed this as completed Apr 4, 2021
@TarxoR
Copy link
Author

TarxoR commented Apr 5, 2021

It was only an example, I never modify lib/core file (unless i intend to propose updates).

It is crazy.
We are two devs, following the same docs (https://dev.to/esnaremaussa/single-sign-on-with-simplesamlphp-and-drupal-9-1h1b) ... without lando, simply docker.

And we both have the same issue.

I will keep digging, as this lib/module is our last hope.

@RoSk0
Copy link
Collaborator

RoSk0 commented Apr 5, 2021

That was a rude reply, sorry.

I tried to reproduce this on the real clean install. The boot method is bootstrapping a Drupal.

I'm pretty sure that the issue is not in the module, but your particular setup. Are you setting new project or are you adding new functionality to existing project?

@RoSk0 RoSk0 reopened this Apr 5, 2021
@TarxoR
Copy link
Author

TarxoR commented Apr 5, 2021

This is a clean install with standard profile.

Custom Docker image starting from php7.4-apache-buster-4 + Drupal
MariaDB docker image + Traeffik Image

composer require drupal/simplesamlphp_auth
drush en simplesamlphp_auth

I add the following lines to the end of config.php on IDP

$config['secretsalt'] = '53k1ftm1duxts4bi2lmefkuut1fuqksh';
$config['auth.adminpassword'] = 'idp';
$config['store.type'] = 'sql';
$config['store.sql.dsn'] = 'mysql:host=db;dbname=d9_provider';
$config['store.sql.username'] = 'root';
$config['store.sql.password'] = 'mdp';
$config['enable.saml20-idp'] = true;

$config['baseurlpath'] = 'https://'. $_SERVER['HTTP_HOST'] . '/simplesaml/';

$config['session.cookie.secure'] = true;

Finally certs, metadata, authsources, idp-hosted, sp-remote as instructed.

Similar install for the SP :

Custom Docker image starting from php7.4-apache-buster-4 + Drupal
MariaDB docker image + Traeffik Image

composer require drupal/simplesamlphp_auth
drush en simplesamlphp_auth

config.php on SP:

$config['secretsalt'] = '2gznxwd8aco0ca6ktegb766pmzk4j9f0';
$config['auth.adminpassword'] = 'client';
$config['store.type'] = 'sql';
$config['store.sql.dsn'] = 'mysql:host=db;dbname=d9_client';
$config['store.sql.username'] = 'root';
$config['store.sql.password'] = 'mdp';

$config['baseurlpath'] = 'https://'. $_SERVER['HTTP_HOST'] . '/simplesaml/';

$config['session.cookie.secure'] = true;
  • certs, authsources, idp-hosted, idp-remote.

Upong login it fails with the mentioned message.

The only thing that works is by modifying in drupalauth module External.php this part:

        if (!empty($drupaluid)) {
            // Load the user object from Drupal.
$originalDir = getcwd();
chdir($this->config->getDrupalroot());
            $drupaluser = User::load($uid);
chdir($originalDir);
            if ($drupaluser->isBlocked()) {
                throw new Error('NOACCESS');
            }

            $requested_attributes = $this->config->getAttributes();

            return $drupalHelper->getAttributes($drupaluser, $requested_attributes);
        }

This does not work for me as I do not agree with modifying source code.

For the moment this is in DEV environement as Proof of Concept.
The target will be 1 IDP with over 100 SP.

I can provide any details if needed.

i am grateful for your help on this issue

@RoSk0
Copy link
Collaborator

RoSk0 commented Apr 6, 2021

This is really interesting.

When you say

simply docker

what do you mean by that ? How do you manage container connections, volume mounts, etc?

Can you please try replicating your issue using Lando and config from https://dev.to/esnaremaussa/single-sign-on-with-simplesamlphp-and-drupal-9-1h1b

@TarxoR
Copy link
Author

TarxoR commented Apr 8, 2021

After you last comment I've started analysing "What have I added to my default Drupal installation that could conflict ?"

Finally, the answer is : Disabling cache

I always disable cache on DEV environment following this guide :

https://www.drupal.org/node/2598914

$cache_bins = array('bootstrap','config','data','default','discovery','dynamic_page_cache','entity','menu','migrate','render','rest','static','toolbar');
foreach ($cache_bins as $bin) {
  $settings['cache']['bins'][$bin] = 'cache.backend.null';
}

The discovery bin is the problem.

Everything works as expected now.

Thank you for your patience and interest.

@RoSk0
Copy link
Collaborator

RoSk0 commented Apr 8, 2021

That's rough, but I'm glad you found your issue.

I would really question suggestions in that guide. Never doing it myself - too many issues in the past when caching wasn't considered during development. Also, have a look https://github.com/drupal/drupal/blob/9.2.x/sites/example.settings.local.php most cache disabling examples have strong warnings about consequences.

@RoSk0 RoSk0 closed this as completed Apr 8, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants