Validate token
@param Token $token token object
@return bool
355817
public function validateToken(Token $token, int $currentTime = null)
    {

        $data = $this->getValidationData($currentTime);
        // @todo Add claims for validation
        return $token->validate($data);
    }
755498
public function validate($token)
    {
        if ($this->hasCache()) {
            $body = $this->getCache()->get($token);

            // Check if token is expired
            if (!is_null($body)) {
                $body = json_decode($body, true);
                if (new \DateTime($body['expire_at']) >= new \DateTime()) {
                    return $this->buildValidationReturn($body);
                } else {
                    $this->getCache()->delete($token);
                    throw new TokenException('The provided token is expired');
                }
            }
        }

        $request = (new RequestDescriptor())
            ->setUrl($this->buildUrl(sprintf('/api/token/validate?token=%s', (string) $token)))
            ->setMethod('GET');

        try {
            $body = json_decode($this->send($request)->getBody(), true);

            if ($this->hasCache()) {
                $this->getCache()->set(
                    $token,
                    json_encode($body),
                    (new \DateTime())->diff(new \DateTime($body['expire_at']))
                );
            }

            return $this->buildValidationReturn($body);
        } catch (ApiClientException $e) {
            $previous = $e->getPrevious();

            if ($previous instanceof BadResponseException) {
                $error = json_decode($previous->getResponse()->getBody(true), true);

                throw new TokenException($error['error'], $error['code'], $previous);
            }

            throw new TokenException($e->getMessage(), $e->getCode(), $e->getPrevious());
        }
    }
586748
public static function validateToken($tokenString)
    {
        $tokens = ApiToken::find(new AndGroup(
            [
                new Equals("Token", $tokenString),
                new GreaterThan("Expires", "now", true)
            ]
        ));

        if (count($tokens) != 1) {
            throw new TokenInvalidException();
        }

        /** @var ApiToken $token */
        $token = $tokens[0];
        $settings = ApiSettings::singleton();
        if ($settings->extendTokenExpirationOnUse) {
            $token->Expires = $settings->tokenExpiration;
            $token->save();
        }

        return $token->AuthenticatedUser;
    }
993613
protected function checkToken($token)
    {
        try {
            $response = $this->http->get($this->checkTokenURL(), [
                'headers' => [
                    'X-Requested-With' => 'XMLHttpRequest',
                    'Authorization' => 'Bearer ' . $token
                ]
            ]);
            $content = json_decode($response->getBody()->getContents());
            if (isset($content->message)) {
                if ($content->message === 'Token is valid') {
                    return true;
                }
            }
        } catch (\Exception $e) {
            return false;
        }
        return false;
    }
1193157
private function isConstantToken($token)
    {
        return $token == T_CONSTANT_ENCAPSED_STRING || $token == T_STRING || $token == T_LNUMBER || $token == T_DNUMBER;
    }
1132889
public function moveToToken(Token $token) {

      if (!$token->isValid()) {
        $this->setValid(false);
        return new Token();
      }

      $tokenIndex = $token->getIndex();


      foreach ($this->collection as $index => $collectionToken) {
        if ($collectionToken->getIndex() === $tokenIndex) {
          $this->setPosition($index);
          return $collectionToken;
        }
      }

      $this->setValid(false);
      return new Token();
    }
1001788
public function handlesToken($token)
    {
        return (
            isset($this->tokensHandled)
            && is_array($this->tokensHandled)
            && in_array($token, $this->tokensHandled)
        );
    }
964063
public function loginViaToken($token)
    {
        $user = $this->userDao->getUserByToken($token);
        if ($user) {
            $this->loginWithoutPassword($user->getLogin());
            return true;
        } else {
            return false;
        }
    }
350430
public function isValidToken($src, $token)
    {
        $img_token = $this->getToken($src);
        if ($img_token === null) {
            return false;
        }

        if (!hash_equals($img_token, $token)) {
            \Yii::warning("Invalid token", __METHOD__);
            return false;
        }

        return true;
    }
