Authenticate the incoming request for a given channel.

@param  \Nova\Http\Request  $request
@return mixed
483682
public function authenticate(Request $request)
    {
        $channelName = $request->input('channel_name');

        $channel = preg_replace('/^(private|presence)\-/', '', $channelName, 1, $count);

        if (($count == 1) && is_null($user = $request->user())) {
            // For the private and presence channels, the Broadcasting needs a valid User instance,
            // but it is not available for the non authenticated users (guests) within Auth System.
            // For the guests, we will use a cached GuestUser instance, with a random string as ID.

            $request->setUserResolver(function ()
            {
                if (! isset($this->authGuest)) {
                    $session = $this->container['session'];

                    if (empty($id = $session->get('broadcasting.guest'))) {
                        $session->set('broadcasting.guest', $id = dechex(time()) . Str::random(16));
                    }

                    return $this->authGuest = new GuestUser($id);
                }

                return $this->authGuest;
            });
        }

        return $this->verifyUserCanAccessChannel($request, $channel);
    }
1246997
public function verifyRequest(Request $request = null)
    {
        $request = $request ?: $this->request;
        $response = $request->request->get('g-recaptcha-response');
        $remoteip = $request->getClientIp();

        return $this->verify($response, $remoteip);
    }
442974
public function login(Request $request)
    {
        $this->validate($request, [
            'email'    => 'required|max:255',
            'password' => 'required|max:255',
        ]);

        if (Auth::attempt(['email' => $request->email, 'password' => $request->password], $request->remember ? true : false)) {
            return redirect()->intended(route('laralum::index'));
        }

        return redirect()->route('laralum::login')->with('error', trans('auth.failed'))->withInput();
    }
919210
protected function user($request)
    {
        if (!$token = $this->auth->setRequest($request)->getToken()) {
            return 401;
        }

        try {
            $user = $this->auth->authenticate($token);
        } catch (JWTException $e) {
            return 401;
        }

        if (!$user) {
            return 401;
        }

        return $user;
    }
40191
public function authenticate(HTTPRequest $request): HTTPRequest
    {
        $requestAdapter = new HttpRequestAdapter();
        $responseAdapter = new HttpResponseAdapter();

        // missing vars (cli)
        $this->addMissingServerVariables($requestAdapter);

        $server = $this->getServer();
        $psrRequest = $requestAdapter->toPsr7($request);
        $psrResponse = new Response();

        try {
            $psrRequest = $server->validateAuthenticatedRequest($psrRequest);
        } catch (OAuthServerException $exception) {
            // convert to authentication exception
            throw new AuthenticationException(
                $exception->getMessage(),
                $exception->getCode(),
                $responseAdapter->fromPsr7($exception->generateHttpResponse($psrResponse))
            );
        } catch (\Exception $exception) {
            // convert to authentication exception
            throw new AuthenticationException(
                $exception->getMessage(),
                $exception->getCode(),
                $responseAdapter->fromPsr7(
                    (new OAuthServerException($exception->getMessage(), 0, 'unknown_error', 500))
                        ->generateHttpResponse($psrResponse)
                )
            );
        }
        // add the request attributes as custom auth headers
        foreach ($psrRequest->getAttributes() as $attribute => $value) {
            $request->addHeader($attribute, $value);
        }

        return $request;
    }
1074079
public function authenticate(Request $request)
    {
        $email    = $request->input(self::AUTH_PARAM_EMAIL, null);
        $password = $request->input(self::AUTH_PARAM_PASSWORD, null);

        if ($email !== null &&
            $password !== null &&
            ($user = User::query()->where(User::FIELD_EMAIL, '=', strtolower($email))->first()) !== null
        ) {
            /** @var HasherInterface $hasher */
            $hasher = app(HasherInterface::class);
            if ($hasher->check($password, $user->{User::FIELD_PASSWORD_HASH}) === true) {
                /** @var TokenCodecInterface $codec */
                $codec = app(TokenCodecInterface::class);
                $token = $codec->encode($user);

                $this->getLogger()->debug(
                    'Account login success.',
                    [User::FIELD_EMAIL => $email, User::FIELD_ID => $user->getKey()]
                );

                return response($token);
            }
        }

        $this->getLogger()->debug('Account login failed.', [User::FIELD_EMAIL => $email]);

        return response(null, Response::HTTP_UNAUTHORIZED);
    }
