Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293925

Exception shown on 401 Unauthorized

$
0
0

When you visit a route that is protected with basic authentication and you do not provide credentials, then the resulting 401 page shows a stacktrace rather than a human friendly error message.

Steps to replicate:

  1. Create a route that is protected with basic authentication. For example put this in user.routing.yml:
    user.basic_auth:
      path: '/user/basic-auth'
      defaults:
        _form: '\Drupal\user\Form\UserLoginForm'
      options:
        _auth: [ 'basic_auth' ]
  2. Enable the basic_auth module.
  3. Visit the path user/basic-auth without an active session (easiest is to open an anonymous browser window to test)
  4. You will be asked to authenticate. Close the dialog without authenticating.

Result: the following backtrace is shown:

Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException: No authentication credentials provided. in Drupal\basic_auth\Authentication\Provider\BasicAuth->challengeException() (line 138 of core/modules/basic_auth/src/Authentication/Provider/BasicAuth.php).
Drupal\Core\Routing\AccessAwareRouter->matchRequest(Object)
Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(Object, 'kernel.request', Object)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.request', Object)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\PageCache->fetch(Object, 1, 1)
Drupal\Core\StackMiddleware\PageCache->lookup(Object, 1, 1)
Drupal\Core\StackMiddleware\PageCache->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1)
Stack\StackedHttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)

Expected result: A human readable message such as:

Unauthorized - Please log in to access this page.


Viewing all articles
Browse latest Browse all 293925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>