@param ApiClientInterface $client
@param UserInterface      $user

@return TokenInterface
343154
public static function create(ApiClientInterface $client, UserInterface $user = null)
    {
        $accessToken = new self();
        $accessToken->setUser($user);
        $accessToken->setClient($client);

        return $accessToken;
    }
981580
protected function createAuthCodeClient(ClientRepository $clients)
    {
        $userId = $this->option('user_id') ?: $this->ask(
            'Which user ID should the client be assigned to?'
        );

        $name = $this->option('name') ?: $this->ask(
            'What should we name the client?'
        );

        $redirect = $this->option('redirect_uri') ?: $this->ask(
            'Where should we redirect the request after authorization?',
            url('/auth/callback')
        );

        $client = $clients->create(
            $userId, $name, $redirect
        );

        $this->info('New client created successfully.');

        $this->outputClientDetails($client);
    }
1356720
private function updateUserByOAuthUserResponse(UserInterface $user, UserResponseInterface $response): SyliusUserInterface
    {
        /** @var SyliusUserInterface $user */
        Assert::isInstanceOf($user, SyliusUserInterface::class);

        /** @var UserOAuthInterface $oauth */
        $oauth = $this->oauthFactory->createNew();
        $oauth->setIdentifier($response->getUsername());
        $oauth->setProvider($response->getResourceOwner()->getName());
        $oauth->setAccessToken($response->getAccessToken());
        $oauth->setRefreshToken($response->getRefreshToken());

        $user->addOAuthAccount($oauth);

        $this->userManager->persist($user);
        $this->userManager->flush();

        return $user;
    }
1121034
public function updateClient(ClientInterface $client)
    {
        if (isset($this->clients[$client->getAccessToken()])) {
            $this->clients[$client->getAccessToken()] = $client;
        }
    }
211663
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
    {
        return $this->authenticateApiKeyToken($token, $userProvider, $providerKey);
    }
101550
public function createAuthenticatedToken(UserInterface $user, $providerKey)
    {
        $preAuthToken = $this->preAuthenticationTokenStorage->getToken();

        if (null === $preAuthToken) {
            throw new \RuntimeException('Unable to return an authenticated token since there is no pre authentication token.');
        }

        $authToken = new JWTUserToken($user->getRoles(), $user, $preAuthToken->getCredentials(), $providerKey);

        if ($this->dispatcher instanceof ContractsEventDispatcherInterface) {
            $this->dispatcher->dispatch(new JWTAuthenticatedEvent($preAuthToken->getPayload(), $authToken), Events::JWT_AUTHENTICATED);
        } else {
            $this->dispatcher->dispatch(Events::JWT_AUTHENTICATED, new JWTAuthenticatedEvent($preAuthToken->getPayload(), $authToken));
        }

        $this->preAuthenticationTokenStorage->setToken(null);

        return $authToken;
    }
1093582
public function create(UserInterface $user) {
    $this->tokens->purge($user);
    return $this->tokens->create($user);
  }
536352
public static function getUserAwareChoiceBuilder(FormBuilderInterface $builder, UserInterface $user = null)
    {
        return function (EntityRepository $objectRepository) use ($builder, $user) {
            return $objectRepository->createQueryBuilder('o')
                ->andWhere('o.user = :user')
                ->setParameter('user', $user ?: $builder->getAttribute('user_aware'))
            ;
        };
    }
47798
public function setApiClient(ApiClientInterface $apiClient)
    {
        $this->apiClient = $apiClient;
        $this->apiClient->setConfig($this->config);
        $this->apiClient->setLogger($this->logger);

        return $this;
    }
75473
public function refreshCreateAccessTokenResponse(
        ClientInterface $client,
        \Limoncello\OAuthServer\Contracts\TokenInterface $token,
        bool $isScopeModified,
        array $scope = null,
        array $extraParameters = []
    ): ResponseInterface {
        $this->logDebug('Prepare refresh token.');

        /** @var TokenInterface $token */
        assert($token instanceof TokenInterface);

        $updatedToken   = clone $token;
        $tokenExpiresIn = $this->getIntegration()->isRenewRefreshValue() === false ?
            $this->setUpTokenValue($updatedToken) : $this->setUpTokenValues($updatedToken);

        $tokenRepo = $this->getIntegration()->getTokenRepository();
        if ($isScopeModified === false) {
            $tokenRepo->updateValues($updatedToken);
        } else {
            assert(is_array($scope));
            $tokenRepo->inTransaction(function () use ($tokenRepo, $updatedToken, $scope) {
                $tokenRepo->updateValues($updatedToken);
                $tokenRepo->unbindScopes($updatedToken->getIdentifier());
                $tokenRepo->bindScopeIdentifiers($updatedToken->getIdentifier(), $scope);
            });
            $updatedToken->setScopeModified()->setScopeIdentifiers($scope);
        }
        $response = $this->createBodyTokenResponse($updatedToken, $tokenExpiresIn);

        return $response;
    }
