Validate that the provided token

@param string $token
@param string $secret
@param string $algorithm

@return bool
197519
public function validateToken($token, $secret, $algorithm = 'HS256')
    {
        try {
            JWT::decode($token, $secret, [$algorithm]);
        } catch(\Exception $e) {
            return false;
        }

        return true;
    }
1026032
public static function customPayload(array $payload, string $secret): string
    {
        $builder = self::builder();

        foreach ($payload as $key => $value) {
            if (is_int($key)) {
                throw new ValidateException('Invalid payload claim.', 8);
            }

            $builder->setPayloadClaim($key, $value);
        }

        return $builder->setSecret($secret)
            ->build()
            ->getToken();
    }
657263
public function request($method, $url, $params=array(), $token='', $secret='') {
        if (empty($token)) {
            $token = $this->access_token;
        }
        if (empty($secret)) {
            $secret = $this->access_token_secret;
        }
        // to access protected resource, sign_secret will alwasy be consumer_secret+token_secret
        $this->sign_secret = $this->consumer_secret.'&'.$secret;
        if (strtolower($method) === 'post' && !empty($params)) {
            $oauth_params = $this->prepare_oauth_parameters($url, array('oauth_token'=>$token) + $params, $method);
        } else {
            $oauth_params = $this->prepare_oauth_parameters($url, array('oauth_token'=>$token), $method);
        }
        $this->setup_oauth_http_header($oauth_params);
        $content = call_user_func_array(array($this->http, strtolower($method)), array($url, $params, $this->http_options));
        // reset http header and options to prepare for the next request
        $this->http->resetHeader();
        // return request return value
        return $content;
    }
1059949
protected function authenticate($key, $secret) {
		$token = $this->cache->get('Twitter_Application_Bearer_Token');
		if ($token === FALSE) {
			$bearerTokenCredentials = base64_encode(urlencode($key) . ':' . urlencode($secret));

			$uri = new Uri('https://api.twitter.com/oauth2/token');
			$httpRequest = Request::create($uri, 'POST');
			$httpRequest->setContent(http_build_query(array('grant_type' => 'client_credentials')));
			$httpRequest->setHeader('Authorization', 'Basic ' . $bearerTokenCredentials);
			$httpRequest->setHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');

			$response = $this->requestEngine->sendRequest($httpRequest);
			$authenticationReponseBody = json_decode($response->getContent(), TRUE);
			if (!isset($authenticationReponseBody['token_type']) || $authenticationReponseBody['token_type'] !== 'bearer' || !isset($authenticationReponseBody['access_token'])) {
				throw new \Exception('Invalid authentication answer! Your application could not authenticate with Twitter.', 1424698337);
			}

			$token = $authenticationReponseBody['access_token'];
			$this->cache->set('Twitter_Application_Bearer_Token', $token);
		}

		return $token;
	}
1110890
function OAuthToken( key, secret ){
    if( ! key || ! secret ){
        throw new Error('OAuthToken params must not be empty');
    }
    this.key = key;
    this.secret = secret;
}
706236
def decode_token(self, token):
        """"""
        key = current_app.secret_key
        if key is None:
            if current_app.debug:
                current_app.logger.debug("app.secret_key not set")
            return None
        try:
            return jwt.decode(
                token, key,
                algorithms=[self.config["algorithm"]],
                options={'require_exp': True}
            )
        except jwt.InvalidTokenError:
            return None
72569
static function verify($secret,$response=NULL) {
		$fw=\Base::instance();
		if (!isset($response))
			$response=$fw->{'POST.g-recaptcha-response'};
		if (!$response)
			return FALSE;
		$web=\Web::instance();
		$out=$web->request(self::URL_Recaptcha,[
			'method'=>'POST',
			'content'=>http_build_query([
				'secret'=>$secret,
				'response'=>$response,
				'remoteip'=>$fw->IP
			]),
		]);
		return isset($out['body']) &&
			($json=json_decode($out['body'],TRUE)) &&
			isset($json['success']) && $json['success'];
	}
