public function json($data = "")
 {
     Token::key();
     header("Content-Type: application/json; charset=utf-8");
     $this->result = new Result($data, Token::encode());
     echo json_encode($this->result);
 }
Exemple #2
0
 /**
  * @covers Token::decode
  */
 public function testDecodeExpired()
 {
     //set timestamp for checking expiration
     $token = new Token();
     $token->payload = new stdClass();
     $token->encode(0);
     sleep(1);
     //simulate receiving of a token value to decode
     $this->object->value = $token->value;
     $this->assertFalse($this->object->decode(), 'Token should not be decoded if expired');
 }
Exemple #3
0
 /**
  * Generate a token for API usage.
  *
  * @return string Token generated
  */
 public function generateToken($payload)
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Token.php';
     require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Configuration.php';
     $configuration = new Configuration();
     $token = new Token($configuration->get('hashKey'));
     $token->payload = $payload;
     $token->encode();
     $result = new stdClass();
     $result->token = $token->value;
     //return the token
     return $result;
 }