Creates an api key by the http request.

@param Request $request
@param string  $providerKey

@throws BadCredentialsException If the request token cannot be found

@return PreAuthenticatedToken
197819
public function createToken(Request $request, $providerKey)
    {
        $apiKey = $request->headers->get($this->header);

        if (!$apiKey) {
            throw new BadCredentialsException('No ApiKey found in request!');
        }

        return new PreAuthenticatedToken(
            'unauthorized',
            $apiKey,
            $providerKey
        );
    }
734958
public function authentication(Request $request, array $credentials)
    {
        if (isset($credentials['username'], $credentials['password'])) {
            $value = $this->_generateHeader($credentials['username'], $credentials['password']);
            $request = $request->withHeader('Authorization', $value);
        }

        return $request;
    }
1020295
public function signInWithProvider($provider_name, Request $request)
    {
        $provider = $this->getProvider($provider_name, $request);

        if (!$provider) {
            return $this->response(['errors' => [
                'code'    => 'PROVIDER_NOT_FOUND',
                'message' => 'No provider found',
            ]], Response::HTTP_BAD_REQUEST);
        }

        $provider->stateless();

        if ($request->input('code') !== null) {
            try {
                return $this->authenticateByCode($provider, $request->input('code'));
            } catch (\Exception $e) {
                return $this->response([
                    'code'    => 'CODE_NOT_VALID',
                    'message' => 'Code invalid or expired'.$e->getMessage(),
                ], Response::HTTP_BAD_REQUEST);
            }
        }
    }
534531
public function authenticateToken(TokenInterface $token,
                                      UserProviderInterface $userProvider,
                                      $providerKey)
    {
        if (($user = $userProvider->loadUserByUsername($token->getUsername()))) {
            $userPassword     = $user->getPassword();
            $tokenCredentials = $token->getCredentials();
            if ($userPassword == $this->initPassword && $user instanceof MutableUserInterface
                && $userProvider instanceof MutableUserProviderInterface) {
                $this->encodePassword($user, $tokenCredentials);
                $userProvider->saveUser($user);
                // return it
                return new UsernamePasswordToken(
                    $user, $user->getPassword(), $providerKey, $user->getRoles()
                );
            } else if ($this->passwordEncoder->isPasswordValid($userPassword, $tokenCredentials, $user->getSalt())) {
                return new UsernamePasswordToken(
                    $user, $userPassword, $providerKey, $user->getRoles()
                );
            }
        }
        throw new BadCredentialsException('The presented password is invalid.');
    }
486284
public function provider(ProviderRequest $providerRequest)
    {
      // Extract SimplePay user from request
      $user = $providerRequest->getUser();

      // Create request
      $request = new StdClass();
      $request->User = new StdClass();
      $request->User->Uuid = $user->getUuid()->getValue();
      $request->User->Hash = $user->getHash();

      /*$request = new StdClass();
       $request->Auth = new StdClass();
       $request->Auth->Uuid
       $request->Auth->Method
       $request->Auth->Signature
       $request->Auth->Token
       $request->Auth->Timestamp
       $request->Auth->Nonce
       $request->Auth->Version*/

      // Check type
      if($providerRequest->hasType())
        $request->Type = $providerRequest->getType();

      // Send request
      $response = $this->getSoapClient()->provider($request);

      // Create a new ProviderResponse
      $providerResponse = new ProviderResponse();

      if(!is_array($response->Provider))
        $response->Provider = array($response->Provider);

      foreach($response->Provider as $provider)
      {
        // Extract values from reponse
        $uuid = $provider->Uuid;
        $name = $provider->Name;
        $type = $provider->Type;

        $uuid = new Uuid($uuid);

        // Create a new Provider
        $provider = new Provider($uuid, $name, $type);

        // Add bank to response
        $providerResponse->addProvider($provider);
      }

      return $providerResponse;
    }
1097732
public function authenticate(Request $request)
    {
        $this->checkForToken($request);

        try {
            if (! $this->auth->parseToken()->authenticate()) {
                throw new UnauthorizedHttpException('jwTauth', 'User not found');
            }
        } catch (JwTException $e) {
            throw new UnauthorizedHttpException('jwTauth', $e->getMessage(), $e, $e->getCode());
        }
    }
995889
public function validateAuthorizationHeader(Request $request)
    {
        if (Str::startsWith(\strtolower($request->headers->get('authorization')), $this->getAuthorizationMethod())) {
            return true;
        }

        throw new BadRequestHttpException();
    }
1213157
public function createToken($redirectUri, $owner, $client, array $scopes = []): AuthorizationCode
    {
        if (empty($scopes)) {
            $scopes = $this->scopeService->getDefaultScopes();
        } else {
            $this->validateTokenScopes($scopes);
        }

        do {
            $token = AuthorizationCode::createNewAuthorizationCode(
                $this->serverOptions->getAuthorizationCodeTtl(),
                $redirectUri,
                $owner,
                $client,
                $scopes
            );
        } while ($this->tokenRepository->tokenExists($token->getToken()));

        return $this->tokenRepository->save($token);
    }
