Obtain the user information from Tokenpass.

And sync it with our local database

@return Response
973038
public function sync(Request $request)
    {

        try {
            $logged_in_user = Auth::user();

            $oauth_user = null;
            if ($logged_in_user['oauth_token']) {
                $oauth_user = Socialite::getUserByExistingToken($logged_in_user['oauth_token']);
            }

            if ($oauth_user) {
                $tokenly_uuid       = $oauth_user->id;
                $oauth_token        = $oauth_user->token;
                $username           = $oauth_user->user['username'];
                $name               = $oauth_user->user['name'];
                $email              = $oauth_user->user['email'];
                $email_is_confirmed = $oauth_user->user['email_is_confirmed'];

                // find an existing user based on the credentials provided
                $existing_user = User::where('tokenly_uuid', $tokenly_uuid);
                if ($existing_user) {
                    // update
                    $existing_user->update(['name' => $name, 'email' => $email, /* etc */ ]);
                }

                $synced = true;
            } else {
                // not able to sync this user
                $synced = false;
            }

            return view('account.sync', ['synced' => $synced, 'user' => $logged_in_user, ]);

        } catch (Exception $e) {
            return view('account.sync-failed', ['error_msg' => 'Failed to sync this user.']);
        }
    }
676798
public function getTokenFromServer()
    {
        $params = [
            'component_appid' => $this->appId,
            'component_appsecret' => $this->secret,
            'component_verify_ticket' => $this->ticket->getTicket(),
        ];

        $http = $this->getHttp();

        $token = $http->parseJSON($http->json(self::API_TOKEN_GET, $params));

        if (empty($token['component_access_token'])) {
            throw new HttpException('Request AccessToken fail. response: '.json_encode($token, JSON_UNESCAPED_UNICODE));
        }

        $token['access_token'] = $token['component_access_token'];

        return $token;
    }
712414
protected function getCurrentUser()
    {
        if ($this->tokenStorage && ($token = $this->tokenStorage->getToken())) {
            $user = $token->getUser();

            if ($user instanceof UserInterface) {
                return $user;
            }
        }

        return;
    }
1063369
protected function getLoggedUser()
    {
        $user = $this->get('security.token_storage')->getToken()->getUser();
        if (is_string($user)) {
            $user = null;
        }

        return $user;
    }
947909
public function acquireUserInfo()
    {
        // Request the userinfo
        $client = new Client(); //GuzzleHttp\Client

        $this->buildHttpHeader();
        $endpoint = $this->userinfo_endpoint;

        try {
            $response = $client->request('GET', $endpoint, [
                'header' => $this->headers,
                'curl' => $this->setGetCurlopts(),
            ]);

            // Get the token and type from the response
            // $this->parseTokenResponse($response);
            return json_decode($response->getBody(), true);

        } catch (\GuzzleException $e) {

            return false;
        }
    }
368618
public function userInfo()
    {
        try {
            $this->startBrokerSession();

            $username = $this->getSessionData('sso_user');

            if (!$username) {
                $this->fail('User not authenticated. Session ID: ' . $this->getSessionData('id'));
            }

            if (!$user = $this->getUserInfo($username)) {
                $this->fail('User not found.');
            }
        } catch (SSOServerException $e) {
            return $this->returnJson(['error' => $e->getMessage()]);
        }

        return $this->returnUserInfo($user);
    }
536750
public function getUser()
    {
        if (null === $tokenStorage = $this->tokenStorage) {
            throw new \RuntimeException('The "app.user" variable is not available.');
        }

        if (!$token = $tokenStorage->getToken()) {
            return;
        }

        $user = $token->getUser();
        if (\is_object($user)) {
            return $user;
        }
    }
227143
public function getTokenResponse()
    {
        $query = [
            'grant_type' => 'client_credential',
            'appid' => $this['appid'],
            'secret' => $this['appsecret'],
        ];

        $response = Http::request('GET', static::ACCESS_TOKEN)
            ->withQuery($query)
            ->send();

        if ($response->containsKey('errcode')) {
            throw new \Exception($response['errmsg'], $response['errcode']);
        }

        return $response;
    }
1308449
public function getUser()
    {
        if ($this->userAuthenticated) {
            return $this->user;
        }

        try {
            // get token
            $this->user = new AnonymousUser();
            $tokenData = $this->getToken()->getUserFromToken();

            if (!$tokenData) {
                $this->eventManager()->fire(SecurityEvent::NOT_AUTHENTICATED, new SecurityEvent($this->user));

                $this->userAuthenticated = false;

                return $this->user;
            } else {
                $this->user->populate($tokenData->getUsername(), '', $tokenData->getRoles(), true);
                $this->user->setAuthProviderName($tokenData->getAuthProviderName());
                $this->user->setUserProviderName($tokenData->getUserProviderName());
                $this->eventManager()->fire(SecurityEvent::AUTHENTICATED, new SecurityEvent($this->user));
                $this->setUserRoles();

                $this->userAuthenticated = true;

                return $this->user;
            }
        } catch (TokenException $e) {
            throw $e;
        } catch (\Exception $e) {
            $this->userAuthenticated = true;
            throw new FirewallException($e->getMessage());
        }
    }
