@param string|array $authorization
@param callable|\Spatie\Menu\Menu|\Spatie\Menu\Item $header
@param callable|\Spatie\Menu\Menu|null $menu

@return $this
509038
public function submenuIfCan($authorization, $header, $menu = null)
    {
        list($authorization, $header, $menu) = $this->parseSubmenuIfCanArgs(...func_get_args());

        $menu = $this->createSubmenuMenu($menu);
        $header = $this->createSubmenuHeader($header);

        return $this->addIfCan($authorization, $menu->prependIf($header, $header));
    }
274840
protected function parseAuthHeader($header = 'authorization', $method = 'bearer')
    {
        $header = $this->request->headers->get($header);

        if (! starts_with(strtolower($header), $method)) {
            return false;
        }

        return trim(str_ireplace($method, '', $header));
    }
291788
public function withHeadings($headings = null)
    {
        $headings = \is_array($headings) ? $headings : \func_get_args();

        if (0 === count($headings)) {
            $this->headingCallback = $this->autoHeading();
        } else {
            $this->headingCallback = function () use ($headings) {
                return $headings;
            };
        }

        return $this;
    }
959478
protected function prefillHeader()
    {
        if ($this->requiresAuthorization() && !empty($this->getAuthorizationHeader())) {
            $this->headers['Authorization'] = $this->getAuthorizationHeader();
        }
        return $this;
    }
58832
public function authorisation(Container $container)
    {
        $auth   = new Authorisation();
        $config = $container->get('config');

        foreach ((array) $config->get('user.policies') as $name => $policy) {
            if ($policy instanceof ClassMeta || (is_string($policy) && class_exists($policy))) {
                $instance = $container->newInstance($policy);

                if (is_subclass_of($instance, PolicyInterface::class)) {
                    $auth->addPolicy($name, $instance);
                } elseif (is_subclass_of($instance, PolicyProviderInterface::class)) {
                    $auth->registerPolicyProvider($instance);
                }
            } elseif ($policy === false) {
                continue;
            } else {
                throw new \InvalidArgumentException(sprintf(
                    'Please register instance of %s or %s',
                    PolicyInterface::class,
                    PolicyProviderInterface::class
                ));
            }
        }

        /** @var EventDispatcher $dispatcher */
        $this->dispatcher->triggerEvent('onLoadAuthorisationPolicies', ['auth' => $auth]);

        return $auth;
    }
993445
public function authorize($action, $config = array())
    {
        if (is_string($config)) {
            $config = array($action => $config);
        }

        $config = AnConfig::unbox($config);

        $context = $this->_mixer->getRepository()->getCommandContext();

        $context->append($config)->append(array(
            'viewer' => get_viewer(),
            'mixer' => $this->_mixer,
        ));

        $authorizers = $this->_authorizers;
        $result = LibBaseDomainAuthorizerAbstract::AUTH_NOT_IMPLEMENTED;

        foreach ($authorizers as $authorizer) {
            $result = $authorizer->execute($action, $context);
            if ($result !== LibBaseDomainAuthorizerAbstract::AUTH_NOT_IMPLEMENTED) {
                break;
            }
        }

        $context->authorization = $result;

        $method = 'authorize'.ucfirst($action);

        if (method_exists($this->_mixer, $method)) {
            $ret = $this->_mixer->$method($context);

            if (!is_null($ret)) {
                $context->authorization = $ret;
            }
        }

        return $context->authorization;
    }
1093442
protected function addInstanceCommandsAuthorizationsToConfigForItems($items)
    {
        collect($this->instanceCommandHandlers)
            // Take all authorized instance commands...
            ->filter(function($instanceCommandHandler) {
                return $instanceCommandHandler->authorize();
            })

            // ... and Entity State if present...
            ->when($this->entityStateHandler, function(Collection $collection) {
                return $collection->push($this->entityStateHandler);
            })

            // ... and for each of them, set authorization for every $item
            ->each(function($commandHandler) use($items) {
                foreach ($items as $item) {
                    $commandHandler->checkAndStoreAuthorizationFor(
                        $item[$this->instanceIdAttribute]
                    );
                }
            });
    }
