Creates a matching authentication for an URL.

@param Authentication $authentication
@param string         $url

@return self
17263
public static function createUrlMatcher(Authentication $authentication, $url)
    {
        $matcher = function (RequestInterface $request) use ($url) {
            return preg_match($url, $request->getRequestTarget());
        };

        return new static($authentication, $matcher);
    }
411521
@Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        if (authentication == null) {
            return authentication;
        }
        UsernamePasswordAuthenticationToken output = null;
        if (authentication instanceof UsernamePasswordAuthenticationToken) {
            output = (UsernamePasswordAuthenticationToken) authentication;
        } else {
            output = new UsernamePasswordAuthenticationToken(authentication, authentication.getCredentials(),
                            authentication.getAuthorities());
            output.setAuthenticated(authentication.isAuthenticated());
            output.setDetails(authentication.getDetails());
        }
        return delegate.authenticate(output);
    }
1284477
public function authenticate() {
    $this->getClient()->authenticate($this->getApiToken(), \Github\Client::AUTH_HTTP_TOKEN);
    return $this;
  }
646736
private function createAuth(array $api, array $configAttributes, array $authorization) : AuthInterface
    {
        if (empty($api['authentication']['type'])) {
            $this->logger->debug("Using no authentication.");
            return new Authentication\NoAuth();
        }
        $this->logger->debug("Using '{$api['authentication']['type']}' authentication.");
        switch ($api['authentication']['type']) {
            case 'basic':
                if (!empty($config['password']) && empty($config['#password'])) {
                    $this->logger->warning("Using deprecated 'password', use '#password' instead.");
                }
                return new Authentication\Basic($configAttributes);
                break;
            /** @noinspection PhpMissingBreakStatementInspection */
            case 'url.query':
                $this->logger->warning("Method 'url.query' auth is deprecated, use 'query'.");
                // intentional, no break
            case 'query':
                if (empty($api['authentication']['query']) && !empty($api['query'])) {
                    $this->logger->warning("Using 'api.query' is deprecated, use 'api.authentication.query");
                    $api['authentication']['query'] = $api['query'];
                }
                return new Authentication\Query($configAttributes, $api['authentication']);
                break;
            case 'login':
                return new Authentication\Login($configAttributes, $api['authentication']);
                break;
            case 'oauth10':
                return new Authentication\OAuth10($authorization);
            case 'oauth20':
                return new Authentication\OAuth20($configAttributes, $authorization, $api['authentication']);
            case 'oauth20.login':
                return new Authentication\OAuth20Login($configAttributes, $authorization, $api['authentication']);
            default:
                throw new UserException("Unknown authorization type '{$api['authentication']['type']}'.");
                break;
        }
    }
1363854
public function start(Request $request, AuthenticationException $authException = null)
    {
        //The URL have to be completed by the current request uri,
        // because Cas Server need to know where redirect user after authentication.
        return new RedirectResponse($this->cas->getUri().$request->getUri());
    }
1017653
public function start(Request $request, AuthenticationException $authException = null)
    {
        return new RedirectResponse($this->createLoginPath($request));
    }
1094578
@Override
    public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
        try {
            return authenticate(credentials, URI.create(method.getURI().getURI()));
        } catch (URIException e) {
            throw new AuthenticationException("Could not determine request URI", e);
        }
    }
753028
protected function setAuthenticationHandler(array $config, Authentication $authentication = null)
    {
        $this->setAuthentication($config, $authentication);

        $authenticationHandler = new AuthenticationHandler();
        $authenticationHandler->setSigner($this->authentication);
        if (!isset($config['handler'])) {
            $config['handler'] = \GuzzleHttp\HandlerStack::create();
        }
        try {
            if (!($config['handler'] instanceof \GuzzleHttp\HandlerStack)) {
                $config['handler'] = \GuzzleHttp\HandlerStack::create($config['handler']);
            }
            $config['handler']->before('history', $authenticationHandler, 'authentication');
        } catch (\InvalidArgumentException $e) {
            // history middleware not added yet
            $config['handler']->push($authenticationHandler, 'authentication');
        }
        return $config;
    }
374631
public void setAuthenticationToken(Authentication authentication) {
        if( logger.isDebugEnabled() ) {
            logger.debug( "New authentication token: " + authentication );
        }

        final HttpInvokerRequestExecutor hire = getHttpInvokerRequestExecutor();
        if( hire instanceof BasicAuthHttpInvokerRequestExecutor ) {
            if( logger.isDebugEnabled() ) {
                logger.debug( "Pass it along to executor" );
            }
            ((BasicAuthHttpInvokerRequestExecutor) hire).setAuthenticationToken( authentication );
        }
    }
1032027
public function httpAuth($user, $password)
    {
        curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($this->ch, CURLOPT_USERPWD, "$user:$password");

        return $this;
    }
37200
protected function authenticate()
    {
        if (!$this->isAuthenticated) {
            list($url, $this->cdnUrl, $this->authToken) = $this->auth->authenticate();
            if ($this->useServicenet) {
                $url = str_replace('https://', 'https://snet-%s', $url);
            }

            $this->connectionUrlInfo = Utils::parseUrl($url);
            $this->httpConnect();

            if ($this->cdnUrl) {
                $this->cdnConnect();
            }

            $this->isAuthenticated = true;
        }
    }
1284262
public function authenticateUser($username, $password)
    {
        try
        {
            return $this->httpHelper->post("customer_portal/auth", ['username' => $username, 'password' => $password]);
        }
        catch (ApiException $e)
        {
            throw new AuthenticationException($e->getMessage());
        }
    }
224149
public function start(Request $request, AuthenticationException $authException = null)
    {
        $url = $this->getLoginUrl();

        return new RedirectResponse($url);
    }
835037
public function setSecureUrl($url)
    {
        if (strpos($url, 'https://') !== false) {
            if (filter_var($url, FILTER_VALIDATE_URL)) {
                $this->setObject('secure_url', $url);
            }
        }

        return $this;
    }
934287
public static function create(
        AuthInterface $authentication,
        bool $throwsExceptions = false,
        string $baseUrl = 'https://api.idos.io/1.0/'
    ) : self {
        return new static(
            $authentication,
            new Client(),
            $throwsExceptions,
            $baseUrl
        );
    }
501381
protected function authenticate(Url $url)
    {
        if (
            !$url->getOption('role') ||
            !$url->getOption('firewall')
        ) {
            return $this;
        }

        $session = $this->session;
        $firewall = $url->getOption('firewall');
        $role = $url->getOption('role');
        $user = $this
            ->environmentBuilder
            ->getAuthenticationUser($url->getOption('role'));

        $token = new UsernamePasswordToken($user, null, $firewall, [$role]);
        $session->set('_security_' . $firewall, serialize($token));
        $session->save();

        $cookie = new Cookie(
            $session->getName(),
            $session->getId()
        );
        $this
            ->client
            ->getCookieJar()
            ->set($cookie);

        return $this;
    }
885627
def prepare_auth(self, auth, url=''):
        """"""

        # If no Auth is explicitly provided, extract it from the URL first.
        if auth is None:
            url_auth = get_auth_from_url(self.url)
            auth = url_auth if any(url_auth) else None

        if auth:
            if isinstance(auth, tuple) and len(auth) == 2:
                # special-case basic HTTP auth
                auth = HTTPBasicAuth(*auth)

            # Allow auth to make its changes.
            r = auth(self)

            # Update self to reflect the auth changes.
            self.__dict__.update(r.__dict__)

            # Recompute Content-Length
            self.prepare_content_length(self.body)