1069333
public static function create(UserInterface $user): UserMetaInterface
    {
        /** @var AbstractUser $user */
        $user_meta = static::findOne(['user_id' => $user->id]);
        if ($user_meta instanceof UserMetaInterface) {
            return $user_meta;
        }
        $user_meta = new static([
            'user_id' => $user->id,
            'notification_email' => $user->email,
            'display_name' => $user->username,
        ]);
        (new UserMetaHandler($user_meta))->create();
        $user_meta->refresh();
        return $user_meta;
    }
577799
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
    {
        if (empty($this->secretKey) == false) {
            $captcha = $this->request->get('g-recaptcha-response');

            $reCaptcha = new ReCaptcha($this->secretKey);
            $response = $reCaptcha->verify($captcha, $this->request->getClientIp());

            if ($response->isSuccess() == false) {
                throw new AuthenticationException('Captcha not passed');
            }
        }

        try {
            $user = $userProvider->loadUserByUsername($token->getUsername());
        } catch (UsernameNotFoundException $e) {
            throw new AuthenticationException('Invalid username or password');
        }

        $passwordValid = $this->encoder->isPasswordValid($user, $token->getCredentials());

        if ($passwordValid) {
            return new UsernamePasswordToken(
                $user,
                $user->getPassword(),
                $providerKey,
                $user->getRoles()
            );
        }

        throw new AuthenticationException('Invalid username or password');
    }
853632
public function createToken($owner, $client, array $scopes = []): RefreshToken
    {
        if (empty($scopes)) {
            $scopes = $this->scopeService->getDefaultScopes();
        } else {
            $this->validateTokenScopes($scopes);
        }

        do {
            $token = RefreshToken::createNewRefreshToken(
                $this->serverOptions->getRefreshTokenTtl(),
                $owner,
                $client,
                $scopes
            );
        } while ($this->tokenRepository->tokenExists($token->getToken()));

        return $this->tokenRepository->save($token);
    }
61678
private function refreshUser(TokenInterface $token)
    {
        $user = $token->getUser();
        if (!$user instanceof UserInterface) {
            return $token;
        }

        if (null !== $this->logger) {
            $this->logger->debug(sprintf('Reloading user from user provider.'));
        }

        foreach ($this->userProviders as $provider) {
            try {
                $refreshedUser = $provider->refreshUser($user);
                $token->setUser($refreshedUser);

                if (null !== $this->logger) {
                    $this->logger->debug(sprintf('Username "%s" was reloaded from user provider.', $refreshedUser->getUsername()));
                }

                return $token;
            } catch (UnsupportedUserException $unsupported) {
                // let's try the next user provider
            } catch (UsernameNotFoundException $notFound) {
                if (null !== $this->logger) {
                    $this->logger->warning(sprintf('Username "%s" could not be found.', $notFound->getUsername()));
                }

                return;
            }
        }

        throw new \RuntimeException(sprintf('There is no user provider for user "%s".', get_class($user)));
    }
489073
private function findKeyByUser(PKEncryptionEnabledUserInterface $user)
    {
        $userClass = $this->getUserClass($user);
        $userId = $user->getId();
        $key = $this->getKeyRepository()->findOneBy(array('userClass' => $userClass, 'userId' => $userId));

        return $key;
    }
643887
public function setUser(UserInterface $user)
    {
        $this->user = $user;

        $this->loggedOut = false;

        return $this;
    }
461352
public static function fromUsername($username, ApiClient $apiClient = null)
    {
        if (is_null($apiClient)) {
            $apiClient = static::createApiClient();
        }

        $apiResult = $apiClient->uuidApi($username);

        $json = $apiResult;

        if (isset($json->error)) {
            throw new \RuntimeException('Mojang Error: '.$json->errorMessage);
        }

        if (empty($json) || !isset($json[0]->id)) {
            throw new \RuntimeException('Invalid Username ('.$username.')');
        }
        static::rateLimitBust();

        return static::fromUuid($json[0]->id);
    }