Extract the token either from Authorization header or query params

@return string|null
495410
private function extractAccessToken(ServerRequestInterface $request)
    {
        // The preferred way is using Authorization header
        if ($request->hasHeader('Authorization')) {
            // Header value is expected to be "Bearer xxx"
            $parts = explode(' ', $request->getHeaderLine('Authorization'));

            if (count($parts) < 2) {
                return null;
            }

            return end($parts);
        }

        // Default back to authorization in query param
        $queryParams = $request->getQueryParams();

        return $queryParams['access_token'] ?? null;
    }
43410
public function getTokenString()
    {
        if (!$this->tokenString) {
            $token = $this->httpRequest()->header('Authorization');
            if (!$token) {
                $token = $this->httpRequest()->post('Authorization');
            }

            return $token;
        }

        return $this->tokenString;
    }
781901
private function get_access_token() {
        global $SESSION;
        if (isset($SESSION->{self::SESSIONKEY}) && $SESSION->{self::SESSIONKEY}) {
            $this->client->setAccessToken($SESSION->{self::SESSIONKEY});
            return $SESSION->{self::SESSIONKEY};
        }
        return null;
    }
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;
    }
563417
public function authorizationToken() {
        $headers = apache_request_headers();
        foreach ($headers as $header => $value) 
            if($header == 'Authorization') {
                $tokens = explode(" ", $value);
                if($tokens[0] != 'Bearer' || empty($tokens[1]))
                    killer('511');
                return $tokens[1];
            }
        killer('401');
    }
936985
protected function getToken()
    {
        $query = $this->request->getQueryParams();
        $temp = $this->getSessionData('Socialite.oauth.temp');
        return $this->server->getTokenCredentials(
            $temp,
            A::get($query, 'oauth_token'),
            A::get($query, 'oauth_verifier')
        );
    }
716762
protected function getTokenFromCache()
    {
        if (!$this->cache || !$this->cache->hasItem(self::TOKEN_CACHE_KEY)) {
            return null;
        }

        /** @var Token $token */
        $token = $this->cache->getItem(self::TOKEN_CACHE_KEY)->get();

        if (!$token || !$token->getAuth()) {
            $this->logger->debug('No token in cache or auth is empty, returning null.');

            return null;
        }

        // invalidate token
        if ($this->isTokenExpired($token)) {
            $this->logger->debug('Token is expired.');

            $this->writeTokenInfoToDebugLog();

            return null;
        }

        return $token;
    }
977249
public function getAuthorizationToken()
    {
        $authorizationToken = "Client-ID {$this->provider->getClientId()}";

        if (! is_null($this->token)) {
            // Validate if the token object link to this class is expire
            // refresh it if it's the case
            if ($this->token->hasExpired()) {
                $this->refreshToken();
            }

            $authorizationToken = "Bearer {$this->token->getToken()}";
        }

        return $authorizationToken;
    }
769809
protected function getTokenFromHeader()
    {
        // if there is no authorization header present.
        if (!$this->getRequest()->headers->has('Authorization')) {
            // abort by returning null.
            return null;
        }

        // gets the full header string.
        $header = $this->getRequest()->headers->get('Authorization');

        // returns the token without the 'Bearer ' prefix.
        return Str::replaceFirst('Bearer ', '', $header);
    }
571359
private function GetHttpHeaderStrong()
    {
        $token = $this->_root->OAuthTokenManager->GetToken($this->GetAutenticationKey());

        if (is_null($token) || !isset($token->access_token) || !isset($token->token_type)) {
            throw new Exception('OAuth token is not created (or is invalid) for strong authentication');
        }

        return 'Authorization: ' . $token->token_type . ' ' . $token->access_token;
    }
95891
public function getBearerToken() {

	    $headers = null;
	    $token   = null;

	    if (isset($_SERVER['Authorization'])) {
	        $headers = \trim($_SERVER['Authorization']);
	    } elseif (isset($_SERVER['HTTP_AUTHORIZATION'])) { //Nginx or fast CGI
	        $headers = \trim($_SERVER['HTTP_AUTHORIZATION']);
	    } elseif (\function_exists('apache_request_headers')) {
	        $requestHeaders = \apache_request_headers();
	        // Server-side fix for bug in old Android versions (a nice side-effect of this fix means we don't care about capitalization for Authorization)
	        $requestHeaders = \array_combine(\array_map('ucwords', \array_keys($requestHeaders)), \array_values($requestHeaders));
	        if (isset($requestHeaders['Authorization'])) {
	            $headers = \trim($requestHeaders['Authorization']);
	        }
	    }

	    // HEADER: Get the access token from the header
	    if ($headers) {
	        if (\preg_match('/Bearer\s(\S+)/', $headers, $matches)) {
	            $token = $matches[1];
	        }
	    }

	    return $token;
	}
1309913
public function getAuthUserParamName() : ?string
   {

      foreach ( $this->_attributes as $attribute )
      {
         if ( Type::USERNAME_PARAM === $attribute->getType() )
         {
            return $attribute->getName();
         }
      }

      return null;

   }
30749
protected function getAuthHeader()
    {
        if ($this->apiClient->accessToken && $this->apiClient->accessToken->isValid) {
            return 'Authorization: OAuth ' . $this->apiClient->accessToken->token;
        }
        throw new InvalidParamException('NOT VALID ACCESS TOKEN', self::CODE_UNAUTHORIZED);
    }
109899
protected function getTokenData() {
    $result = null;

    $request = ObjectFactory::getInstance('request');
    $token = $request->hasHeader(self::TOKEN_HEADER) ?
        trim(str_replace(self::AUTH_TYPE, '', $request->getHeader(self::TOKEN_HEADER))) : $this->token;
    if ($token !== null) {
      $jwt = (new Parser())->parse((string)$token);

      // validate
      $data = new ValidationData();
      $data->setIssuer($this->getTokenIssuer());
      if ($jwt->validate($data) && $jwt->verify($this->getTokenSigner(), $this->key)) {
        $result = $jwt->getClaims();
      }
    }
    return $result;
  }
1254875
private function getProvidedCsrfToken(): ?string
    {
        $token = $this->request->getParameter(self::REQUEST_TOKEN_VALUE);
        if (is_null($token)) {
            $token = isset($_SERVER[self::HEADER_TOKEN]) ? $_SERVER[self::HEADER_TOKEN] : null;
        }
        return $token;
    }
1244078
protected function requestAuthorizationToken(): string
    {
        $result = $this->options->getAuthorizationToken();
        if ($result === '') {
            $authRequest = new AuthRequest();
            $authRequest->setAgent($this->options->getAgent())
                        ->setAccessKey($this->options->getAccessKey())
                        ->setEnabledModNames($this->options->getEnabledModNames());

            $authResponse = $this->fetchResponse($authRequest);
            if ($authResponse instanceof AuthResponse) {
                $result = $authResponse->getAuthorizationToken();
                $this->options->setAuthorizationToken($result);
            }
        }
        return $result;
    }
621518
protected function get_stored_token() {
        global $SESSION;

        $name = $this->get_tokenname();

        if (isset($SESSION->{$name})) {
            return $SESSION->{$name};
        }

        return null;
    }