GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
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?
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?
Let me know if I'm grokking your issue correctly.
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.
// 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