mezzio / mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.
https://docs.mezzio.dev/mezzio-authentication-oauth2/
BSD 3-Clause "New" or "Revised" License
25 stars 17 forks source link

Ensure event listeners have a valid priority when added via the AuthorizationServerFactory #72

Closed akrabat closed 3 months ago

akrabat commented 3 months ago
Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

Defining a event listeners in the config for the AuthorizationServerFactory without a priority or with a priority that isn't a string is incorrect as per the signature of `League\Event\ListenerAcceptorInterface::addListener()' which is:

    /**
     * Add a listener for an event.
     *
     * [...]
     *
     * @param string                     $event
     * @param ListenerInterface|callable $listener
     * @param int                        $priority
     *
     * @return $this
     */
    public function addListener($event, $listener, $priority = self::P_NORMAL);

More importantly, if $priority is set to null (as is the default) then the error message "ArgumentCountError array_merge() does not accept unknown named parameters" is raised in League\Event\Emitter::getSortedListeners()

This PR sets the default priority to zero if it is not set in config and will throw an exception if a non-integer is configured for this property.

Fixes in #63.

Thanks @cardcc for the excellent report.

Ocramius commented 3 months ago

Thanks @akrabat!