@param UserProviderInterface $provider
@param TokenInterface        $token

@return bool|ApiKeyUserToken
@throws AuthenticationException
542521
protected function doAuth($provider, TokenInterface $token)
    {
        if (! $provider instanceof ApiKeyUserProviderInterface) {
            return false;
        }

        /** @var UserInterface $user */
        $user = $provider->loadUserByApiKey($token->getCredentials());

        if ($user) {
            $authenticatedToken = new ApiKeyUserToken($user->getRoles());
            $authenticatedToken->setUser($user);

            return $authenticatedToken;
        }

        throw new AuthenticationException("The API Key authentication failed.");
    }
1373972
public function createAuthenticationProvider(\Silex\Application $app,
                                                 UserProviderInterface $userProvider,
                                                 $providerKey)
    {
        return new DaoAuthenticationProvider($userProvider,
            $app['security.user_checker'], $providerKey,
            $this->encoderFactory ? : $app['security.encoder_factory']);
    }
1304303
public function createToken(TokenInterface $token): TokenInterface
    {
        try {
            $now        = $this->ignoreException(function (): DateTimeImmutable {
                return new DateTimeImmutable();
            });
            $schema     = $this->getDatabaseSchema();
            $hasRefresh = $token->getRefreshValue() !== null;
            $values     = $hasRefresh === false ? [
                $schema->getTokensClientIdentityColumn() => $token->getClientIdentifier(),
                $schema->getTokensUserIdentityColumn()   => $token->getUserIdentifier(),
                $schema->getTokensValueColumn()          => $token->getValue(),
                $schema->getTokensTypeColumn()           => $token->getType(),
                $schema->getTokensIsScopeModified()      => $token->isScopeModified(),
                $schema->getTokensIsEnabledColumn()      => $token->isEnabled(),
                $schema->getTokensValueCreatedAtColumn() => $now,
            ] : [
                $schema->getTokensClientIdentityColumn()   => $token->getClientIdentifier(),
                $schema->getTokensUserIdentityColumn()     => $token->getUserIdentifier(),
                $schema->getTokensValueColumn()            => $token->getValue(),
                $schema->getTokensTypeColumn()             => $token->getType(),
                $schema->getTokensIsScopeModified()        => $token->isScopeModified(),
                $schema->getTokensIsEnabledColumn()        => $token->isEnabled(),
                $schema->getTokensValueCreatedAtColumn()   => $now,
                $schema->getTokensRefreshColumn()          => $token->getRefreshValue(),
                $schema->getTokensRefreshCreatedAtColumn() => $now,
            ];

            $tokenIdentifier = null;
            if (empty($scopeIdentifiers = $token->getScopeIdentifiers()) === false) {
                $this->inTransaction(function () use ($values, $scopeIdentifiers, &$tokenIdentifier) {
                    $this->createResource($values);
                    $tokenIdentifier = $this->getLastInsertId();
                    $this->bindScopeIdentifiers($tokenIdentifier, $scopeIdentifiers);
                });
            } else {
                $this->createResource($values);
                $tokenIdentifier = $this->getLastInsertId();
            }

            $token->setIdentifier($tokenIdentifier)->setValueCreatedAt($now);
            if ($hasRefresh === true) {
                $token->setRefreshCreatedAt($now);
            }

            return $token;
        } catch (RepositoryException $exception) {
            $message = 'Token creation failed';
            throw new RepositoryException($message, 0, $exception);
        }
    }
128705
public function refreshAccessToken(TokenInterface $token)
    {
      $refreshToken = $token->getRefreshToken();

      if(empty($refreshToken))
        throw new MissingRefreshTokenException();

      $parameters = array(
        'grant_type'    => 'refresh_token',
        'type'          => 'web_server',
        'client_id'     => $this->credentials->getConsumerId(),
        'client_secret' => $this->credentials->getConsumerSecret(),
        'refresh_token' => $refreshToken,
      );

      require_once 'libx/base.php';

      require_once 'libx/net/http/codes.class.php';
      require_once 'libx/net/rest/client.class.php';
      require_once 'libx/net/rest/request.class.php';
      require_once 'libx/net/rest/response.class.php';

      $request = new \LibXRestRequest($this->getAccessTokenEndpoint(), \LibXRestRequest::REQUEST_METHOD_POST);
      $request->setParameters($parameters);

      $response = new \LibXRestResponse();

      $client = new \LibXRestClient();
      $client->execute($request, $response);

      // Parse token
      $token = $this->parseAccessToken($response->getData());

      // Store token
      $this->storage->storeAccessToken($this->service(), $token);

      // Return token
      return $token;
    }
360023
public function create(ApiClientInterface $client, UserInterface $user = null)
    {
        $tokenClass = $this->tokenClass;

        return $tokenClass::create($client, $user);
    }
507739
protected function addCurrentUser(TokenInterface $token, array $sids)
    {
        if (!$token instanceof AnonymousToken) {
            try {
                $sids[] = UserSecurityIdentity::fromToken($token);
            } catch (\InvalidArgumentException $e) {
                // ignore, user has no user security identity
            }
        }

        return $sids;
    }
