Created
July 15, 2016 00:39
-
-
Save programmarchy/d85eed316bad4d81093bf22b574e45ec to your computer and use it in GitHub Desktop.
Extracts ember auth info from localStorage
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
<pre id="credentials"></pre> | |
<button onClick="javascript:sendRequest()">Send Request</button> | |
<script> | |
function getEmberSessionCredentials() { | |
var data = localStorage['ember_simple_auth:session'] | |
if (!data) { return null } | |
var session = JSON.parse(data) | |
if (!session) { return null } | |
var authenticated = session['authenticated'] | |
if (!authenticated) { return null } | |
return { | |
'key': authenticated['key'], | |
'secret': authenticated['token'] | |
} | |
} | |
function sendRequest() { | |
var req = new XMLHttpRequest() | |
req.open('GET', '?') | |
var credentials = getEmberSessionCredentials() | |
if (credentials) { | |
req.setRequestHeader('X-Auth-Key', credentials.key) | |
req.setRequestHeader('X-Auth-Secret', credentials.secret) | |
} | |
req.send() | |
} | |
document.getElementById('credentials').innerText = | |
JSON.stringify(getEmberSessionCredentials()) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment