Get an API Auth object

@param array  $parameters
@param string $authMethod

@return AuthInterface
550342
public function newAuth($parameters = array(), $authMethod = 'OAuth')
    {
        $class      = 'Mautic\\Auth\\'.$authMethod;
        $authObject = new $class();

        $reflection = new \ReflectionMethod($class, 'setup');
        $pass       = array();

        foreach ($reflection->getParameters() as $param) {
            if (isset($parameters[$param->getName()])) {
                $pass[] = $parameters[$param->getName()];
            } else {
                $pass[] = null;
            }
        }

        $reflection->invokeArgs($authObject, $pass);

        return $authObject;
    }
563926
private function onAuthenticateHandler($authMethod, $authMethodInfo, Realm $realm, Session $session, AuthenticateMessage $msg)
    {

        $onAuthenticateSuccess = function ($res) use ($realm, $session) {

            if (count($res) < 1) {
                $session->abort(new \stdClass(), 'thruway.error.authentication_failure');

                return;
            }

            // we should figure out a way to have the router send the welcome
            // message so that the roles and extras that go along with it can be
            // filled in
            if ($res[0] === 'SUCCESS') {
                $this->sendWelcomeMessage($session, $res[1]);
            } elseif (isset($res[0]) && $res[0] === 'FAILURE') {
                $this->abortSessionUsingResponse($session, $res);
            } else {
                $session->abort(new \stdClass(), 'thruway.error.authentication_failure');
            }
        };

        $onAuthenticateError = function () use ($session) {
            Logger::error($this, 'onauthenticate rejected the promise');
            $session->abort(new \stdClass(), 'thruway.error.unknown');
        };

        $extra                    = new \stdClass();
        $extra->challenge_details = $session->getAuthenticationDetails()->getChallengeDetails();

        $arguments                = new \stdClass();
        $arguments->extra         = $extra;
        $arguments->authid        = $session->getAuthenticationDetails()->getAuthId();
        $arguments->challenge     = $session->getAuthenticationDetails()->getChallenge();
        $arguments->signature     = $msg->getSignature();
        $arguments->authmethod    = $authMethod;
        $arguments->hello_message = $session->getHelloMessage();

        // now we send our authenticate information to the RPC
        $onAuthenticateHandler = $authMethodInfo['handlers']->onauthenticate;

        $this->session->call($onAuthenticateHandler, [$arguments])
            ->then($onAuthenticateSuccess, $onAuthenticateError);

    }
658094
protected function getBestAuthMethod()
    {
        $available_methods = explode(' ', $this->esmtp['AUTH']);

        foreach ($this->auth_methods as $method => $callback) {
            if (in_array($method, $available_methods)) {
                return $method;
            }
        }

        return PEAR::raiseError('No supported authentication methods');
    }
591412
public function get($methodName, array $params = array())
    {
        $options = array_merge($this->defaultApiOptions, $this->createConfigByMethodName($methodName));
        $options['http'] = 'get';
        return $this->internalCall($methodName, $options, $params);
    }
1261653
public function getHeaders(CredentialsInterface $credentials, $method, $url, array $bodyParameters = array())
    {
        $header = $this->protocolHeader(strtoupper($method), $url, $credentials, $bodyParameters);
        $authorizationHeader = array('Authorization' => $header);
        $headers = $this->buildHttpClientHeaders($authorizationHeader);

        return $headers;
    }
940336
private function createHeader($parameters)
	{
		$header = 'OAuth ';

		foreach ($parameters as $key => $value)
		{
			if (!strcmp($header, 'OAuth '))
			{
				$header .= $key . '="' . $this->safeEncode($value) . '"';
			}
			else
			{
				$header .= ', ' . $key . '="' . $value . '"';
			}
		}

		return $header;
	}
703635
public function getAuthenticatedRequest($method, $url, $token, array $options = [])
    {
        $baseUri = new Psr7\Uri($this->urlApiDomain);
        $relativeUri = new Psr7\Uri($url);
        $newUri = Psr7\Uri::resolve($baseUri, $relativeUri);

        return parent::getAuthenticatedRequest($method, $newUri, $token, $options);
    }
812443
protected function getAuthClass(array $authConfig = []): Auth
    {
        $type = $authConfig['type'] ?? '';

        switch ($type) {
            case ClientCredentials::TYPE:
                return new ClientCredentials(
                    $authConfig['appId'],
                    $authConfig['appSecret']
                );
            case LegacyCredentials::TYPE:
                return new LegacyCredentials(
                    $authConfig['clientId'],
                    $authConfig['apiKey']
                );
            case RefreshCredentials::TYPE:
                return new RefreshCredentials(
                    $authConfig['appId'],
                    $authConfig['appSecret'],
                    $authConfig['refreshToken']
                );
            default:
                return new NullCredentials();
        }
    }
