Embed a Dashboard Using a Generated Snippet and OAuth Access Tokens
Logi Analytics recommends using Trusted Access for all embed-related workflows.
To embed a dashboard into your application using OAuth Access Tokens:
Verify that the embedded dashboard prerequisites have been met. See Embedded Component Prerequisites.
Use the Composer API to register your host application as an OAuth client of your Composer instance and obtain a client ID and client secret. See Register an OAuth Client.
The response from this API request includes the client ID, client name, and client secret, as well as the expiration time (in seconds).
API documentation is provided with your Composer installation at this link:
https://<composer-URL>/composer/swagger-ui.html
.Add a
window.logiGetToken
function to your host application to obtain an access token and expiration for a user session when a user uses the embedded dashboard.The
logiGetToken
function must communicate with a server you have created (see Step 4) that takes information about the active user session (the user name) and contacts Composer to generate an access token for the user session. This is anasync
function that returns a promise. For example:window.logiGetToken = async function logiGetToken() { return { access_token: "<access_token>", expires_in: <seconds> }; };
Where
<access-token>
is the OAuth access token you obtain from your server and<seconds>
is the number of seconds until the token expires (also obtained from your server).Implement your own server-side code that accepts requests generated by the
window.logiGetToken
function and, in turn, makes requests to Composer to generate a token for the specific user session of a user using the embedded dashboard. Your server-side code should respond to these requests with a token and expiration information.To obtain an access token for the user session, your server must submit the following API request to Composer:
POST <yourserver>/<yourpath>/api/oauth2/token?username=<username>
Where:
<yourserver>
is replaced with the DNS or IP address of your Composer instance, with any necessary port number<yourpath>
is replaced with your Composer server's path, usually composer or zoomdata<username>
is replaced with the appropriate user name (from the user session information). User names must be specified in all lowercase.
Be sure to:
Use the content type
application/vnd.composer.v2+json
.Use basic auth and provide the supervisor ID and password.
Provide the required JSON object in the body of the request. Typically, the request body's JSON object includes these properties:
{
"clientId": "<string>",
"clientName": "<name>" }Where:
clientId
specifies the client ID you obtained for your application in Step 2.clientname
specifies the client name you used for your application in Step 2.
The response from this request provides a token value and expiration information:
{ "tokenValue": "<token>", "expiration": "<expiration-date-time>" }
Where:
Substitution Description <tokenValue>
The OAuth access token you need. This value will be used in the access_token
setting of thewindow.logiGetToken
function in Step 3.<expiration>
The expiration UTC date of the access token. Your server or host application must convert this UTC date to the number of remaining seconds available for the access token. This value will be used in the expires_in
setting of thewindow.logiGetToken
function in Step 3.For example:
{ "tokenValue": "57ce7de3-7b15-4677-bc7e-4d73cec660b2", "expiration": "2020-07-19 03:10:16.063" }
Generate and copy the embeddable snippet for your dashboard. See Generate an Embeddable Dashboard HTML Snippet.
Insert the generated snippet into your host application using the appropriate
script
tag, configured to show the embedded dashboard in the appropriate HTML element.
Comments
0 comments
Please sign in to leave a comment.