Skip to content

Instantly share code, notes, and snippets.

@programmarchy
Created July 15, 2016 00:39
Show Gist options
  • Save programmarchy/d85eed316bad4d81093bf22b574e45ec to your computer and use it in GitHub Desktop.
Save programmarchy/d85eed316bad4d81093bf22b574e45ec to your computer and use it in GitHub Desktop.
Extracts ember auth info from localStorage
<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