public function buildUserAuthToken($userId, $displayName, $expires) { if (!ctype_alnum($userId)) { throw new \InvalidArgumentException("userId must be alphanumeric"); } $token = array("domain" => $this->_name, "user_id" => $userId, "display_name" => $displayName, "expires" => time() + (int) $expires); return JWT::encode($token, $this->_key); }
public function buildCollectionMetaToken($title, $articleId, $url, $options = array()) { if (filter_var($this->_IDNA->encode($url), FILTER_VALIDATE_URL) === false) { throw new \InvalidArgumentException("provided url is not a valid url"); } if (strlen($title) > 255) { throw new \InvalidArgumentException("title length should be under 255 char"); } $collectionMeta = array("url" => $url, "title" => $title, "articleId" => $articleId); if (array_key_exists("type", $options) and !in_array($options["type"], self::$TYPE)) { throw new \InvalidArgumentException("type is not a recognized type. must be in " . implode(",", self::$TYPE)); } return JWT::encode(array_merge($collectionMeta, $options), $this->_key); }