Public Pages

Sometimes you may need to create pages that do not require an account to access. For example, you may want to create a special public search page.

 

There are two types of public pages:

  • Public Page No Token: This is a public page with no token in the URL. 
  • Public Page with Token: This is a public page with a token in the URL (hard to guess). This is ideal for account generated access.  Ie: A user wishes to make some data public.
    • These tokens are managed by account admins & are currently stored in the tenant's UP stream on the Medium One platform

Configuring the portal

Before you can use public pages, you must edit the Advanced Config. As a super admin, go to "Developer" > "Advanced Config".

Enable Public Pages

Add "ENABLE_PUBLIC_PAGES": true, to the config dictionary and save. For more information about the advanced config, read our doc Advanced Config.

Specify Public Endpoint Policy

If your public page is making any API calls to the IoT platform, you should use this tag as well. For security, you should only allow public endpoints to read and write data from specific streams or tags. Add the tag "PUBLIC_ENDPOINT_POLICY". The value is a dictionary where the keys are public endpoints and the values are a list of streams and tags allowed to be accessed by that endpoint. 

Example:

"PUBLIC_ENDPOINT_POLICY": {
"public_device_data_by_stream_v2": [
"device_data",
"device_config"
]
}

 

Setting up the page

Tokens

When editing a custom dashboard page, you can select the user role "Public Page Token" or "Public Page No Token". 

No token

If you choose no token, after saving the dashboard, your page is ready to be publicly accessed at the URL https://<PORTAL URL>/public/<PAGE ROUTE>

Token

If you choose token, you must set up another page in order to allow accounts to generate and manage their public tokens.

Here is the sample code for this page:

Name the custom page as you like and be sure to set the access to "Account Admin". When you are within an account (either by switching to account view or by logging in as an account admin), you should be able to access this page and create tokens.

Screen_Shot_2019-12-09_at_4.18.47_PM.png

The public token page URL will have the following format:

https://<PORTAL URL>/token_page/<PAGE ROUTE>/<ACCOUNT ID>/<TOKEN>

 

JavaScript Requirements and Limitations

Public pages do not have access to the same resources as the regular dashboard pages, so you will need to adjust your dashboard code to take this into consideration.

 

Module

You must use the module "Module":

mceclip0.png

Otherwise you will get the following error:

mceclip2.png

 

Custom Services

You are not able to use Custom Services on public pages.

 

Public Endpoints

As mentioned in the "Configuring the portal" section, you must use special Public Endpoints to access the portal API. The endpoints used on regular dashboard pages will not work as they have an added layer of security and are only able to be used by authenticated users.

 

Loading External Scripts

On typical dashboard pages, external scripts are loaded using a custom service.

In order to load external scripts on public pages, use the following sample code:

var scriptId = "ui-scriptloaderservice-0"

var script = document.createElement("script");
script.setAttribute("id", scriptId);
script.type = "text/javascript";
script.onload = function() {
activate()
}

document.getElementsByTagName("head")[0].appendChild(script);
script.src = <SCRIPT URL>


// remove script element when leave page
$scope.$on("$destroy", function() {
var element = document.getElementById(scriptId);
if (element) {
element.parentNode.removeChild(element);
}
});

 

Responsive Pages

To make a public page responsive, add the following to your JS:

// required for responsive pages
var meta = document.createElement("meta")
meta.setAttribute("name", "viewport")
meta.setAttribute("content", "width=device-width, initial-scale=1")
document.getElementsByTagName("head")[0].appendChild(meta)