Prepopulate session key for all REST calls on IO Docs page #126

Allblues opened this Issue Sep 25, 2013 · 3 comments


None yet
3 participants

I have a REST API that has a /login call where you provide an OAuth 2 access_token as a query parameter and you get back a session key. Each of the subsequent calls requires that session key as either a query parameter, a header, or a browser cookie. I'm wondering if there's a simple way to prepopulate the session key into the requests for all of my API methods. It would be great if the session cookie would be used automatically for each call, but it isn't by default. Is there a way to configure app.js so that IO Docs stores my session cookie for all requests?


AlekSi commented Mar 19, 2014



mansilladev commented Mar 25, 2014

So, just to clear this up, are you saying that every time you hit "Try It" (execute an API call), you want the session_key (that was acquired during the /login method) to be passed as a query parameter?

If so, you could make session_key a query parameter field for each method. And whenever a user uses the /login call on I/O Docs, you can use JavaScript magic to grep out the session_key value from the payload, and stuff it into each session_key parameter in I/O Docs.

Let me know if I'm grokking your issue correctly.


mansilladev commented Mar 28, 2014

So, from a pure JS perspective that you can put into action now -- you can try something like this.. where post AJAX success, we look for cookie value in xhr.responseText. Of course, it could use some tuning for your environment, but I think you'll get the general utility out of it.

jQuery(document).ajaxSuccess(function(data,xhr,settings) {
    // Raw responseText from xhr object
    var responseText = jQuery.parseJSON(xhr.responseText);

    // Pull out authToken which is inside the responseText.responseBody
    var cookieVal = jQuery.parseJSON(responseText.responseBody).cookieKeyname;

    // For each DOM element that matches the name params[x-auth-token],
    // replace the value with authToken
        .each(function() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment