alcalyn/authorization-header-fix

Simple listener that restore Authorization header in a Symfony Request under Apache.

1.0.1 2016-12-04 13:53 UTC

This package is not auto-updated.

Last update: 2024-11-13 20:36:44 UTC


README

Using a Symfony application on Apache, you get null when trying to get Authorization header with $request->headers->get('Authorization');.

The why is explained in this Stackoverflow question.

So if you don't want to patch your .htaccess, this library, inspired by fschmengler's answer in this another SO question, provides a listener which adds the Authorization header to a Symfony Request instance.

Installation

Download

Using Composer:

{
    "require": {
        "alcalyn/authorization-header-fix": "1.0.x"
    }
}

Register listener

To fix all Requests in a full stack Symfony app, register a listener like this:

# app/config/services.yml
services:
    acme.listeners.authorization_header_fix:
        class: Alcalyn\AuthorizationHeaderFix\AuthorizationHeaderFixListener
        tags:
            - { name: kernel.event_listener, event: kernel.request, priority: 10 }

Or using Silex:

$this->on('kernel.request', array(
    new Alcalyn\AuthorizationHeaderFix\AuthorizationHeaderFixListener(),
    'onKernelRequest'
), 10);

Note:

An higher priority is recommended to have the Authorization header available in others listeners.

License

This library is under MIT License.