authenticationcakephpcomponentscakephp-2.xcakephp-2.7

How do I load a component inside a class that extends BaseAuthenticate in CakePHP?


I have created my own authenticator which handles OAuth 2:

class OauthAuthenticate extends BaseAuthenticate

I would like to use a custom component (extended from Component) in my OauthAuthenticate class.

How can I to load my component there? The traditional

public $components = array('OauthAuthenticate');

doesn't work - the component is not loaded.


Solution

  • BaseAuthenticate class cannot load component via $components array as is usual in controllers, but loading a component is possible in constructor:

    private $utilComponent = null;
    
        public function __construct(ComponentCollection $collection, array $settings)
        {
            $this->utilComponent = $collection->load('Util');
        }