1229907
public function getSignature($params = [], $method = Alidayu::SIGN_METHOD_HMAC)
    {
        $rawQuery = [];
        ksort($params);
        foreach ($params as $k => $v) {
            $rawQuery[] = sprintf('%s%s', $k, $v);
        }
        $rawText = implode('', $rawQuery);
        $signature = '';
        if ($method === Alidayu::SIGN_METHOD_MD5) {
            $signature = md5($this->appSecret . $rawText . $this->appSecret);
        } elseif ($method === Alidayu::SIGN_METHOD_HMAC) {
            $signature = hash_hmac('md5', $rawText, $this->appSecret);
        }
        return strtoupper($signature);
    }
33992
public function getAuthenticatedRequest($method, $url, $token, array $options = [])
    {
        $parsedUrl = parse_url($url);
        $queryString = array();

        if (isset($parsedUrl['query'])) {
            parse_str($parsedUrl['query'], $queryString);
        }

        if (!isset($queryString['access_token'])) {
            $queryString['access_token'] = (string) $token;
        }

        $url = http_build_url($url, [
            'query' => http_build_query($queryString),
        ]);

        return $this->createRequest($method, $url, null, $options);
    }
183982
protected function getOpauthResponse() {
		$config = OpauthAuthenticator::get_opauth_config();
		$transportMethod = $config['callback_transport'];
		switch($transportMethod) {
			case 'session':
				return $this->getResponseFromSession();
			case 'get':
			case 'post':
				return $this->getResponseFromRequest($transportMethod);
			default:
				throw new InvalidArgumentException('Invalid transport method: ' . $transportMethod);
		}
	}
454364
protected function resolveHTTPAuth(array &$parameters, array &$headers)
    {
        $authorizationHeader = null;
        if (isset($parameters['HTTP_AUTHORIZATION'])) {
            $authorizationHeader = $parameters['HTTP_AUTHORIZATION'];
        } elseif (isset($parameters['REDIRECT_HTTP_AUTHORIZATION'])) {
            $authorizationHeader = $parameters['REDIRECT_HTTP_AUTHORIZATION'];
        }

        if ($authorizationHeader !== null && stripos($authorizationHeader, 'basic') === 0) {
            $exploded = explode(':', base64_decode(substr($authorizationHeader, 6)));
            if (count($exploded) == 2) {
                list($headers['PHP_AUTH_USER'], $headers['PHP_AUTH_PW']) = $exploded;
            }
        }
    }
1007813
public function authenticate($auth = null)
    {
        if ($auth !== null) {
            $this->auth = $auth;
        }

        return $this->auth;
    }
820506
public function api($method, $path, array $parameters = array(), $multipart = false, $appOnlyAuth = false, $internal = false)
    {
        $result = $this->twitter->api($method, $path, $parameters, $multipart, $appOnlyAuth, $internal);
        
        return $this->reformatResult($result);
    }
881143
public function authenticate($credentials, $authMethod = self::AUTH_HTTP_PASSWORD)
    {
        if ($authMethod === self::AUTH_HTTP_PASSWORD) {
            $listener = new BasicAuthListener(
                $credentials['username'],
                $credentials['password']
            );
        } else {
            $listener = new OAuthListener(
                [
                    'oauth_consumer_key' => $credentials['key'],
                    'oauth_consumer_secret' => $credentials['secret'],
                ]
            );
        }

        $this->httpClient->addListener($listener);
    }
743832
protected function createAuthorization(array $parameters): ResponseInterface
    {
        try {
            list($client, $redirectUri) = $this->getValidClientAndRedirectUri(
                $this->codeGetClientId($parameters),
                $this->codeGetRedirectUri($parameters)
            );
            if ($client === null || $redirectUri === null) {
                return $this->getIntegration()->createInvalidClientAndRedirectUriErrorResponse();
            }

            $maxStateLength = $this->getMaxStateLength();
            switch ($responseType = $this->getResponseType($parameters)) {
                case ResponseTypes::AUTHORIZATION_CODE:
                    $this->logDebug('Handling code authorization.');
                    $response = $this
                        ->codeAskResourceOwnerForApproval($parameters, $client, $redirectUri, $maxStateLength);
                    break;
                case ResponseTypes::IMPLICIT:
                    $this->logDebug('Handling implicit authorization.');
                    $response = $this
                        ->implicitAskResourceOwnerForApproval($parameters, $client, $redirectUri, $maxStateLength);
                    break;
                default:
                    // @link https://tools.ietf.org/html/rfc6749#section-3.1.1 ->
                    // @link https://tools.ietf.org/html/rfc6749#section-4.1.2.1
                    $this->logInfo('Unsupported response type in request.', ['response_type' => $responseType]);
                    $errorCode = OAuthCodeRedirectException::ERROR_UNSUPPORTED_RESPONSE_TYPE;
                    throw new OAuthCodeRedirectException($errorCode, $redirectUri);
            }
        } catch (OAuthRedirectException $exception) {
            $response = $this->createRedirectErrorResponse($exception);
        }

        return $response;
    }
762115
public function api($path, array $parameters = array(), $method = 'GET')
    {
        return $this->getRequest()->api($path, $method, $parameters);
    }