1112656
public function authorizeConsumerRequestToken ( $token, $user_id, $referrer_host = '' )
	{
 		// 1.0a Compatibility : create a token verifier
 		$verifier = substr(md5(rand()),0,10);
		
		$sql = "BEGIN SP_AUTH_CONSUMER_REQ_TOKEN(:P_USER_ID, :P_REFERRER_HOST, :P_VERIFIER, :P_TOKEN, :P_RESULT); END;";

			// parse sql
		$stmt = oci_parse($this->conn, $sql) or die ('Can not parse query');

		// Bind In and Out Variables
		oci_bind_by_name($stmt, ':P_USER_ID', $user_id, 255);
		oci_bind_by_name($stmt, ':P_REFERRER_HOST', $referrer_host, 255);
		oci_bind_by_name($stmt, ':P_VERIFIER', $verifier, 255);
		oci_bind_by_name($stmt, ':P_TOKEN', $token, 255);
		oci_bind_by_name($stmt, ':P_RESULT', $result, 20);


		//Execute the statement
		oci_execute($stmt);

		return $verifier;
	}
213057
public function verifyTwoFactor(UserInterface $user, $token, $remember = false)
    {
        $this->getTwoFactorStrategy()->verify($user, $token);

        // mark the user as 2FA verified, now and for the session
        $user->markTwoFactorVerified();

        // the user is now considered fully signed in
        // now we want to perform the sign in so an event is recorded
        // and a remember me token is generated, if needed
        if (!$user->isSignedIn()) {
            $this->signInUser($user, '2fa', $remember);
        }

        $saved = $this->getStorage()
                      ->twoFactorVerified($user,
                                          $this->request,
                                          $this->response);
        if (!$saved) {
            throw new AuthException('Unable to mark user session as two-factor verified');
        }

        return $this;
    }
489554
public function getSecurityIdentities(TokenInterface $token)
    {
        $sids = parent::getSecurityIdentities($token);

        if ($token->getUser() instanceof \BackBee\Security\User) {
            foreach ($token->getUser()->getGroups() as $group) {
                $securityIdentity = new UserSecurityIdentity($group->getObjectIdentifier(), ClassUtils::getRealClass($group));
                array_unshift($sids, $securityIdentity);
            }
        }

        return $sids;
    }
718644
private function getUser(TokenInterface $authenticationToken)
    {
        $user = $authenticationToken->getUser();

        if (is_string($user)) {
            return $user;
        } elseif (method_exists($user, 'getAPIUser')) {
            return $user->getAPIUser()->id;
        }

        return $authenticationToken->getUsername();
    }
583362
public function activateUser($token)
    {
        $activation = $this->getActivationByToken($token);

        if( $activation === null ) {
            throw new \Exception(trans('HCACL::users.activation.bad_token'));
        }

        $user = $this->getUser($activation);

        if( is_null($user) )
            throw new \Exception(trans('HCACL::users.activation.user_not_found'));

        // activate user
        $user->activate();

        // delete activation code
        $this->deleteActivation($token);

        // login user to the site
        auth()->login($user);
    }
238780
private function getAccessToken(Provider $provider, $userId, $scope)
    {
        $accessTokenList = $this->tokenStorage->getAccessTokenList($userId);
        foreach ($accessTokenList as $accessToken) {
            if ($provider->getProviderId() !== $accessToken->getProviderId()) {
                continue;
            }
            if ($scope !== $accessToken->getScope()) {
                continue;
            }

            return $accessToken;
        }

        return false;
    }
223920
public function userHasSocialLoginWithProvider($provider, $user)
    {
        return (bool) $this->socialLoginMapper->findBy([
            'provider' => $provider,
            'user_id'  => $user->getId()
        ]);
    }
124805
public function setToken(string $token, int $authentication = self::OAUTH_AUTH): AbstractApi
    {
        $this->token = $token;
        $this->setAuthentication($authentication);

        return $this;
    }
24387
public function authenticate(string $method, string $token, string $password = null)
    {
        $this->getHttpClientBuilder()->removePlugin(Authentication::class);
        $this->getHttpClientBuilder()->addPlugin(new Authentication($method, $token, $password));
    }
777004
public function getAPI(TokenInterface $token) {
            $id = $token->getService();
            if (!isset($this->apis[$id])) {
                // TODO: execption
                return null;
            }
            if (is_string($this->apis[$id])) {
                $this->apis[$id] = $this->container->get($this->apis[$id]);
            }

            $this->apis[$id]->setAccessToken($token);
            return $this->apis[$id];
        }
640686
public static function fromToken(TokenInterface $token)
    {
        $user = $token->getUser();

        if ($user instanceof RoleableInterface) {
            $sids = [];
            $roles = $user->getRoles();

            foreach ($roles as $role) {
                $sids[] = self::fromAccount($role);
            }

            return $sids;
        }

        throw new InvalidArgumentException('The user class must implement "Fxp\Component\Security\Model\Traits\RoleableInterface"');
    }