{"id":8775,"date":"2021-05-13T17:09:42","date_gmt":"2021-05-13T09:09:42","guid":{"rendered":"https:\/\/www.kiloview.com\/en\/support\/docs\/ndi-device-http-apiversion-1-0\/security-rules\/"},"modified":"2021-05-13T17:09:42","modified_gmt":"2021-05-13T09:09:42","slug":"security-rules","status":"publish","type":"docs","link":"https:\/\/www.kiloview.com\/en\/docs\/ndi-device-http-apiversion-1-0\/security-rules\/","title":{"rendered":"Security Rules"},"content":{"rendered":"<p>To ensure network security, the HTTP API requires you to perform security authorization according to the security rules described in this section, otherwise the device will reject your HTTP request.<\/p>\n<blockquote>\n<p>Unless otherwise specified, we strongly recommend that you use <strong>HTTPS<\/strong> (not HTTP) to execute the HTTP API. HTTP may bring you hidden security risks of leaking sensitive information (such as user name and password).<\/p>\n<\/blockquote>\n<h2>Authorization<\/h2>\n<p>Before you use any of the HTTP APIs described in this document, you must first obtain authorization to use the HTTP API.<\/p>\n<p>The mechanism of NDI Devices authorization is briefly described as follows:<\/p>\n<p>1) First of all, you need to provide a valid username and password. NDI Device needs to verify the validity of your username and password;<\/p>\n<p>2) If your username and password are verified correctly, NDI Device will generate a random pair of <strong>Session ID<\/strong> and <strong>Authorization Token<\/strong> for you and return it to you in the response.<\/p>\n<p>3) You must record the pair of Session ID and Authorization Token. In each of your next HTTP API requests, you must pass the Session ID and Authorization Token in the HTTP request headers or parameters. There are three alternative delivery methods:<\/p>\n<ul>\n<li>Through HTTP <strong>GET \/ POST<\/strong> <strong>parameters<\/strong>;<\/li>\n<li>Through the HTTP <strong>Headers fields<\/strong>;<\/li>\n<li>Through HTTP <strong>cookies<\/strong>. <\/li>\n<\/ul>\n<p>Authorization is also an <strong>HTTP API<\/strong> itself, but it differs from other APIs in that it does not check and verify the Session ID and Authorization Token, but generates the Session ID for you by checking the username and password you submitted And Authorization Token.<\/p>\n<hr \/>\n<h4>API URL<\/h4>\n<p>\u200b   <strong>\/api\/v1\/user\/authorize<\/strong><\/p>\n<h4>Request<\/h4>\n<p>\u200b   Method: <strong>GET\/POST<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>Parameter<\/th>\n<th>Value<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>username<\/td>\n<td><strong>[STRING]<\/strong> ,<strong>Required<\/strong><\/td>\n<td>A valid username to request authorization<\/td>\n<\/tr>\n<tr>\n<td>password<\/td>\n<td><strong>[STRING]<\/strong> ,<strong>Required<\/strong><\/td>\n<td>The password of the authorized user<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>Response<\/h4>\n<p><strong>Format (Example) : <\/strong><\/p>\n<pre><code class=\"language-json\">{\n    &quot;result&quot;: &quot;ok&quot;,\n    &quot;data&quot;: {\n        &quot;session&quot;: &quot;559dee0bd779a894618d6e044c35a3fc&quot;,\n        &quot;token&quot;: &quot;4345cd7b092d762bd4a646a98aa9f8ff&quot;\n    }\n}<\/code><\/pre>\n<p><strong>Data field description: <\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>Field<\/th>\n<th>Value<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>session<\/td>\n<td><strong>[STRING]<\/strong><\/td>\n<td>Random Session ID <br \/>The Session ID and Authorization Token will expire within <strong>10 minutes<\/strong> after <strong>you do not have any HTTP API operations<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>token<\/td>\n<td><strong>[STRING]<\/strong><\/td>\n<td>Random Authorization Token <br \/>You should record the value of session &amp; token and pass these two values in other subsequent HTTP API requests.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Some  advices: <\/strong><\/p>\n<blockquote>\n<p>1) <strong>Remind you!<\/strong> It is best not to use the built-in administrator user &quot;admin&quot; for API authorization, which will have serious security risks! You can create other users in the Web UI of NDI Devices and use these users to perform HTTP API requests.<\/p>\n<p>2) Use HTTPS instead of HTTP to request authorization, otherwise you risk to leak your username and password!<\/p>\n<\/blockquote>\n<hr \/>\n<h2>Pass Session ID and Authorization Token in HTTP API request<\/h2>\n<p>If you request authorization according to the method described in 2.1, you will get the Session ID and Authorization Token generated by NDI Device for you. Next, you request any other <strong>HTTP API <\/strong>, NDI Device will need to verify that your Session ID and Authorization Token are legal. If you do not provide the Session ID and Authorization Token, or if you provide an illegal value, your HTTP API request will return the following error (example):<\/p>\n<pre><code class=\"language-json\">{\n    &quot;result&quot;: &quot;auth-failed&quot;,\n    &quot;msg&quot;: &quot;...error message...&quot;\n}<\/code><\/pre>\n<p>There are three ways to pass Session ID and Authorization Token:<\/p>\n<h4>A. [Recommended method] Pass through HTTP Request Headers<\/h4>\n<p>In HTTP Request Headers, add <strong>API-Session<\/strong> Header field to indicate Session ID, and <strong>API-Token<\/strong> Header field to indicate Authorization Token. E.g:<\/p>\n<pre><code class=\"language-http\">POST \/api\/v1\/your\/api HTTP\/1.1\n...\nAPI-Session: 559dee0bd779a894618d6e044c35a3fc\nAPI-Token: 4345cd7b092d762bd4a646a98aa9f8ff\n...\n\n&lt;BODY&gt;<\/code><\/pre>\n<p>If curl is used for testing, the command is as follows:<\/p>\n<pre><code class=\"language-shell\">$ curl -H &#039;API-Session: 4345cd7b092d762bd4a646a98aa9f8ff&#039; -H &#039;API-Token: 4345cd7b092d762bd4a646a98aa9f8ff&#039; https:\/\/192.168.100.168\/api\/v1\/your\/api<\/code><\/pre>\n<h4>B. Pass through cookies<\/h4>\n<p>Pass the Session ID through the HTTP Cookie field <strong>session<\/strong> and the Authorization Token through the field <strong>token<\/strong>.  E.g:<\/p>\n<pre><code class=\"language-http\">POST \/api\/v1\/your\/api HTTP\/1.1\n...\nCookie: session=4345cd7b092d762bd4a646a98aa9f8ff;token=4345cd7b092d762bd4a646a98aa9f8ff\n...\n\n&lt;BODY&gt;<\/code><\/pre>\n<p>If curl is used for testing, the command is as follows:<\/p>\n<pre><code class=\"language-shell\">$ curl -b &#039;session=4345cd7b092d762bd4a646a98aa9f8ff;token=4345cd7b092d762bd4a646a98aa9f8ff&#039; https:\/\/192.168.100.168\/api\/v1\/your\/api<\/code><\/pre>\n<h4>C. Pass through GET\/POST parameters [not recommended]<\/h4>\n<p>If neither Method A nor Method B is applicable to you, you can also pass the Session ID and Authorization Token through the parameters of GET\/POST. But we  <strong>donot recommend that<\/strong> you use this method, because it will lessen the standardization of HTTP API parameters, making the parameters of the HTTP API seem confusing.<\/p>\n<p>When it really necessary, you can pass <strong>api-session<\/strong> as the Session ID and <strong>api-token<\/strong> as the Authorization Token in the HTTP GET \/ POST parameters. E.g:<\/p>\n<pre><code class=\"language-http\">https:\/\/&lt;device-ip&gt;\/api\/v1\/your\/api?api-session=4345cd7b092d762bd4a646a98aa9f8ff&amp;api-token=4345cd7b092d762bd4a646a98aa9f8ff<\/code><\/pre>\n","protected":false},"featured_media":0,"parent":48319,"menu_order":1,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-8775","docs","type-docs","status-publish","hentry"],"acf":[],"aioseo_notices":[],"comment_count":0,"_links":{"self":[{"href":"https:\/\/www.kiloview.com\/en\/wp-json\/wp\/v2\/docs\/8775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kiloview.com\/en\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.kiloview.com\/en\/wp-json\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kiloview.com\/en\/wp-json\/wp\/v2\/comments?post=8775"}],"version-history":[{"count":0,"href":"https:\/\/www.kiloview.com\/en\/wp-json\/wp\/v2\/docs\/8775\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.kiloview.com\/en\/wp-json\/wp\/v2\/docs\/48319"}],"next":[{"title":"Status and switching of encoding and decoding modes","link":"https:\/\/www.kiloview.com\/en\/docs\/ndi-device-http-apiversion-1-0\/status-and-switching-of-encoding-and-decoding-modes\/","href":"https:\/\/www.kiloview.com\/en\/wp-json\/wp\/v2\/docs\/8777"}],"prev":[{"title":"Basic Rules","link":"https:\/\/www.kiloview.com\/en\/docs\/ndi-device-http-apiversion-1-0\/basic-rules\/","href":"https:\/\/www.kiloview.com\/en\/wp-json\/wp\/v2\/docs\/8772"}],"wp:attachment":[{"href":"https:\/\/www.kiloview.com\/en\/wp-json\/wp\/v2\/media?parent=8775"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.kiloview.com\/en\/wp-json\/wp\/v2\/doc_tag?post=8775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}