219089
private function authBasic(Request $request) {
		$user = $this->findUser($request->getUser());
		if ($user !== null && $this->verifyUser($user, $request->getPassword())) {
			$session = $this->findSession($user);
			if ($session === null) {
				$session = $this->createSession($user);
			}
			$this->authenticated = true;

			return $session;
		}
		return null;
	}
310796
public function verify(Request $request)
    {
        if ($request->route('id') != $request->user()->getKey()) {
            throw new AuthorizationException();
        }

        if ($request->user()->hasVerifiedEmail()) {
            return redirect($this->redirectPath());
        }

        if ($request->user()->markEmailAsVerified()) {
            event(new Verified($request->user()));
        }

        return redirect($this->redirectPath())->with('verified', true);
    }
179190
protected function authentication(RequestInterface $request)
	{
		$uri = $request->getUri();
		$key = http_build_query(['key' => $this->getAccessKey()], null, '&');

		if (strlen($uri->getQuery()) > 0)
		{
			$key = '&'.$key;
		}

		return $request->withUri($uri->withQuery($uri->getQuery().$key));
	}
1148175
public function authenticate(Request $request)
    {
        return $request->get('username') === $this->username
            && password_verify($request->get('password'), $this->password);
    }
713554
public function authorize(Request $request): Response
    {
        return $this->auth->authorize($request)
            ? $this->broadcastManager->authorized($request)
            : $this->broadcastManager->unauthorized($request);
    }
1132904
public function authenticateAction(Request $request) {
        $data = $request->request->all();
        try {
            $data = $this->getAuthCredentials($request);
            $this->info('> Authenticate request', ['method' => $request->getMethod(), 'query' => $data]);
            // exports $client_id, $redirect_uri, $username and $password
            extract($data);

            $accessCredentials = $this->accessProvider->generate($request, $client_id, $redirect_uri, $username, $password);
            $response = new RedirectResponse($redirect_uri . '?code=' . $accessCredentials->getAuthCode());
        }catch (BadDataException $e) {
            $data['errors'] = $e->getErrors();
            $this->error('Bad Data Exception: ' . $e->getMessage(), ['errors' => $data['errors'], 'exception' => $e]);
            $response = $this->getBadFormRequestResponse($data);
        } catch (SoauthException $e) {
            $this->error('Soauth Exception: ' . $e->getMessage(), ['exception' => $e]);
            $response = $this->getBadFormRequestResponse($data);
        }

        $this->info('< Response', ['status_code' => $response->getStatusCode(), 'target' => $response instanceOf RedirectResponse ? $response->getTargetUrl() : null]);
        return $response;
    }
1134705
public function handle(Request $request)
	{
		$response = $this->next($request);

		// If CLI then we have to gather all query, post and header values
		// into params for Oauth_Provider's constructor.
		$params = array();

		if ($this->app->runningInConsole())
		{
			$queryvars = $this->app['request']->get('queryvars');
			$postvars  = $this->app['request']->get('postdata');

			if (!empty($queryvars))
			{
				foreach ($queryvars as $key => $value)
				{
					if (isset($queryvars[$key]))
					{
						$params[$key] = $queryvars[$key];
					}
					else if (isset($postvars[$key]))
					{
						$params[$key] = $postvars[$key];
					}
				}
			}

			if (!empty($postvars))
			{
				foreach ($postvars as $key => $value)
				{
					if (isset($queryvars[$key]))
					{
						$params[$key] = $queryvars[$key];
					}
					else if (isset($postvars[$key]))
					{
						$params[$key] = $postvars[$key];
					}
				}
			}

			if (empty($params))
			{
				return false;
			}
		}

		$this->app['authn'] = $this->app['auth']->authenticate($params);

		$this->app['request']->setVar('validApiKey', !empty($this->app['authn']['consumer_key']));

		return $response;
	}