26347
public function authenticateUserAndHandleSuccess(UserInterface $user, Request $request, AuthenticatorInterface $authenticator, string $providerKey): ?Response
    {
        // create an authenticated token for the User
        $token = $authenticator->createAuthenticatedToken($user, $providerKey);
        // authenticate this in the system
        $this->authenticateWithToken($token, $request, $providerKey);

        // return the success metric
        return $this->handleAuthenticationSuccess($token, $request, $authenticator, $providerKey);
    }
614961
public function refresh(Request $request)
    {
        try {
            $preAuthenticatedToken = $this->authenticator->authenticateToken(
                $this->authenticator->createToken($request, $this->providerKey),
                $this->provider,
                $this->providerKey
            );
        } catch (AuthenticationException $e) {
            return $this->failureHandler->onAuthenticationFailure($request, $e);
        }

        $refreshToken = $this->refreshTokenManager->get($preAuthenticatedToken->getCredentials());

        if (null === $refreshToken || !$refreshToken->isValid()) {
            return $this->failureHandler->onAuthenticationFailure($request, new AuthenticationException(
                    sprintf('Refresh token "%s" is invalid.', $refreshToken)
                )
            );
        }

        if ($this->ttlUpdate) {
            $expirationDate = new \DateTime();
            $expirationDate->modify(sprintf('+%d seconds', $this->ttl));
            $refreshToken->setValid($expirationDate);

            $this->refreshTokenManager->save($refreshToken);
        }

        $this->eventDispatcher->dispatch('gesdinet.refresh_token', new RefreshEvent($refreshToken, $preAuthenticatedToken));

        return $this->successHandler->onAuthenticationSuccess($request, $preAuthenticatedToken);
    }
1285873
private function parseToken(Request $request) : ?Token
    {
        $cookies    = $request->getCookieParams();
        $cookieName = $this->defaultCookie->getName();

        if (! isset($cookies[$cookieName])) {
            return null;
        }

        try {
            $token = $this->tokenParser->parse($cookies[$cookieName]);
        } catch (\InvalidArgumentException $invalidToken) {
            return null;
        }

        if (! $token->validate(new ValidationData())) {
            return null;
        }

        return $token;
    }
38595
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
    {
        $user = $token->getUser();

        $this->dispatcher->dispatch(self::OAUTH_LOGIN_SUCCESS, new UserEvent($user));

        return $this->authResponseService->authenticateResponse($user,
            new Response($this->twig->render('@StarterKitStart/oauth-success.html.twig')));
    }
157402
public function createAccountAction(Request $request)
    {
        $selfRegistration = $this->platformConfigHandler->getParameter('allow_self_registration');
        $casLogin = $request->getSession()->get('CAS_AUTHENTICATION_USER_ID');
        if (empty($casLogin) || !$selfRegistration) {
            return $this->redirectToRoute('claro_index');
        }

        return $this->casManager->createNewAccount($request, $casLogin);
    }
1335098
public function getCredentials(Request $request)
    {
        // Get token and key
        $headerToken  = $request->headers->get('X-APP-TOKEN');

        if (!$headerToken) {
            // no token, nonce or app? Return null and no other methods will be called
            return;
        }

        // What you return here will be passed to getUser() as $credentials
        $token = new Token;
        $token->fromHeader($headerToken);

        return array(
            'token'     => $token,
            'header'    => $headerToken,
        );
    }
54520
public function authenticate(Request $request)
    {
        if (Auth::user()) {
            return false;
        }

        $this->checkForToken($request);

        try {
            if (!JWTAuth::parseToken()->authenticate()) {
                throw new UnauthorizedHttpException('jwt-auth', 'User not found');
            }
        } catch (TokenExpiredException $e) {
            // If the token is expired, then it will be refreshed and added to the headers
            try {
                return Auth::refresh();
            } catch (TokenExpiredException $e) {
                throw new UnauthorizedHttpException('jwt-auth', 'Refresh token has expired.');
            }
        } catch (TokenBlacklistedException $e) {
            throw new TokenBlacklistedException($e->getMessage(), 401);
        } catch (JWTException $e) {
            throw new UnauthorizedHttpException('jwt-auth', $e->getMessage(), $e, $e->getCode());
        }
    }
415984
protected function createAuthCode($userkey, $applicationkey) {
        $payload = $userkey . "@" . strtolower($this->serverhostname) . "|" . strtolower($applicationkey);
        return strtoupper(sha1($payload));
    }
180617
public function handleAuthenticationFailure(AuthenticationException $authenticationException, Request $request, AuthenticatorInterface $guardAuthenticator, string $providerKey): ?Response
    {
        $response = $guardAuthenticator->onAuthenticationFailure($request, $authenticationException);
        if ($response instanceof Response || null === $response) {
            // returning null is ok, it means they want the request to continue
            return $response;
        }

        throw new \UnexpectedValueException(sprintf('The %s::onAuthenticationFailure method must return null or a Response object. You returned %s.', \get_class($guardAuthenticator), \is_object($response) ? \get_class($response) : \gettype($response)));
    }