183398
public function validateRandomSessionToken(string $token): bool
    {
        if (!isset($this->session[$this->name])) {
            return false;
        }

        return $token == $this->session[$this->name];
    }
546706
public static function isSupportedSigningAlgorithm($algorithm)
    {
        return in_array(
            $algorithm,
            array(
                XMLSecurityKey::RSA_1_5,
                XMLSecurityKey::RSA_SHA1,
                XMLSecurityKey::RSA_SHA256,
                XMLSecurityKey::RSA_SHA384,
                XMLSecurityKey::RSA_SHA512
            )
        );
    }
370610
public static function decrypt(string $data, string $secret='', string $algorithm='AES-256-CBC')
  {
    # if AES we extract the 16 bytes in the beginning as the IV
    if ( strtoupper(substr($algorithm,0,3))==='AES' ) {
      $encoded  = base64_decode($data);
      $iv       = substr($encoded,0,16);
      $encoded  = substr($encoded,16);
    } else {
      $encoded = $data;
      $iv = '';
    }

    # If no secret provided, use the one in config
    if (empty($secret))
      $secret = config()->get('application.secret');

    # Decrypt
    $result = openssl_decrypt($encoded,$algorithm,$secret,0,$iv);

    return $result;
  }
748289
public function validateHash(string $hash, string $algorithm = 'sha256', bool $raw = false): bool
	{
		return hash_equals($hash, $this->getHash($algorithm, $raw));
	}
861920
public function hotp($secret, $counter)
    {
        if (!is_numeric($counter) || $counter < 0) {
            throw new \InvalidArgumentException('Invalid counter supplied');
        }
        
        $hash = hash_hmac(
                $this->algorithm,
                $this->getBinaryCounter($counter),
                $secret,
                true
        );
    
        return str_pad($this->truncate($hash), $this->digits, '0', STR_PAD_LEFT);
    }
1372491
public function get_access_token($token, $secret, $verifier='') {
        $this->sign_secret = $this->consumer_secret.'&'.$secret;
        $params = $this->prepare_oauth_parameters($this->access_token_api, array('oauth_token'=>$token, 'oauth_verifier'=>$verifier), 'POST');
        $this->setup_oauth_http_header($params);
        // Should never send the callback in this request.
        unset($params['oauth_callback']);
        $content = $this->http->post($this->access_token_api, $params, $this->http_options);
        $keys = $this->parse_result($content);

        if (empty($keys['oauth_token']) || empty($keys['oauth_token_secret'])) {
            throw new moodle_exception('oauth1accesstoken', 'core_error', '', null, $content);
        }

        $this->set_access_token($keys['oauth_token'], $keys['oauth_token_secret']);
        return $keys;
    }
431217
public function verify($token, $identifier = null)
    {
        $identifier = ($identifier !== null) ? $identifier : $this->identifier;

        // Throw error for empty token or empty identifier, because the server will not handle this
        if (empty($token)) {
            throw new BackupCode\EmptyTokenException();
        }
        if (empty($identifier)) {
            throw new BackupCode\EmptyIdentifierException();
        }

        $this->sendApiCall(self::ACTION_RETRIEVE, sprintf('%s/%s?token=%s', $this->getCreateUrl(), urlencode($identifier), $token));
    }
919993
public static function validate($post, $configuration) {
		// TODO move constants to global configuration
		$log = new Logger ( $configuration->log_dir, $configuration->log_level );
		$token = $configuration->token;
		$result = false;
		if ($token != null && isset ( $post ['token'] )) {
			if (strcmp ( $token, $post ['token'] ) == 0)
				$result = true;
		}
		return $result;
	}
1349165
public function validateToken(JwtToken $token)
    {
        $this->validateHeader($token->getHeader());
        $this->validateClaims($token->getClaims());

        if (!$this->secretLoader) {
            $token->validateSignature($this->secret, $this->getSignatureValidator());

            return;
        }
        $token->validateSignature($this->secretLoader->load($token), $this->getSignatureValidator());
    }
1255228
public static function parser(string $token, string $secret): Parse
    {
        $jwt = new Jwt($token, $secret);

        return new Parse($jwt, new Validate(), new Encode());
    }