226654
public function setAuthorizationFlow($name, $flow, $authorizationUrl, $tokenUrl, $refreshUrl = null, array $scopes = null)
    {
        if (!isset($this->authFlows[$name])) {
            $this->authFlows[$name] = [];
        }

        $this->authFlows[$name][] = [$flow, $authorizationUrl, $tokenUrl, $refreshUrl, $scopes];
    }
124805
public function setToken(string $token, int $authentication = self::OAUTH_AUTH): AbstractApi
    {
        $this->token = $token;
        $this->setAuthentication($authentication);

        return $this;
    }
418612
public function withoutHeader($header)
    {
        if ($this->complete) {
            return $this;
        }

        $new = $this->psrResponse->withoutHeader($header);
        return new self($new);
    }
294908
public function set_header($header, $content = null)
	{
		if (is_null($content))
		{
			$this->headers[] = $header;
		}
		else
		{
			$this->headers[$header] = $content;
		}

		return $this;
	}
478507
public function post($path, array $parameters, $authorization = false)
    {
    	$query = [];

    	if ($authorization)
    	    $query = [
    	        'client_id' => $this->client_key,
    	    	'client_secret' => $this->client_secret,
    	    	'redirect_uri' => $this->redirect_uri,			 
    	    	'grant_type' => 'authorization_code',
    	    ];

    	if ($parameters)
            $query = array_merge($query, $parameters);

        try {
    	    $response = $this->client->request('POST', $path, [
    	        'form_params' => $query,
		        'timeout' => self::TIMEOUT
    	    ]);

            return $this->toArray($response);
    	} 
    	catch (ClientException $e) {
    	    return $this->toArray($e->getResponse());
        }    	
    }
842649
public function handle(RequestInterface $request): RequestInterface
    {
        if ($this->token === '' || $this->key === '') {
            throw new AuthorizationException('Could not create api token, missing or empty arguments');
        }
        return $request->withHeader($this->key, $this->token);
    }
480275
public function addHeader($title, $order = null)
    {
        $this->items[] = new MenuItem(array(
            'name' => 'header',
            'title' => $title,
            'order' => $order,
        ));

        return $this;
    }
559810
protected function authorize($user, Gate $gate, string $ability, array $args): void
    {
        $can = $gate->forUser($user)->check($ability, $args);

        if (! $can) {
            throw new AuthorizationException(
                "You are not authorized to access {$this->definitionNode->name->value}"
            );
        }
    }
884242
protected function runAuthorizesWithApiKeyTasks($method, &$path, &$options, &$withAuthorization)
    {
        // By default, we append the authorization header to every request.
        if ($withAuthorization) {
            $authorizationHeader = $this->getAuthorizationHeader();
            $options['headers'] = array_merge($this->defaultHeaders, $options['headers'], $authorizationHeader);
        }
    }
1002099
protected function buildAuthorizationHeaderForAPIRequest(
        $method,
        Url $uri,
        TokenInterface $token,
        $bodyParams = null
    ) {
        $this->signature->setTokenSecret($token->getAccessTokenSecret());
        $authParameters = $this->getBasicAuthorizationHeaderInfo();
        if (isset($authParameters[ 'oauth_callback' ])) {
            unset($authParameters[ 'oauth_callback' ]);
        }

        $authParameters = array_merge($authParameters, ['oauth_token' => $token->getAccessToken()]);

        $signatureParams = (is_array($bodyParams)) ? array_merge($authParameters, $bodyParams) : $authParameters;
        $authParameters[ 'oauth_signature' ] = $this->signature->getSignature($uri, $signatureParams, $method);

        $authorizationHeader = 'OAuth ';
        $delimiter = '';

        foreach ($authParameters as $key => $value) {
            $authorizationHeader .= $delimiter . rawurlencode($key) . '="' . rawurlencode($value) . '"';
            $delimiter = ', ';
        }

        return $authorizationHeader;
    }