Created
March 22, 2016 21:11
-
-
Save stegel/9b0b2b4858532df4e7c8 to your computer and use it in GitHub Desktop.
How to get session token on a ui page with direct=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
<!--- In a ui page --> | |
<!-- this will get the token on the server side and set it to a client-side javascript variable. | |
<g:evaluate object="true"> | |
var g_ck = gs.getSessionToken(); | |
</g:evaluate> | |
<script> | |
window.g_ck = "$[g_ck]"; | |
</script> | |
<!-- In your AngularJS config, you can set the token as a default $httpProvider header --> | |
<!-- This isn't good if you are making $http calls to other endpoints besides SN --> | |
angular.module("app").run(function ($http) { | |
$http.defaults.headers.get = { | |
'X-UserToken' : window.g_ck | |
}; | |
}); | |
<!-- In a single $http call, you can specify the token in the config options of the call --> | |
$http.get("url",{ headers : { "X-UserToken" : window.g_ck}}).then(function(response, result){}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment