Extracts access_token from web request
@return string
@throws Exception
324804
public function extract()
    {
        $headerToken = null;
        foreach ($this->_request->getHeaders()->get('Authorization', [], false) as $authHeader) {
            if (preg_match('/^Bearer\\s+(.*?)$/', $authHeader, $matches)) {
                $headerToken = $matches[1];
                break;
            }
        }
        $postToken = $this->_request->post('access_token');
        $getToken = $this->_request->get('access_token');

        // Check that exactly one method was used
        $methodsCount = isset($headerToken) + isset($postToken) + isset($getToken);
        if ($methodsCount > 1) {
            throw new Exception(Yii::t('conquer/oauth2', 'Only one method may be used to authenticate at a time (Auth header, POST or GET).'));
        } elseif ($methodsCount === 0) {
            throw new Exception(Yii::t('conquer/oauth2', 'The access token was not found.'));
        }

        // HEADER: Get the access token from the header
        if ($headerToken) {
            return $headerToken;
        }

        // POST: Get the token from POST data
        if ($postToken) {
            if (!$this->_request->isPost) {
                throw new Exception(Yii::t('conquer/oauth2', 'When putting the token in the body, the method must be POST.'));
            }
            // IETF specifies content-type. NB: Not all webservers populate this _SERVER variable
            if (strpos($this->_request->contentType, 'application/x-www-form-urlencoded') !== 0) {
                throw new Exception(Yii::t('conquer/oauth2', 'The content type for POST requests must be "application/x-www-form-urlencoded".'));
            }
            return $postToken;
        }

        return $getToken;
    }
780641
public function getAuthToken()
    {
        if(!isset($this->__token))
        {
            $token   = false;
            $request = $this->getObject('request');

            if($request->headers->has('Authorization'))
            {
                $header = $request->headers->get('Authorization');

                if(stripos($header, 'jwt') === 0) {
                    $token = substr($header , 4);
                }
            }

            if($request->isSafe())
            {
                if($request->query->has('auth_token')) {
                    $token = $request->query->get('auth_token', 'url');
                }
            }
            else
            {
                if($request->data->has('auth_token')) {
                    $token = $request->data->get('auth_token', 'url');
                }
            }

            if($token) {
                $token = $this->getObject('lib:http.token')->fromString($token);
            }

            $this->__token = $token;
        }

        return $this->__token;
    }
1250647
protected function getAccessToken()
    {
        switch ($this->grant) {
            case 'provided_token':
                return $this->token;

            case 'client_credentials':
                return $this->getFrameworkBridge()->getClientToken();

            case 'authorization_code':
                $user = $this->getFrameworkBridge()->getCurrentUser();

                if (! $user) {
                    return null;
                }

                return $user->getOAuthToken();

            default:
                throw new \Exception('Unsupported grant type. Check $this->grant.');
        }
    }
268829
public function getAccessToken() {
        if (!is_null($this->_cachedAccessToken) &&
            $this->_cachedAccessToken->isValid()) {
            return $this->_cachedAccessToken;
        }

        $this->_cachedAccessToken = $this->acquireAccessToken();
        return $this->_cachedAccessToken;
    }
518129
public static function getCSRFToken() {
        $allHeaders = array_change_key_case(parent::getHeaders(), CASE_UPPER);

        if (array_key_exists('X-CSRF-TOKEN', $allHeaders)) {
            return $allHeaders['X-CSRF-TOKEN'];
        } else {
            throw new \Exception(ExceptionMessages::CSRF_TOKEN_NOT_FOUND);
        }
    }
679489
public function requestToken(){
		$url = 'https://api.dropbox.com/1/oauth/request_token';
		$params = $this->reqParams;
		$result = $this->web->request($url,array(
			'method'=>'POST',
			'content'=> http_build_query($params)
		));
		parse_str($result['body'], $output);
		if (array_key_exists('oauth_token_secret',$output) &&
			array_key_exists('oauth_token', $output))
		{
			return $output;
		} else {
			$result = json_decode($result['body'], true);
			trigger_error(sprintf(self::E_AUTHERROR,$result['error']));
		}
	}
757025
public function parse() : string
	{
		$raw_token = $this->_Request->getHeader($this->key);

		if(!$raw_token) {
			return '';
		}

		return trim( str_ireplace($this->prefix, '', $raw_token));
	}
231509
public function getToken()
    {
        $auth = $this->request->getHeader('Authorization');

        if (!$auth) {
            return null;
        }

        if ('bearer ' !== strtolower(substr($auth, 0, 7))) {
            return null;
        }

        return substr($auth, 7);
    }
150775
public function getToken()
    {
        if (Cache::has(self::CACHE_NAME)) {
            return Cache::get(self::CACHE_NAME);
        } else {
            $url    = $this->url."token";
            $option = [
                'grant_type'    => 'client_credentials',
                'client_id'     => $this->client_id,
                'client_secret' => $this->client_secret,
            ];
            $return = Http::postCurl($url, $option);
            Cache::put(self::CACHE_NAME, $return['access_token'], (int) ($return['expires_in'] / 60));

            return $return['access_token'];

        }
    }
356443
protected function getToken(Request $request)
    {
        try {
            $this->validateAuthorizationHeader($request);

            $token = $this->parseAuthorizationHeader($request);
        } catch (Exception $exception) {
            if (! $token = $request->query('token', false)) {
                throw $exception;
            }
        }

        return $token;
    }
1233209
protected function obtainTokenFromSession()
    {
        global $_SESSION;

        if (!isset($_SESSION['formsTokens'])) {
            throw new Exception('no token found', $this::ERR_NO_TOKEN);
        }

        if (!isset($_SESSION['formsTokens'][$this->formId])) {
            throw new Exception(
                'no token found for the form id '.$this->formId,
                $this::ERR_NO_TOKEN_FOR_FORM_ID
            );
        }

        return $_SESSION['formsTokens'][$this->formId];
    }
1311412
public function get_access_token() {
        if (isset ($this->ll_access_token) && !is_null($this->ll_access_token)) {
            return $this->ll_access_token;
        }

        $app_client_values = array(
            'client_id' => $this->client_id,
            'client_secret' => $this->client_secret,
            'grant_type' => 'client_credentials'
        );

        $access_data = MPRestClient::post(array(
            "uri" => "/oauth/token",
            "data" => $app_client_values,
            "headers" => array(
                "content-type" => "application/x-www-form-urlencoded"
            )
        ));

        if ($access_data["status"] != 200) {
            throw new MercadoPagoException ($access_data['response']['message'], $access_data['status']);
        }

        $this->access_data = $access_data['response'];

        return $this->access_data['access_token'];
    }
647432
private function extractAuthKeyFromPemContent()
    {
        $details = openssl_pkey_get_details(openssl_pkey_get_private($this->pem));
        if (!array_key_exists('key', $details)) {
            return null;
        }

        // Remove BEGIN RSA PRIVATE KEY / END RSA PRIVATE KEY lines
        $KeyStr = trim($details['key']);
        // Support line break on *nix systems, OS, older OS, and Microsoft
        $keyArr = preg_split('/\r\n|\r|\n/', $KeyStr);
        if (strpos($KeyStr, 'BEGIN') !== false) {
            array_shift($keyArr);
            array_pop($keyArr);
        }
        $authKey = implode('', $keyArr);

        // Check auth key is not empty
        if (empty($authKey)) {
            throw new RequestException('Could not retrieve Auth key from PEM content.', 401);
        }

        return $authKey;
    }
1215399
public function getAuthoriseUrl()
    {
        // Get the request token
        $token = $this->getToken();
    
        // Prepare request parameters
        $params = array(
            'oauth_token' => $token->oauth_token,
            'oauth_token_secret' => $token->oauth_token_secret,
            'oauth_callback' => $this->callback,
        );
    
        // Build the URL and redirect the user
        $query = '?' . http_build_query($params, '', '&');
        $url = self::WEB_URL . self::AUTHORISE_METHOD . $query;
        return $url;
    }
993180
protected function getAuthToken()
    {
        $token = $this->request->getHeader('X_AUTHORIZATION');
        if (!$token) {
            $request = $this->getDI()->get('request');
            $token = $request->getQuery('token') ?: $request->getPost('token');
        }

        $token = trim(str_ireplace('Token:', '', $token));
        if (strlen($token) < 30) {
            throw new HTTPException('Unauthorized access blocked', 401, [
                'dev' => 'Supplied Token: ' . $token,
                'code' => '98914681681864674'
            ]);
        }
        return $token;
    }
1216506
public function revokeAccessToken()
    {
        $grantType = $this->getRequest()->request->get('grant_type') ? $this->getRequest()->request->get('grant_type') : 'password';
        $token = $this->getRequest()->request->get('token');
        if (is_null($token)) {
            throw new Exception\InvalidRequestException('token');
        }
        $token_type_hint = $this->getRequest()->request->get('token_type_hint');
        if (! is_null($token_type_hint) && $token_type_hint == 'refresh_token') {
            $authorization = ! empty(Request::header()['authorization'][0]) ? str_replace('Bearer ','', Request::header()['authorization'][0]) : null;
            if (is_null($authorization)) {
                throw new Exception\InvalidRequestException('access_token');
            }
        }
        // Ensure grant type is one that is recognised and is enabled
        if (!in_array($grantType, array_keys($this->grantTypes))) {
            throw new Exception\UnsupportedGrantTypeException($grantType);
        }
        if ($grantType != 'password' && $grantType != 'refresh_token') {
            throw new Exception\UnsupportedRevokeTypeException;
        }
        // Complete the flow

        return $this->getGrantType($grantType)->revokeFlow();
    }
1366884
public function getAccessToken()
    {
        if (null === $this->accessTokens) {
            $this->accessTokens = [];
        }

        if (!array_key_exists($this->getRegion(), $this->accessTokens)) {
            $this->accessTokens[$this->getRegion()] = $this->requestAccessToken();
        }

        return $this->accessTokens[$this->getRegion()]->getToken();
    }