<div dir="ltr">Thanks OJ, this makes sense</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 29, 2013 at 7:49 PM, OJ Reeves <span dir="ltr"><<a href="mailto:oj@buffered.io" target="_blank">oj@buffered.io</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Alex,<div><br></div><div>I don't believe that sending cookies in the response when in the websocket handler will result in a cookie being set in the browser. The way I handle this is sending the cookie in the response outside of the websocket handler.</div>
<div><br></div><div>That is, I have a "home" and "websocket" resource. I deal with authentication in the usual HTTP/REST way in the "home" resource, and only when the user is authenticated do I set up a websocket for communications via the "websocket" resource. My websocket_init function in the "websocket" resource is able to check for the authentication cookie, and if the user isn't auth'd then the websocket connection is killed.</div>
<div><br></div><div>I haven't tried (or considered) setting up and sending out an auth cookie via websocket_init, I don't feel that it makes much sense.</div><div><br></div><div>Hope that helps in some way.</div>
<div>
OJ<br><br><br><div class="gmail_quote"><div><div class="h5">On Wed, Jan 30, 2013 at 10:36 AM, Alex Babkin <span dir="ltr"><<a href="mailto:ababkin@gmail.com" target="_blank">ababkin@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
<div dir="ltr">Hi all<div><br></div><div>Imagine an auth protocol over a websocket: client sends credentials, server responds with either success or failure. If success, it should set some persistent state so if the user reloads the page, the session will continue until either logout or some timeout</div>
<div><br></div><div>I'm trying to set a cookie from a websocket handler, such that after a page reload, in the websocket handler init i can try to read back the cookie and check for it's validity and if valid, resume the session without the user needing to login again</div>
<div><br></div><div>here is some code i tried with no success, i.e upon reload, the cookie is no longer there (or perhaps is never getting set by the handler to begin with)</div><div><br></div><div>
<div>websocket_handle({text, Input}, Req, State) -></div><div> lager:debug("stream received ~s", [Input]),</div><div> Req2 = cowboy_req:set_resp_cookie(<br></div><div> <<"auth">>,</div>
<div> [<<"test">>],</div><div> [{max_age, 600}, {path, "/"}, {secure, true}, {http_only, true}],</div><div> Req</div><div> ),</div><div> {ok, Req3} = cowboy_req:reply(200, Req2),<br>
</div><div> {ok, Req3, NewState}.<br></div></div><div><br></div><div>... or alternatively:</div><div><br></div><div><div>{reply, {text, Output}, Req2, NewState}.</div><div><br></div></div><div>
as the last line</div><div><br></div><div>after the socket terminates and i try to reload page i do this in websocket init:</div><div><br></div><div>{Cookie, Req2} = cowboy_req:cookie(<<"auth">>, Req),<br>
</div><div><div><br></div><div>and there are no cookies</div><div><br></div><div><br></div><div>any ideas what i'm doing wrong?</div><div>is this even possible with websocket or do i pretty much have to have a dedicated regular http roundtrip to set the auth cookie?</div>
<div><br></div><div>Thanks</div></div><div><br></div><div><br></div></div>
<br></div></div>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><br>OJ Reeves<div><a href="tel:%2B61%20431%20952%20586" value="+61431952586" target="_blank">+61 431 952 586</a><br>
<a href="http://buffered.io/" target="_blank">http://buffered.io/</a></div>
</font></span></div>
</blockquote></div><br></div>