/**
  * Spawns a one-off instance and hits the Account API endpoint to
  * validate the API key provided is valid and active. Returns true
  * if the key is valid and can be used, false on failure.
  *
  * @param string $key The DiffBot token to use with all requests to the API.
  * @return bool True when the token is found to be valid and active, false on any failure.
  */
 public static function validate_key($key)
 {
     if (empty($key)) {
         return false;
     }
     try {
         $bot = new static($key);
     } catch (\Exception $e) {
         return false;
     }
     $account = $bot->account();
     return 'active' === $account['status'];
 }
Example #2
0
File: Oath.php Project: khooz/oath
 /**
  * Default constructor
  *
  * @param BaseConverterInterface $baseConverter Converter
  * @param string                 $type			OTP type
  * @param string                 $issuer		Issuer
  * @param string                 $account		Account
  * @param string                 $domain		Domain
  * @param string                 $qrURL			Base url for qr-code generator
  */
 public function __construct(BaseConverterInterface $baseConverter, $type = OATH_TOTP, $issuer = '', $account = '', $domain = '', $qrURL = 'https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=')
 {
     static::$converter = $baseConverter;
     static::$type = $type;
     static::$issuer = $issuer;
     static::$account = $account;
     static::$domain = $domain;
     static::$qrURL = $qrURL;
     //static::$secret = static::$Secret();
 }