Skip to content

Instantly share code, notes, and snippets.

@eleventigers
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save eleventigers/9178879 to your computer and use it in GitHub Desktop.

Select an option

Save eleventigers/9178879 to your computer and use it in GitHub Desktop.

Revisions

  1. eleventigers revised this gist Feb 23, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cookies.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    To load sessions into the Rendr app I used `connect-redis` from [visionmedia](https://github.com/visionmedia/connect-redis). Whatever I set on req.session will be stored in a Redis store.

    In a custom data-adapter that communicates with our API, I send relevant cookies to through the request method. So for example when my data-adapter tries to authenticate with the API on success it should receive a response with sessions cookies set by Deployed. What I do is I save those cookies into req.session and the next time data-adapter does a request I take them out of the cookie jar and put them on top of the request - Deployed links this request with a session on Rendr in this way. Remember that a custom data-adapter can be augmented by any express middleware that comes before it, whether it sets stuff on req.session or else.
    In a custom data-adapter that communicates with our API, I send relevant cookies through the request method. So for example when my data-adapter tries to authenticate with the API on success it should receive a response with sessions cookies set by Deployed. What I do is I save those cookies into req.session and the next time data-adapter does a request I take them out of the cookie jar and put them on top of the request - Deployed links this request with a session on Rendr in this way. Remember that a custom data-adapter can be augmented by any express middleware that comes before it, whether it sets stuff on req.session or else.

    This is what I wrote when I needed to pass cookies around, it probably sucks but hey it worked at that time:

  2. eleventigers created this gist Feb 23, 2014.
    25 changes: 25 additions & 0 deletions cookies.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    To load sessions into the Rendr app I used `connect-redis` from [visionmedia](https://github.com/visionmedia/connect-redis). Whatever I set on req.session will be stored in a Redis store.

    In a custom data-adapter that communicates with our API, I send relevant cookies to through the request method. So for example when my data-adapter tries to authenticate with the API on success it should receive a response with sessions cookies set by Deployed. What I do is I save those cookies into req.session and the next time data-adapter does a request I take them out of the cookie jar and put them on top of the request - Deployed links this request with a session on Rendr in this way. Remember that a custom data-adapter can be augmented by any express middleware that comes before it, whether it sets stuff on req.session or else.

    This is what I wrote when I needed to pass cookies around, it probably sucks but hey it worked at that time:

    if(req.session){
    jar = request.jar();
    if(req.session[sessCookiePath]){
    jar.cookies = req.session[sessCookiePath];
    }
    cookieString = _.map(_.filter(jar.cookies, function(c){return !!(c.name);}), function (c) {
    return c.name + "=" + c.value;
    }).join("; ");
    api.headers.cookie = cookieString;
    api.jar = jar;
    }

    Once I get response from the API I do:

    req.session[sessCookiePath] = _.clone(jar.cookies);

    I guess a better way would be not to store every cookie returned from the API but just one that is used to authenticate with it. Your session could have a field with `apiSessionAuthToken` or similar and you send it when needed.