Tries to authenticate user via social network. If user has already used
this network's account, he will be logged in. Otherwise, it will try
to create new user account.

@param ClientInterface $client
968176
public function authenticate(ClientInterface $client) {
    $account = Account::find()->byClient($client)->one();

    if (!$this->module->enableRegistration && ($account === null || $account->user === null)) {
      Yii::$app->session->setFlash('danger', Yii::t('users', 'Registration on this website is disabled'));
      $this->action->successUrl = Url::to(['/users/security/login']);
      return;
    }

    if ($account === null) {
      /** @var Account $account */
      $accountObj = Yii::createObject(Account::className());
      $account = $accountObj::create($client);
    }

    $event = $this->getAuthEvent($account, $client);

    $this->trigger(self::EVENT_BEFORE_AUTHENTICATE, $event);

    if ($account->user instanceof User) {
      if ($account->user->isBlocked) {
        Yii::$app->session->setFlash('danger', Yii::t('users', 'Your account has been blocked.'));
        $this->action->successUrl = Url::to(['/users/security/login']);
      } else {
        Yii::$app->user->login($account->user, $this->module->rememberFor);
        $this->action->successUrl = Yii::$app->getUser()->getReturnUrl();
      }
    } else {
      $this->action->successUrl = $account->getConnectUrl();
    }

    $this->trigger(self::EVENT_AFTER_AUTHENTICATE, $event);
  }
253791
public function setClient($client)
    {
        if (!$client instanceof CloudFrontClient) {
            @trigger_error('The '.__METHOD__.' expects a CloudFrontClient as parameter.', E_USER_DEPRECATED);
        }

        $this->client = $client;
    }
912554
public function withClient(ClientInterface $client): AmazonServer
    {
        $server = clone $this;
        $server->client = $client;

        return $this;
    }
1358236
public function register(ClientInterface $client)
    {
        $client = $this->decorate($client);

        array_push($this->clients, $client);

        return $client;
    }
1262632
protected function registerClientSubscribers(ClientInterface $client)
    {
        $client->on('irc.received', function ($message, $write, $connection) {
            $this->processClientEvent('irc.received', $message, $connection, $write);
        });

        $client->on('irc.sent', function ($message, $write, $connection) {
            $parsed = $this->getParser()->parse($message);
            if (!$parsed) {
                return;
            }
            $this->processClientEvent('irc.sent', $parsed, $connection, $write);
        });

        $client->on('irc.tick', function ($write, $connection) {
            $this->processOutgoingEvents($connection, $write);
        });
    }
520712
public function send(RequestInterface $request, array $options = [])
    {
        $response = parent::send($request, $options);

        // re-authenticate if 403 and token is expired
        if (
            $this->token &&
            $response->getStatusCode() === 403 &&
            $this->isTokenExpired($this->token) &&
            !$this->authenticate()
        ) {
            throw new ClientException('Cannot re-authenticate.');
        }

        $this->checkResponse($response);

        return $response;
    }
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);
    }
1129901
public function authenticate(IRequest $request)
    {
        $id = $request->request('client_id');
        $secret = $request->request('client_secret');

        if (!$id) {
            throw new InvalidClientException('Client id is missing.');
        }

        if (!$client = $this->clientStorage->get($id)) {
            throw new InvalidClientException('Invalid client credentials.');
        }

        if ((string) $secret !== (string) $client->getSecret()) {
            throw new InvalidClientException('Invalid client credentials.');
        }

        return $client;
    }
423537
public function setClient(\OAuth2\ServerBundle\Entity\Client $client = null)
    {
        $this->client = $client;

        return $this;
    }
443468
private function addClient(ClientInterface $client): self
    {
        $configurations = $this->configResolver->getParameter('configurations', 'ez_platform_automated_translation');
        $reflection     = new \ReflectionClass($client);
        $key            = strtolower($reflection->getShortName());
        if (isset($configurations[$key])) {
            $client->setConfiguration($configurations[$key]);
            $this->clients[$key] = $client;
        }

        return $this;
    }
1252037
public function add(ClientInterface $client)
    {
        $this->clients[$client->getClientType()][$client->getClientIdentifier()] = $client;

        return $this;
    }
651113
public static function setKey($key, ClientInterface $client = null)
	{
		self::$api = new Api($key, $client);

		return self::$api;
	}
274570
public function oauthCallbackAction(Request $request, Session $session, Client $client): RedirectResponse
    {
        // Give up if the required GET params or stored request token don't exist.
        if (!$request->get('oauth_verifier')) {
            throw $this->createNotFoundException('No OAuth verifier given.');
        }
        if (!$session->has('oauth.request_token')) {
            throw $this->createNotFoundException('No request token found. Please try logging in again.');
        }

        // Complete authentication.
        $token = $session->get('oauth.request_token');
        $verifier = $request->get('oauth_verifier');
        $accessToken = $client->complete($token, $verifier);

        // Store access token, and remove request token.
        $session->set('oauth.access_token', $accessToken);
        $session->remove('oauth.request_token');

        // Regenerate session ID.
        $session->migrate();

        // Store user identity.
        $ident = $client->identify($accessToken);
        $session->set('logged_in_user', $ident);

        // Send to homepage.
        return $this->redirectToRoute('home');
    }
1128447
public function authenticate(OAuth $client)
    {
        $account = Wechat::find()->byClient($client)->one();
        if ($account === null) {
            $account = Wechat::create($client);
        }
        if ($account->user instanceof User) {
            if ($account->user->isBlocked) {
                Yii::$app->session->setFlash('danger', Yii::t('user', 'Your account has been blocked.'));
                $this->action->successUrl = Url::to(['/user/security/login']);
            } else {
                Yii::$app->user->login($account->user, $this->getSetting('rememberFor'));
                $this->action->successUrl = Yii::$app->getUser()->getReturnUrl();
            }
        } else {
            $this->action->successUrl = $account->getConnectUrl();
        }
    }
166854
public function setRemoteUser(ClientInterface $client, IdentityInterface $user)
    {
        $model = $this->getRemoteUser($client);
        $model->client_id = $user->getId();
        $model->save();

        return $user;
    }
729509
public function addClient(\Gpupo\CommonSchema\ORM\Entity\Application\API\OAuth\Client\Client $client)
    {
        $this->clients[] = $client;

        return $this;
    }
689903
protected function createClientCredentialsClient(ClientRepository $clients)
    {
        $name = $this->option('name') ?: $this->ask(
            'What should we name the client?',
            config('app.name').' ClientCredentials Grant Client'
        );

        $client = $clients->create(
            null, $name, ''
        );

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

        $this->outputClientDetails($client);
    }