Unable to install module due to missing authmap table

Created on 11 December 2023, about 1 year ago

Problem/Motivation

I have a site running Drupal 10.1.7. When I install and enable the module, a number of site functions break down. For example, when existing users (not created by SAML) attempt to login, they experience the error:

The website encountered an unexpected error. Please try again later.

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'cab.authmap' doesn't exist: SELECT "am"."authname" AS "authname" FROM "authmap" "am" WHERE ("uid" = :db_condition_placeholder_0) AND ("provider" = :db_condition_placeholder_1) LIMIT 1 OFFSET 0; Array ( [:db_condition_placeholder_0] => 2 [:db_condition_placeholder_1] => samlauth ) in Drupal\externalauth\Authmap->get() (line 63 of modules/contrib/externalauth/src/Authmap.php).
Drupal\Core\Database\StatementWrapperIterator->execute(Array, Array) (Line: 790)
Drupal\Core\Database\Connection->query('SELECT "am"."authname" AS "authname"
FROM
{authmap} "am"
WHERE ("uid" = :db_condition_placeholder_0) AND ("provider" = :db_condition_placeholder_1)
LIMIT 1 OFFSET 0', Array, Array) (Line: 525)
Drupal\Core\Database\Query\Select->execute() (Line: 63)
Drupal\externalauth\Authmap->get(2, 'samlauth') (Line: 118)
samlauth_check_saml_user(Array, Object)
call_user_func_array('samlauth_check_saml_user', Array) (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 275)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'user_login_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('user_login_form', Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('user_login_form', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 592)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Additionally, when I go to configure the SAML Auth, the Links tab results in the below error:

The website encountered an unexpected error. Please try again later.

Drupal\Core\Database\DatabaseExceptionWrapper: Exception in SAML Authentication Links[samlauth_map]: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'cab.authmap' doesn't exist: SELECT "authmap"."authname" AS "authmap_authname", "authmap"."uid" AS "authmap_uid", "users_field_data_authmap"."uid" AS "users_field_data_authmap_uid" FROM "authmap" "authmap" LEFT JOIN "users_field_data" "users_field_data_authmap" ON authmap.uid = users_field_data_authmap.uid WHERE "authmap"."provider" LIKE :db_condition_placeholder_0 ESCAPE '\\' ORDER BY "authmap_authname" ASC LIMIT 51 OFFSET 0; Array ( [:db_condition_placeholder_0] => samlauth ) in main() (line 19 of index.php).
Drupal\views\ViewExecutable->execute(NULL) (Line: 1469)
Drupal\views\ViewExecutable->render() (Line: 199)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1645)
Drupal\views\ViewExecutable->executeDisplay('page', Array) (Line: 81)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 797)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 386)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 592)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

First, I took a look at the README and attempted to go through the steps.

I installed the module using:

composer require 'drupal/samlauth:^3.9'

Then I went into the extend menu and enabled the following:

  • External Authentication
  • SAML Authentication
  • SAML Auth User Fields Mapping
  • SAML Auth User Role Assignment

For me, this is all it takes for the issues to start.

I attempted some solutions described below but all were unsuccessful. I did not proceed further with the setup because I have to push this to my staging server before configuring it, and as I am unable to login while these modules are installed, I am not be able to login as an admin to configure the module, so I rolled back.

Uninstalling the module completely gets rid of the bugs.

Attempted Solutions

1) I thought that maybe there are tables to create/update so I ran drush updb which said there were no pending updates.

2) The readme stated that a UI exists for the authmap at admin/config/people/saml/authmap so I attempted to visit this link to see if there is a function there to create the authmap table. This immediately threw a similar error to before:

The website encountered an unexpected error. Please try again later.

Drupal\Core\Database\DatabaseExceptionWrapper: Exception in SAML Authentication Links[samlauth_map]: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'cab.authmap' doesn't exist: SELECT "authmap"."authname" AS "authmap_authname", "authmap"."uid" AS "authmap_uid", "users_field_data_authmap"."uid" AS "users_field_data_authmap_uid" FROM "authmap" "authmap" LEFT JOIN "users_field_data" "users_field_data_authmap" ON authmap.uid = users_field_data_authmap.uid WHERE "authmap"."provider" LIKE :db_condition_placeholder_0 ESCAPE '\\' ORDER BY "authmap_authname" ASC LIMIT 51 OFFSET 0; Array ( [:db_condition_placeholder_0] => samlauth ) in main() (line 19 of index.php).
Drupal\views\ViewExecutable->execute(NULL) (Line: 1469)
Drupal\views\ViewExecutable->render() (Line: 199)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1645)
Drupal\views\ViewExecutable->executeDisplay('page', Array) (Line: 81)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 797)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 386)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 592)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Summary

Does anybody know how to fix this error and install this module successfully? It sounds like the authmap table failed to generate, but I am not sure what I can do to force it to re-generate.

💬 Support request
Status

Closed: works as designed

Version

3.9

Component

Code

Created by

🇨🇦Canada ciesinsg

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ciesinsg
  • 🇳🇱Netherlands roderik Amsterdam,NL / Budapest,HU

    I can't tell you what your issue is, only restrict the area to investigate.

    The authmap table is part of the External Authentication (externalauth) module (which SAML Authentication depends on). So first try uninstalling and reinstalling that, without the SAML modules

    Assuming there is no other module in your system that depends on externalauth, this should be easy enough. (And there likely is no other dependent module - because providing the authmap table is its only function - so your site would already have been broken.) Just check if the table exists.

    The externalauth module nowadays has its own UI/view for this table, at /admin/people/authmap - so if that works, your troubles should be over and you can enable the rest. And if it doesn't work, you need to trace why. The externalauth module is fairly simple in nature, its install procedure only creates the authmap table and so it should log an error if that fails.

  • 🇨🇦Canada ciesinsg

    I made some progress with this issue. I believe that the External Authentication dependency is what is responsible for creating the authmap table.

    After checking the update from Roderik, it looks like this is correct! Thanks for the support!

    In my case, I was able to get rid of the issues locally by uninstalling all of the SAML modules, as well as the External Authentication. After this, I removed "drupal/samlauth": "^3.9", from my composer.json file and ran composer update. Then, I started the installation over, but I was hesitant to simply checkmark all four modules like I did the first time I installed. Instead, I installed in the below order:

    External Authentication -> SAML Authentication -> SAML Auth User Fields Mapping & SAML Auth User Role Assignment

    I'm not sure if this order is necessary, but it seems to have resolved my issue and eliminated the errors I encountered during login and configuration.

    When pushing to staging, I had to repeat this process. In the staging environment, I had to manually uninstall all four modules. I didn't have to update the composer files, so this step may not be necessary. Then, I installed the modules in the same order as above. Once again, this resolved the errors I was encountering in local and staging.

  • Status changed to Closed: works as designed about 1 year ago
Production build 0.71.5 2024