Created
September 12, 2020 18:41
-
-
Save alsmola/15ec1d5c86105e5a17bfdc3af37d8186 to your computer and use it in GitHub Desktop.
Chrome extension to use AWS IoT Credentials Endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
chrome.runtime.onMessage.addListener( | |
function (request, sender, sendResponse) { | |
if (request.contentScriptQuery == "getCredentials") { | |
const url = "https://{credentials-endpoint}.credentials.iot.us-east-1.amazonaws.com/role-aliases/chromeiot/credentials"; | |
const params = { headers: { "x-amzn-iot-thingname": "{thingName}" } } | |
fetch(url, params) | |
.then(response => response.json()) | |
.then(data => sendResponse(data.credentials)); | |
} | |
return true; | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome.runtime.sendMessage({contentScriptQuery: "getCredentials"}, function(credentials) { | |
document.getElementById("accessKeyID").innerText = credentials.accessKeyId; | |
document.getElementById("secretAccessKey").innerText = credentials.secretAccessKey; | |
document.getElementById("sessionToken").innerText = credentials.sessionToken; | |
document.getElementById("expiration").innerText = credentials.expiration; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
</head> | |
<body> | |
<div id="accessKeyID"></div> | |
<div id="secretAccessKey"></div> | |
<div id="sessionToken"></div> | |
<div id="expiration"></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Chrome IOT", | |
"version": "1.0", | |
"description": "Get AWS IAM creds via a certificate", | |
"background": { | |
"scripts": ["background.js"], | |
"persistent": false | |
}, | |
"content_scripts": [ | |
{ | |
"matches": ["https://{your-domain}.com/*"], | |
"js": ["contentScript.js"] | |
} | |
], | |
"permissions": [ | |
"activeTab", | |
"https://{credentials-endpoint}.credentials.iot.us-east-1.amazonaws.com/" | |
], | |
"manifest_version": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment