Add the Authorization header to requests.

@param BeforeEvent $event Event received
976854
public function onBefore(BeforeEvent $event)
    {
        $request = $event->getRequest();
        if ($request->getConfig()->get('auth') == 'oauth2') {
            $token = $this->getAccessToken();
            if ($token !== null) {
                $request->setHeader('Authorization', 'Bearer ' . $token->getToken());
            }
        }
    }
502728
public function beforeRender($event)
    {
        $this->Controller->set('authUser', $this->Controller->authUser);

        // beforeRender-event
        $_event = new Event('Component.Manager.beforeRender', $this, [
        ]);
        $this->Controller->eventManager()->dispatch($_event);

        if ($this->isPrefix()) {
            $this->_runCallback("beforeRender", $event);

            // beforeRender-event with Prefix
            $this->_runEvent("beforeRender");
        }
    }
351528
public function onPreContentView(PreContentViewEvent $event): void
    {
        $currentRequest = $this->requestStack->getCurrentRequest();
        if (!$currentRequest instanceof Request) {
            return;
        }

        $viewType = $currentRequest->attributes->get('viewType');

        $event->getContentView()->addParameters(
            [
                'view_type' => !empty($viewType) ? $viewType : '',
            ]
        );
    }
439725
public function beforeRedirect(Event $event)
    {
        $subject = $event->getSubject();

        $redirects = $this->_action()->redirectConfig();
        if (empty($redirects)) {
            return;
        }

        foreach ($redirects as $redirect) {
            if (!$this->_getKey($subject, $redirect['reader'], $redirect['key'])) {
                continue;
            }

            $subject->url = $this->_getUrl($subject, $redirect['url']);
            break;
        }
    }
421088
public function onBefore(BeforeEvent $event)
    {
        $request = $event->getRequest();
        $options = $request->getConfig();

        $videoManagerId = isset($options['videoManagerId']) ? $options['videoManagerId'] : null;
        $token = $this->tokenManager->getToken($videoManagerId);

        if (null !== $token) {
            $request->setHeader('Authorization', sprintf(self::AUTH_BEARER, $token));
        }
    }
240035
public function beforeDelete($event)
    {
        $oldId = $this->owner->{$this->savedAttribute};
        if (($oldModel = FileModel::findOne($oldId)) !== null) {
            $event->isValid = $event->isValid && $oldModel->delete();
        }
    }
785891
public function onRequestBeforeSend(Event $event)
    {
        $request = $event['request'];

        $request->setHeader('Accept',(string) $this->config['accept-header']);

        return $this->config['accept-header'];
    }
1343445
public function onBeforeSend(Event $event)
    {
        /** @var $request Request */
        $request = $event['request'];

        $id = $this->signatureCredentials->getMacId();
        $ts = $this->timeProvider->getCurrentTime()->getTimestamp();
        $nonce = $this->randomProvider->generateStringForRanges($this->nonceLength, self::$characterRanges);
        $ext = $this->extensionProvider->getExtensionParameters($request, $this->signatureCredentials, $ts, $nonce);
        $ext = http_build_query($ext, null, '&');
        $mac = $this->algorithmManager->generateMac($request, $this->signatureCredentials, $ts, $nonce, $ext);

        $params = array(
            'id' => $id,
            'ts' => $ts,
            'nonce' => $nonce,
            'ext' => $ext,
            'mac' => $mac,
        );

        $list = array();
        foreach ($params as $key => $value) {
            $list[] = $key . '="' . $value . '"';
        }
        $header = 'MAC ' . implode(', ', $list);

        $request->setHeader('Authorization', $header);
    }
705018
public function beforeFilter(Event $event)
    {
        EventManager::trigger('Controller.setup', $this);

        $pluginEvent = Plugin::getData('Core', 'Controller.beforeFilter');
        if (is_callable($pluginEvent->find(0)) && Plugin::hasManifestEvent('Controller.beforeFilter')) {
            call_user_func_array($pluginEvent->find(0), [$this, $event]);
        }
    }
178292
public function beforeFilter(\Cake\Event\Event $event)
    {
        parent::beforeFilter($event);

        // Auth-settings: Allows all user-related methods
        $this->Auth->allow(['resetPassword', 'forgotPassword', 'logout', 'login', 'activate', 'register']);

        // Setting up the base-theme
        if (!$this->theme) {
            $this->theme = "CakeManager";
        }

        // Setting up the base-layout
        if (!$this->layout) {
            $this->layout = "base";
        }

        $this->set('title', 'Users');
    }
1273102
public function beforeDispatch(Event $event)
    {
        $this->_setIdentifier($event->getData('request'));
        $this->_initCache();
        $this->_count = $this->_touch();

        $config = $this->getConfig();

        // client has not exceeded rate limit
        if ($this->_count <= $config['limit']) {
            $this->_setHeaders($event->getData('response'));

            return;
        }

        if (isset($config['message'])) {
            $message = $config['message'];
        } else {
            $message = $config['response']['body'];
        }

        // client has reached rate limit
        $event->stopPropagation();
        $response = new Response([
            'body' => $message,
            'status' => 429,
            'type' => $config['response']['type']
        ]);

        if (is_array($config['response']['headers'])) {
            foreach ($config['response']['headers'] as $name => $value) {
                $response = $response->withHeader($name, $value);
            }
        }

        return $response;
    }
472019
public function beforeRender(Event $event)
    {
        if (!array_key_exists('_serialize', $this->viewVars) &&
            in_array($this->response->type(), ['application/json', 'application/xml'])
        ) {
            $this->set('_serialize', true);
        }
    }
830628
public function onPreSendHAHeaders(HttpClientPreSendRequestEvent $event)
    {
        if ($event->getRequest()->getQueryMode() == 'WRITE') {
            $event->getRequest()->setHeader($this->queryModeHeaderName, $this->queryModeWriteQueryHeaderValue);
        } elseif ($event->getRequest()->getQueryMode() == 'READ') {
            $event->getRequest()->setHeader($this->queryModeHeaderName, $this->queryModeReadQueryHeaderValue);
        }
    }
227136
public function beforeFilter(\Cake\Event\Event $event)
    {
        parent::beforeFilter($event);

        $this->loadModel(Configure::read('CM.UserModel'));
    }
721601
public function before_request(&$url, &$headers, &$data, &$type, &$options)
    {
        $headers['Authorization'] = 'Basic '.base64_encode($this->token.':'.$this->key);
    }
922591
public function beforeFilter(Event $event)
    {
        $slug = lcfirst($this->request->params['type']);

        $this->type = $this->PostTypes->getOption($slug);

        if (!$this->type) {
            throw new Exception("The PostType is not registered");
        }

        $this->Model = TableRegistry::get($this->type['model']);

        // making the current item active
        $this->Menu->active($this->type['alias']);

        parent::beforeFilter($event);
    }
372215
public function preCreate(CreateEvent $event)
    {
        /** @var Group $role */
        $group = $event->getObject();
        $user = $this->tokenStorage->getToken()->getUser();

        if ($user instanceof User) {
            $group->addOrganization($user->getMainOrganization());
        }
    }