Add the Authorization header to requests.

@param BeforeEvent $event Event received
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));
        }
    }
936249
public function beforeActionAccess(Event $event)
    {
        /** @var \yii\web\Controller $controller */
        $controller = $event->sender;
        if (!Yii::$app->user->can($controller->module->id.'/'.$controller->id.'/'.$controller->action->id)) {
            if (Yii::$app->user->isGuest) {
                $controller->redirect(Yii::$app->user->loginUrl) && Yii::$app->end();
            }
            throw new HttpException(403, Yii::t('app', 'Access denied'));
        }
    }
922430
public function beforeRender(Event $event)
    {
        parent::beforeRender($event);

        $this->set('detect', $this->detect);
    }
1106064
public function beforeFilter(Event $event)
    {
        $this->TimebasedCurrencyPayment = TableRegistry::getTableLocator()->get('TimebasedCurrencyPayments');
        $this->TimebasedCurrencyOrderDetail = TableRegistry::getTableLocator()->get('TimebasedCurrencyOrderDetails');
        parent::beforeFilter($event);
    }
263233
public static function beforeActionAccess($event)
    {
        $controller = $event->sender;
        $permissionName = AuthItem::createPermissionName([$controller->module->id, $controller->id, $controller->action->id]);
        if (!AuthItem::checkAccess($permissionName, Yii::$app->user)) {
            throw new HttpException(403, Yii::t('modules/rbac', 'Access denied'));
        }
    }
1320392
public function signRequest(Event $event) {
        $command = $event['command'];

        switch ($command->getName()) {
            case 'AddImage':
            case 'DeleteImage':
            case 'ReplaceMetadata':
            case 'EditMetadata':
            case 'DeleteMetadata':
            case 'GenerateShortUrl':
            case 'EditResourceGroup':
            case 'DeleteResourceGroup':
            case 'EditPublicKey':
            case 'DeletePublicKey':
            case 'AddAccessControlRules':
            case 'DeleteAccessControlRule':
                // Add the auth headers
                $this->addAuthenticationHeaders($command->getRequest());
                break;
        }
    }
1205514
protected function beforeValidate($event)
    {
        if ($this->autoSave) {
            $this->owner->{$this->uploadAttribute} = $this->getUploadedFile();
        }
    }
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]);
        }
    }
10223
public function beforeRender(Event $event): void
    {
        $this->setJson('isAjax', $this->_controller->request->is('ajax'));
        $this->setJson('isMobile', $this->_controller->request->is('mobile'));
        $this->setBoth('isDialog', $this->_controller->request->is('dialog'));
        $this->setBoth('isJson', $this->_controller->request->is('json'));
        $this->setJson('debug', Configure::read('debug'));

        $ssl = false;
        if (env('HTTPS') || $this->_controller->request->is('ssl') || $this->_controller->request->env('HTTP_X_FORWARDED_PROTO') == 'https') {
            $ssl = true;
        }

        $appData = array(
            'jsonData' => $this->_jsonData,
            'webroot' => 'http' . ($ssl ? 's' : '') . '://' . env('HTTP_HOST') . $this->_controller->request->webroot,
            'url' => $this->_controller->request->url,
            // 'controller' => $this->_controller->name,
            // 'action' => $this->_controller->request->action,
            // 'plugin' => $this->_controller->request->plugin,
            'request' => array(
                'query' => $this->_controller->request->query,
                'pass' => $this->_controller->request->params['pass'],
                'plugin' => $this->_controller->request->plugin,
                'controller' => Inflector::underscore($this->_controller->name),
                'action' => $this->_controller->request->action
            )
        );

        // merge in the additional frontend data
        $appData = Hash::merge($appData, $this->_additionalAppData);
        $this->_controller->set('frontendData', $appData);
        $this->_controller->set('closeDialog', $this->_closeDialog);
    }
766294
public function onBeforeNormalization(BeforeNormalizationEvent $event): void
    {
        $resource = $event->getResource();

        if (!$resource instanceof RelatedResourceInterface) {
            return;
        }

        $relations = $resource->getRelations();

        foreach ($relations as $relation) {
            if (!$relation instanceof SymfonyGrantedRelation) {
                continue;
            }

            if (!$this->authorizationChecker->isGranted($relation->getAttribute(), $relation->getObject())) {
                $resource->removeRelation($relation);
            }
        }
    }
1128725
public function preSend(Event $e)
    {
        $validator = new NotEmpty();

        if (!isset($this->options['tokenOrLogin'])
            || !$validator->isValid($this->options['tokenOrLogin'])
        ) {
            throw new Exception\InvalidArgumentException('You need to set OAuth token!');
        }

        /* @var Http\Request $request */
        $request = $e->getTarget();

        $headers = $request->getHeaders();
        $params = array(
            'Authorization' => 'token ' . $this->options['tokenOrLogin'],
        );
        $headers->addHeaders($params);
    }
724543
public static function setPermissionsChmod(Event $event)
	{
		$http_user = self::getHttpdUser($event);
		foreach (self::getWritableDirs($event) as $path) {
			self::ChmodPermissionsSetter($event, $http_user, $path, 'dir');
		}
		foreach (self::getWritableFiles($event) as $path) {
			self::ChmodPermissionsSetter($event, $http_user, $path, 'file');
		}
	}
1207663
public function beforeValidate($event)
    {
        parent::beforeValidate($event);
        if ($this->owner->hasAttribute($this->statusAttribute) && !isset($this->owner->{$this->statusAttribute})) {
            $this->owner->{$this->statusAttribute} = $this->defaultStatus;
        }
    }
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);
        }
    }
7019
public function beforeRun($event)
    {
        $id = $this->owner->options['id'];
        $options = Json::htmlEncode($this->getClientOptions());
        $view = $this->owner->getView();
        GridViewAsset::register($view);
        $view->registerJs("jQuery('#$id').yiiGridView($options);");
    }
582216
public function onRequestBeforeSend(Event $event)
    {
        $timestamp = $this->getTimestamp($event);
        $request = $event['request'];
        $nonce = $this->generateNonce($request);
        $authorizationParams = $this->getOauthParams($timestamp, $nonce);
        $authorizationParams['oauth_signature']  = $this->getSignature($request, $timestamp, $nonce);

        switch ($this->config['request_method']) {
            case self::REQUEST_METHOD_HEADER:
                $request->setHeader(
                    'Authorization',
                    $this->buildAuthorizationHeader($authorizationParams)
                );
                break;
            case self::REQUEST_METHOD_QUERY:
                foreach ($authorizationParams as $key => $value) {
                    $request->getQuery()->set($key, $value);
                }
                break;
            default:
                throw new \InvalidArgumentException(sprintf(
                    'Invalid consumer method "%s"',
                    $this->config['request_method']
                ));
        }

        return $authorizationParams;
    }
114756
protected function beforeSave($event)
    {
        if ($this->autoSave) {
            $this->saveFile($this->owner->{$this->uploadAttribute}, $this->name, $this->path);
        }
    }