347519
protected function verifyToken(string $token): bool
    {
        if ($this->token_validation_url) {
            $this->logger->debug('validate oauth2 token via rfc7662 token validation endpoint ['.$this->token_validation_url.']', [
               'category' => get_class($this),
            ]);

            $url = str_replace('{token}', $token, $this->token_validation_url);
        } else {
            $discovery = $this->getDiscoveryDocument();
            if (!(isset($discovery['userinfo_endpoint']))) {
                throw new OidcException\UserEndpointNotSet('userinfo_endpoint could not be determained');
            }

            $this->logger->debug('validate token via openid-connect userinfo_endpoint ['.$discovery['userinfo_endpoint'].']', [
               'category' => get_class($this),
            ]);

            $url = $discovery['userinfo_endpoint'].'?access_token='.$token;
        }

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        $response = json_decode($result, true);

        if (200 === $code) {
            $attributes = json_decode($result, true);
            $this->logger->debug('successfully verified oauth2 access token via authorization server', [
               'category' => get_class($this),
            ]);

            if (!isset($attributes[$this->identity_attribute])) {
                throw new Exception\IdentityAttributeNotFound('identity attribute '.$this->identity_attribute.' not found in oauth2 response');
            }

            $this->identifier = $attributes[$this->identity_attribute];

            if ($this->token_validation_url) {
                $this->attributes = $attributes;
            } else {
                $this->access_token = $token;
            }

            return true;
        }
        $this->logger->error('failed verify oauth2 access token via authorization server, received status ['.$code.']', [
               'category' => get_class($this),
            ]);

        throw new OidcException\InvalidAccessToken('failed verify oauth2 access token via authorization server');
    }
708254
public function checkToken($token)
    {
        return (bool) $this->token()->where('token', $token)->where('expiration_date', '>', Carbon::now())->count();
    }
915675
public function isTokenValid(CsrfToken $token) {

		$tokenId = $token->getId();

		if (!$this->storage->hasToken($tokenId)) {
			return FALSE;
		}
	
		return hash_equals($this->storage->getToken($tokenId)->getValue(), $token->getValue());

	}
1141939
public static function isAccessTokenValid($token)
    {
        if (empty($token)) {
            return false;
        }
        $data = Yii::$app->jwt->getValidationData(); // It will use the current time to validate (iat, nbf and exp)
        $data->setIssuer(Yii::getAlias("@restIssuer"));
        $data->setAudience(Yii::getAlias("@restAudience"));
        $data->setId(Yii::getAlias("@restId")+strtotime(date('Y-m-d',time())), true);
        if (is_string($token))
            $token = Yii::$app->jwt->getParser()->parse($token);

        return $token->validate($data);
    }
6298
public static function isTokenValid(string $token): bool
    {
        if (!static::hasTokenStored()) {
            return false;
        }

        $storedToken = static::getStoredToken();
        return $storedToken->getToken() === $token;
    }
976949
public function contains( $token )
	{
		$token = (string) $token;
		$this->__validate( $token );

		return $this->__contains( $token );
	}
42736
public function deleteToken($token)
    {
        $tokenObject = $this->findToken($token);

        if ($tokenObject == null) {
            return (false);
        }
        $this->call($this->tyrUrl . '/' . $this->version . '/users/' . $this->user->id . '/keys/' . $tokenObject->id .'/', 'DELETE');
        return true;
    }
982558
protected function _verify($token)
    {
        if (empty($token)) {
            $this->_tokenError();
        }

        $subject = $this->_subject();
        $subject->set([
            'token' => $token,
            'repository' => $this->_table(),
            'query' => $this->_table()->find(
                $this->findMethod(),
                [
                    'token' => $token,
                    'conditions' => [$this->_table()->aliasField($this->config('tokenField')) => $token]
                ]
            ),
        ]);

        $this->_trigger('beforeFind', $subject);
        $entity = $subject->query->first();

        if (empty($token)) {
            $this->_tokenError();
        }

        $subject->set(['entity' => $entity]);
        $this->_trigger('afterFind', $subject);

        if (!isset($subject->verified)) {
            $subject->set(['verified' => false]);
        }
        $this->_trigger('verifyToken', $subject);

        if ($subject->verified) {
            return $subject->entity;
        }

        $this->_tokenError('tokenExpired');
    }