{"id":146,"date":"2018-04-02T11:07:06","date_gmt":"2018-04-02T11:07:06","guid":{"rendered":"https:\/\/html5-chat.com\/blog\/?p=146"},"modified":"2023-07-28T18:13:01","modified_gmt":"2023-07-28T18:13:01","slug":"jwt-a-quicker-and-simpler-version-using-the-html5-service","status":"publish","type":"post","link":"https:\/\/html5-chat.com\/blog\/jwt-a-quicker-and-simpler-version-using-the-html5-service\/","title":{"rendered":"JWT: a quicker and simpler version using the HTML5 service"},"content":{"rendered":"<p>Here is a quicker and simpler version of integrating&nbsp; HTML5 chat into an existing website than the <a href=\"https:\/\/html5-chat.com\/blog\/how-to-secure-pass-user-data-into-html5-chat\/\">JWT version described in that post<\/a><\/p>\n<p>The bottom sample is a PHP sample, but you can easily adapt it to JS or ASP in needed. let assume your <strong>webmasterid = 1050<\/strong><\/p>\n<p><strong>Step 1<\/strong>: you create an array of your user such as:<\/p>\n<pre>$json = json_encode([\n  &nbsp; 'webmasterid' =&gt;'1050',\n    'username'  =&gt;'myUsername',\n    'password'  =&gt;'myChatAccountPassword',\n    'gender'    =&gt;'male',\n    'role'      =&gt;'user',\n    'image'     =&gt;base64_encode('https:\/\/html5-chat.com\/img\/malecostume.svg'),\n    'profile'   =&gt;'https:\/\/monsite.com\/profile\/myUserername',\n    'birthyear'=&gt;1970\n    ]\n);<\/pre>\n<p><strong>Step 2<\/strong> : you encode it using the html5 JWT online service<\/p>\n<pre class=\"prettyprint\">$encoded = file_get_contents(\"https:\/\/jwt.html5-chat.com\/protect\/\".base64_encode($json));<\/pre>\n<p><strong>Step 3<\/strong> : you inject that encoded string into your JS script<\/p>\n<pre class=\"prettyprint\">&lt;script src=\"https:\/\/html5-chat.com\/script\/&lt;?=$<strong>webmasterid<\/strong>?&gt;\/&lt;?=$encoded?&gt;\"&gt;&lt;\/script&gt;<\/pre>\n<p>And that&#8217;s ALL:<\/p>\n<p><a href=\"https:\/\/html5-chat.com\/blog\/new-feature-roles\/\"><strong>role<\/strong> <\/a>: can be admin,&nbsp; user, guest,&nbsp; dj, custom1, custom2, custom3<\/p>\n<p><strong>avatar<\/strong> is the http:\/\/ image of the expected avatar<\/p>\n<p><strong>profile<\/strong>: the link to the user profile (if available)<\/p>\n<p><strong>startRoom<\/strong> : the id of the room where to start in (roomid is an integer number)<\/p>\n<p>Replace the <strong>webmasterid<\/strong> in script by your script id (webmasterid, a positive integer you can find in your chatadmin panel)<\/p>\n<p>If you want to use JWT on your server, <a href=\"https:\/\/html5-chat.com\/blog\/how-to-secure-pass-user-data-into-html5-chat\/\">please refer to this post<\/a>.<\/p>\n<pre class=\"prettyprint\">&lt;?php $json = json_encode(['username'=&gt;'myUsername', 'password'=&gt;'myPassword', 'gender'=&gt;'male', 'role'=&gt;'user', 'profile'=&gt;'https:\/\/monsite.com\/profile\/myUserername', 'image'=&gt;'https:\/\/html5-chat.com\/img\/malecostume.svg']);\n$encoded = file_get_contents(\"https:\/\/jwt.html5-chat.com\/protect\/\".base64_encode($json), 'startRoom'=&gt;5);\n?&gt;\n&lt;!doctype html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;title&gt;HTML5 chat&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n\n&lt;div style=\"width: 1024px;height: 800px;\"&gt;\n    &lt;script src=\"https:\/\/html5-chat.com\/script\/xxxxx\/&lt;?=$encoded?&gt;\"&gt;&lt;\/script&gt;\n&lt;\/div&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>Notice: if <a href=\"https:\/\/www.php.net\/manual\/en\/function.file-get-contents.php\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>file_get_contents<\/strong> <\/a>is DISABLED on your hosting, you can use the <a href=\"https:\/\/www.php.net\/manual\/en\/book.curl.php\"><strong>curl<\/strong><\/a><\/p>\n<pre class=\"prettyprint\">$curl=&nbsp;curl_init();\ncurl_setopt_array($curl, array(\n      CURLOPT_RETURNTRANSFER =&gt; 1,\n      CURLOPT_URL =&gt; \"https:\/\/jwt.html5-chat.com\/protect\/\".base64_encode($json)\n));\n$encoded = curl_exec($curl);<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here is a quicker and simpler version of integrating&nbsp; HTML5 chat into an existing website than the JWT version described in that post The bottom sample is a PHP sample, but you can easily adapt it to JS or ASP in needed. let assume your webmasterid = 1050 Step 1: you create an array of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":147,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,2],"tags":[34,33],"class_list":["post-146","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-integration","category-news","tag-encoded","tag-jwt"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/html5-chat.com\/blog\/wp-json\/wp\/v2\/posts\/146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/html5-chat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/html5-chat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/html5-chat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/html5-chat.com\/blog\/wp-json\/wp\/v2\/comments?post=146"}],"version-history":[{"count":25,"href":"https:\/\/html5-chat.com\/blog\/wp-json\/wp\/v2\/posts\/146\/revisions"}],"predecessor-version":[{"id":1459,"href":"https:\/\/html5-chat.com\/blog\/wp-json\/wp\/v2\/posts\/146\/revisions\/1459"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/html5-chat.com\/blog\/wp-json\/wp\/v2\/media\/147"}],"wp:attachment":[{"href":"https:\/\/html5-chat.com\/blog\/wp-json\/wp\/v2\/media?parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/html5-chat.com\/blog\/wp-json\/wp\/v2\/categories?post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/html5-chat.com\/blog\/wp-json\/wp\/v2\/tags?post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}