243216
protected function attemptAuthentication(Request $request)
    {
        $samlResponse = $this->receiveSamlResponse();

        $token = new SamlSpResponseToken($samlResponse, $this->providerKey);

        $token = $this->authenticationManager->authenticate($token);

        return $token;
    }
353160
public function fetchAccessToken(&$request)
    {
        $this->getVersion($request);

        $consumer = $this->getConsumer($request);

        // requires authorized request token
        $token = $this->getToken($request, $consumer, "request");

        $this->checkSignature($request, $consumer, $token);

        // Rev A change
        $verifier = $request->get_parameter('oauth_verifier');
        $new_token = $this->data_store->new_access_token($token, $consumer, $verifier);

        return $new_token;
    }
588518
public function getRequest( Request $request ) {
		$response = $this->getClient()->request(
			'GET',
			$this->apiUrl,
			$this->getClientRequestOptions( $request, 'query' )
		);

		return $this->decodeResponse( $response );
	}
1123921
private function authenticate($request)
    {
        switch (strtolower($this->authN_type)) {

            case 'cas':
                // Use CAS authentication.
                $casAuth = new UsfAuthCAS($this->config['cas']);
                $casAuth->auth();

                //Authorization check
                $this->isAuthorized = $casAuth->isAuthorized($this->authZ_roles);

                //Add the username and entitlements to the request
                $request = $request->withHeader('AUTH_PRINCIPAL', $casAuth->getPrincipal());
                $request = $request->withHeader('AUTH_ENTITLEMENTS', $casAuth->getEntitlements());

                //Add all Attributes
                foreach ($casAuth->getAttributes() as $key => $value) {
                    $request = $request->withHeader('AUTH_ATTR_'.strtoupper($key), $value);
                }
                break;

            case 'token':
                // Use the USF Token Auth library.
                $tokenAuth = new UsfAuthToken(
                    $this->config['token']['app_id'],
                    $this->config['token']['token_url']
                );

                $tokenAuth->setRequestMethod($request->getMethod());
                $tokenAuth->setReferrer($request->getHeader('HTTP_REFERER'));

                //Validate request token
                $tokenAuth->validateRequest($request->getHeader('HTTP_X_AUTH_TOKEN'));

                //Authorization check
                $this->isAuthorized = $tokenAuth->isAuthorized($this->authZ_roles);

                //Add the username and entitlements to the request
                $request = $request->withHeader('AUTH_PRINCIPAL', $tokenAuth->getPrincipal());
                $request = $request->withHeader('AUTH_ENTITLEMENTS', $tokenAuth->getEntitlements());

                //Add all Attributes
                foreach ($tokenAuth->getAttributes() as $key => $value) {
                    $request = $request->withHeader('AUTH_ATTR_'.strtoupper($key), $value);
                }
                break;

            case 'hmac':
                // HMAC authentication: https://github.com/acquia/http-hmac-spec
                $hmacAuth = new UsfAuthHmac($this->config['hmac']['keyRegistry']);
                if (!empty($this->config['hmac']['timeout'])) {
                    $hmacAuth->setTimeout($this->config['hmac']['timeout']);
                }

                $hmacAuth->setRequestWrapper(new Psr7Request($request));

                try {
                    $hmacAuth->authenticate();
                    $this->isAuthorized = true;
                } catch (\Exception $exception) {
                    $this->isAuthorized = false;
                }

                //Add the username to the request
                $request = $request->withHeader('AUTH_PRINCIPAL', $hmacAuth->getPrincipal());
                break;

            case 'permitall':
                // No authentication - let everyone in.
                $this->isAuthorized = true;
                break;

            case 'denyall':
                // No authentication - keep everyone out.
                $this->isAuthorized = false;
                break;

            default:
                throw new \Exception("Unknown Authentication type: " . $this->authN_type, 500);
                break;
        }

        return $request;
    }