402169
public function authorize()
    {
        // Create the request and response objects
        $request = \OAuth2\Request::createFromGlobals();
        $response = new \OAuth2\Response();

        // Validate the authorize request
        if (!$this->tokenServer->validateAuthorizeRequest($request, $response)) {
            // Get the data as json and convert it to an array,
            // - so we can set our own response type.
            $data = $response->getResponseBody('json');
            $data = json_decode($data, true);

            // Set the response, status code and output content setting final output to true
            $this->response = $data;
            $this->statusCode = $response->getStatusCode();
            $this->output(true);
            return $this;
        }

        // Display an authorization form
        if ($this->method != 'post' || !isset($this->data['authorized'])) {
            // Get the authorization form
            ob_start();
            require $this->configuration->getAuthorizationForm();
            $form = ob_get_clean();
            $this->response = $form;
            $this->statusCode = 200;
            $this->responseType = 'text/html';
            $this->output(true);
            return $this;
        }

        // Print the authorization code if the user has authorized your client
        $isAuthorized = ($this->data['authorized'] === 'yes');
        $this->tokenServer->handleAuthorizeRequest($request, $response, $isAuthorized);

        // Check if the request was successful
        if ($response->getStatusCode() === 302) {
            // Check if we should redirect according to our configuration
            if ($this->configuration->getRedirectAuthorization() === true) {
                // The response will contain a Location header we should navigate to
                header('Location: ' . $response->getHttpHeader('Location'));
                exit;
            }

            // Create a response with the authorization code
            $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40);
            $this->response = ['status' => 1, 'authorization_code' => $code];
            $this->statusCode = 200;
            $this->output(true);
            return $this;
        }

        // Get the data as json and convert it to an array,
        // - so we can set our own response type.
        $data = $response->getResponseBody('json');
        $data = json_decode($data, true);

        // Set the response, status code and output content setting final output to true
        $this->response = $data;
        $this->statusCode = $response->getStatusCode();
        $this->output(true);
        return $this;
    }
955840
public function getUserInfo()
    {
        if (!isset($this->userinfo)) {
            $this->userinfo = $this->request('GET', 'userInfo');
        }

        return $this->userinfo;
    }
496945
public function getUser()
    {

        // destroy previous content
        $this->destroyUserData();

        if ($this->user === false) {

            // get user

            $url = 'http://ulogin.ru/token.php?token=' . $this->getToken() . '&host=' . (new Request())->getHttpHost();
            $content = file_get_contents($url);
            $this->user = json_decode($content, true);

            // if use has error , destroy user data
            if ($this->destroyUserData() === true) {
                $this->logout();
            }
        }

        return $this->user;
    }
590213
public function getMeAction()
    {
        $tokenManager = $this->get('fos_oauth_server.access_token_manager');


        $accessToken = $tokenManager->findTokenByToken(
            $this->get('security.context')->getToken()->getToken()
        );
        /* @var $me UserInterface */
        $me = $accessToken->getUser();

        if (null === $me) {
            throw new NotFoundHttpException('User is null.');
        }
        if (false === $me instanceof UserInterface) {
            throw new NotFoundHttpException('User not found.');
        }

        return new JsonResponse([
            'objectId' => $me->getId()
            , 'userName' => $me->getUsername()]);
    }
247337
private function checkUser()
    {
        static $enabled;

        if (!isset($enabled)) {

            $token = $this->tokenStorage->getToken();

            if ($token) {

                $user = $token->getUser();

                if ($user instanceof \FOS\UserBundle\Model\User) {
                    if ($user->hasRole('ROLE_USER'))
                        $enabled = $token->isAuthenticated();
                }
            } else
                $enabled = false;
        }

        return $enabled;
    }
1046736
protected function getCurrentUser()
    {
        if (!$this->tokenStorage) {
            return;
        }

        if (!$this->tokenStorage->getToken()) {
            return;
        }

        $user = $this->tokenStorage->getToken()->getUser();

        if ($user instanceof UserInterface) {
            return $user;
        }

        return;
    }
109899
protected function getTokenData() {
    $result = null;

    $request = ObjectFactory::getInstance('request');
    $token = $request->hasHeader(self::TOKEN_HEADER) ?
        trim(str_replace(self::AUTH_TYPE, '', $request->getHeader(self::TOKEN_HEADER))) : $this->token;
    if ($token !== null) {
      $jwt = (new Parser())->parse((string)$token);

      // validate
      $data = new ValidationData();
      $data->setIssuer($this->getTokenIssuer());
      if ($jwt->validate($data) && $jwt->verify($this->getTokenSigner(), $this->key)) {
        $result = $jwt->getClaims();
      }
    }
    return $result;
  }
1287648
public function getRequestUser()
    {
        if ($this->requestUser === null) {
            $token = $this->getRequestApiToken();
            if ($token === '') {
                $this->requestUser = 'no-token';
            } else {
                $ip = $this->app->make('ip');
                if ($ip->isBanned()) {
                    $this->requestUser = 'banned';
                } else {
                    $requestUser = null;
                    $list = new UserList();
                    $list->disableAutomaticSorting();
                    $list->filterByAttribute('api_token', $token);
                    $ids = $list->getResultIDs();
                    if (!empty($ids)) {
                        $u = \User::getByUserID($ids[0]);
                        if ($u->isRegistered()) {
                            $requestUser = $u;
                        }
                    }
                    if ($requestUser === null) {
                        $this->requestUser == 'invalid-token';
                        $ip->logSignupRequest();
                        if ($ip->signupRequestThreshholdReached()) {
                            $ip->createIPBan();
                        }
                    } else {
                        $this->requestUser = $requestUser;
                    }
                }
            }
        }
        if ($this->requestUser === 'no-token') {
            throw AccessDeniedException::create(t('API Access Token required'));
        }
        if ($this->requestUser === 'banned') {
            throw AccessDeniedException::create($this->app->make('ip')->getErrorMessage());
        }
        if ($this->requestUser === 'invalid-token') {
            throw AccessDeniedException::create(t('Bad API Access Token'));
        }

        return $this->requestUser;
    }