diff options
author | Naveen Bobbili <nbobbili@amazon.com> | 2018-12-05 14:41:43 -0800 |
---|---|---|
committer | Naveen Bobbili <nbobbili@amazon.com> | 2018-12-06 14:31:57 -0800 |
commit | 4082dd6e354e68a90d1e50953c34cfa36b3d1519 (patch) | |
tree | 5d55434015158137b210f5f6759ed93b6e40c76d /htdocs/binding.js | |
parent | 3c87e5c620dc1273a900cf3a607f0bdbc67f34a5 (diff) |
Code Base Linking based authentication implementationguppy_6.99.4guppy_6.99.3guppy/6.99.4guppy/6.99.36.99.46.99.3ces2019
for Alexa Voice Agent.
Using the VSHL Tester HTML5 app
1. Click Enumerate Agents will show Login With Amazon button
if the low level Alexa voice agent is not authenticated.
2. Clicking Login with Amazon button will start the login
process. A CBL link will be displayed using which the user
can authenticate using Amazon account.
3. The app will automatically fetch the access token
needed by the low-level Alexa Voice Agent and pass it
to it using the setAuthToken exposed by the agent.
Change-Id: I327e9b77a2f296a268530df00804cbef60cf0c3c
Signed-off-by: Naveen Bobbili <nbobbili@amazon.com>
Diffstat (limited to 'htdocs/binding.js')
-rw-r--r-- | htdocs/binding.js | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/htdocs/binding.js b/htdocs/binding.js index c24d62e..7e7439b 100644 --- a/htdocs/binding.js +++ b/htdocs/binding.js @@ -3,6 +3,8 @@ var ws; var evtIdx = 0; var count = 0; +var amazon = new AMAZON(); +var amazonCbl; //********************************************** // Logger @@ -10,7 +12,7 @@ var count = 0; var log = { command: function (api, verb, query) { console.log("subscribe api=" + api + " verb=" + verb + " query=", query); - var question = urlWS + "/" + api + "/" + verb + "?query=" + JSON.stringify(query); + var question = afb.url + "/" + api + "/" + verb + "?query=" + JSON.stringify(query); log._write("question", count + ": " + log.syntaxHighlight(question)); }, @@ -92,6 +94,8 @@ function init(elemID, api, verb, query) { document.getElementById("connected").innerHTML = "Binder WS Active"; document.getElementById("connected").style.background = "lightgreen"; ws.onevent("*", log.event); + // Fetch and render voice agents. + fetchAndRenderVoiceAgents(); } function onabort() { @@ -165,6 +169,24 @@ function addVoiceAgent(containerDiv, voiceAgent, isDefault) { subscribeBtn.innerHTML = 'Subscribe'; agentDiv.appendChild(subscribeBtn); + // Login implementation for Alexa Voice Agent + if (voiceAgent.name == "Alexa") { + amazonCbl = new amazon.cbl(); + if (typeof(Storage) !== "undefined" && + localStorage.getItem("access_token") !== null && + localStorage.getItem("refresh_token") !== null) { + amazonCbl.refreshToken(voiceAgent); + } else { + const loginWithAmazonBtn = document.createElement("button"); + loginWithAmazonBtn.addEventListener('click', (evt) => { + loginWithAmazonBtn.style.visibility = "hidden"; + amazonCbl.login(voiceAgent); + }); + loginWithAmazonBtn.innerHTML = 'Login With Amazon!!'; + agentDiv.appendChild(loginWithAmazonBtn); + } + } + containerDiv.appendChild(agentDiv); } |