Retrieve user by token.

@author Morten Rugaard <moru@nodes.dk>

@return mixed|null
557283
protected function getUserByToken()
    {
        // Look up in cache and return if found
        if ($user = cache_get('api.userToken', $this->getCacheParams())) {
            return $user;
        }

        // Look up in database
        $user = $this->generateQuery()->first();

        // Add to cache
       if ($user) {
           cache_put('api.userToken', $this->getCacheParams(), $user);
       }

        return $user;
    }
845650
public function getUser()
    {
        // Ensure we have the user info
        if ($this->user === null) {
            $this->exchangeCode();
        }

        if (! is_array($this->user)) {
            return null;
        }

        return $this->user;
    }
521273
protected function getUserString()
    {
        $user = $this->core->auth()->user();

        if ( ! $user) return null;

        return $user->getUsername();
    }
1136701
public function getToken()
  {

    if ($this->has('token'))
    {
      return $this->get('token');
    }

    if ($this->has('access_token'))
    {
      return $this->get('access_token');
    }

    if ($this->has('accessToken'))
    {
      return $this->get('accessToken');
    }

    if ($authorization = $this->getHeader('AUTHORIZATION'))
    {
      return $authorization;
    }

    return null;
  }
1242191
protected function getUserByToken($token)
    {
        return $this->sdkClient()
                    ->useCustomApiEndpoint($this->getEnvironmentEndpoint('api'))
                    ->setAccessToken($token)
                    ->uses('Profile')
                    ->get()
                    ->toArray();
    }
70760
public function getUser($user) {
            if ($user instanceof TokenInterface) {
                $id = $user->getService();
            } else if (is_array($user)) {
                $id = $user['service'];
            } else {
                $id = $user;
            }

            if (!isset($this->users[$id])) {
                // TODO: execption
                return null;
            }
            if (is_string($this->users[$id])) {
                $this->users[$id] = $this->container->get($this->users[$id]);
            }

            if ($user instanceof TokenInterface) {
                $this->users[$id]->setTokenData($user);
            } else if (is_array($user)) {
                $this->users[$id]->setOptions($user);
            }

            return $this->users[$id];
        }
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;
  }
565440
protected function getUser()
    {
        if ($this->_user === null) {
            $this->_user = $this->getClient()->user;
        }
        return $this->_user;
    }
1284545
public function user()
    {
        // If we've already retrieved the user for the current request we can just
        // return it back immediately. We do not want to fetch the user data on
        // every call to this method because that would be tremendously slow.
        if (! is_null($this->user)) {
            return $this->user;
        }

        $user = null;

        // If a user ID was provided in the JWT, then
        // we should attempt to fetch their profile.
        if (! empty($this->id())) {
            $user = $this->provider->retrieveById($this->id());
        }

        return $this->user = $user;
    }
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());
        }
    }
1147027
public function getUser()
    {
        /** @var AbstractAdmin $admin */
        $admin = $this;

        $container = $admin->getContainer();

        if (!$container->has('security.token_storage')) {
            return null;
        }

        $tokenStorage = $container->get('security.token_storage');

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

        if (!\is_object($user = $token->getUser())) {
            // e.g. anonymous authentication
            return null;
        }

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

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

        return;
    }
462063
public function user()
    {
        // if the user was explicitly marked as logged out.
        if ($this->loggedOut) {
            // just return null.
            return null;
        }

        // if the user is already set.
        if ($this->user) {
            return $this->user;
        }

        // detects a token presence.
        $token = $this->detectedToken();

        // if the received token is not actually valid.
        if (!$token || !$this->manager->validToken($token)) {
            // also return null since the token
            // signature could not be determined.
            return null;
        }

        // if the token has expired.
        if ($this->manager->expired($token)) {
            // you got right?
            return null;
        }

        // try to find the user which the token belongs to.
        $user = $this->findUserByToken($token);

        // if the user has not been found.
        if (!$user) {
            // abort!
            return null;
        }

        // set the current user on the scope.
        $this->setUser($user);

        // return the scope user.
        return $this->user;
    }
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;
    }
1012681
public function user()
    {
        if (!is_null($this->user)) {
            return $this->user;
        }

        if ($this->jwt->setRequest($this->request)->getToken() && $this->jwt->check()) {
            $id = $this->jwt->payload()->get('sub');

            return $this->user = $this->provider->retrieveById($id);
        }
    }
876063
public function getUser()
    {
        if ($this->user_id) {
            return $this->hasOne(Yii::$app->user->identityClass, ['id' => 'user_id']);
        }
        return null;
    }
551156
public function user()
    {
        if ($this->user !== null) {
            return $this->user;
        }

        if ($this->jwt->setRequest($this->request)->getToken() &&
            ($payload = $this->jwt->check(true)) &&
            $this->validateSubject()
        ) {
            return $this->user = $this->provider->retrieveById($payload['sub']);
        }
    }