Validate BOT token

    :param token:
    :return:
422370
def check_token(token: str) -> bool:
    
    if any(x.isspace() for x in token):
        raise exceptions.ValidationError('Token is invalid!')

    left, sep, right = token.partition(':')
    if (not sep) or (not left.isdigit()) or (len(left) < 3):
        raise exceptions.ValidationError('Token is invalid!')

    return True
185976
public function validateCsrfToken($token) {
		return (
			isset($_SESSION[$this->csrfTokenSessionKey])
			&& $_SESSION[$this->csrfTokenSessionKey] === $token
		);
	}
1109629
private boolean _validate(Token token, Term term) {

		if (token == null) {
			return true;
		}

		Set<String> terms = token.getTerms();
		if ((!terms.contains(Token.ALL)) && !terms.contains(term.getName()) && !(terms.contains(":" + term.getNatureStr()))) {
			return true;
		}

		boolean flag = token.getRegexs().size() != 0;

		for (String regex : token.getRegexs()) {
			if (term.getName().matches(regex)) {
				flag = false;
				break;
			}
		}

		return flag;
	}
416725
def token_auth(self, token):
        
        if not token:
            return

        self.headers.update({
            'Authorization': 'token {0}'.format(token)
            })
        # Unset username/password so we stop sending them
        self.auth = None
673073
def _token_valid(self):
        
        if not self._cache_token:
            return False
        now = time.time()
        if now - self._token.acquired_time > self._token_timeout:
            logger.debug('token needs to be reset')
            return False
        return True
575794
public CommonProfile validateToken(final String token) {
        final TokenCredentials credentials = new TokenCredentials(token);
        try {
            validate(credentials, null);
        } catch (final HttpAction e) {
            throw new TechnicalException(e);
        } catch (final CredentialsException e) {
            logger.info("Failed to retrieve or validate credentials: {}", e.getMessage());
            logger.debug("Failed to retrieve or validate credentials", e);
            return null;
        }
        return credentials.getUserProfile();
    }
585573
def check_token_status(token)
      info = Slack::Web::Client.new(token: token).auth_test
      fail SlackBotManager::InvalidToken unless info && info['ok']
      info
    end
97004
def check_token(self, user, token):
        
        # Parse the token
        try:
            ts_b36, hash = token.split("-")
        except ValueError:
            return False

        try:
            ts = base36_to_int(ts_b36)
        except ValueError:
            return False

        # Check that the timestamp/uid has not been tampered with
        if not constant_time_compare(self._make_token_with_timestamp(user, ts), token):
            return False

        # Check the timestamp is within limit
        if (self._num_days(self._today()) - ts) > REGISTRATION_TIMEOUT_DAYS:
            return False

        return True
1244497
def validate(token):
    """"""
    token_url = TOKEN_URL_FMT.format(token=token)
    headers = {
        'x-auth-token': token,
        'accept': 'application/json',
    }
    resp = requests.get(token_url, headers=headers)

    if not resp.status_code == 200:
        raise HTTPError(status=401)
    return resp.json()
1169564
def verify_token_type(self):
        
        try:
            token_type = self.payload[api_settings.TOKEN_TYPE_CLAIM]
        except KeyError:
            raise TokenError(_('Token has no type'))

        if self.token_type != token_type:
            raise TokenError(_('Token has wrong type'))
1362214
private static boolean areTokensValid(Token... tokens)
    {
        for (Token token : tokens)
        {
            if (!isTokenValid(token))
                return false;
        }
        return true;
    }
57163
def valid(cls, token, **kwargs):
        
        try:
            token = yield cls.get(token)
        except couch.NotFound:
            raise Return(False)

        raise Return(token.ttl >= datetime.utcnow())
1190126
def valid_token?
      uri = URI.join(Teambition::API_DOMAIN, "/api/applications/#{Teambition.client_key}/tokens/check")

      req = Net::HTTP::Get.new(uri)
      req['Authorization'] = "OAuth2 #{token}"

      res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |https|
        https.request(req)
      end
      res.code == '200'
    end
351746
def validate(config):
    '''
    
    '''
    if not isinstance(config, list):
        return False, ('Configuration for telegram_bot_msg '
                       'beacon must be a list.')

    _config = {}
    list(map(_config.update, config))

    if not all(_config.get(required_config)
               for required_config in ['token', 'accept_from']):
        return False, ('Not all required configuration for '
                       'telegram_bot_msg are set.')

    if not isinstance(_config.get('accept_from'), list):
        return False, ('Configuration for telegram_bot_msg, '
                       'accept_from must be a list of usernames.')

    return True, 'Valid beacon configuration.'
532082
def _oauth_tokengetter(token=None):
    
    token = session.get("oauth")
    log.debug("Token Get: {0}".format(token))
    return token
680230
def _verify_token(self):
        
        res = self._session.get(self._token_verification_url)
        if not res.ok:
            raise exceptions.BadToken(consts.LOG_MSG_BAD_TOKEN)
        return True
367763
private function validateToken($token)
    {
        // Without a session file, no token will validate.
        if (!file_exists($this->config->getSessionFileName()))
        {
            return false;
        }

        $encrypted = file_get_contents($this->config->getSessionFileName()); // Read encrypted session file.

        $plain = Encryption::decrypt($encrypted, $this->config->getSecretKey()); // Decrypt data.
        $file = Spyc::YAMLLoadString($plain); // Parse YAML.

        return $token == $file['token'] && time() < $file['expires']; // Token must be valid and not expired.
    }