Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ServiceStack authentication use cookies rather than a sessionId header?

Tags:

servicestack

I'm loving using ServiceStack, but one question has come up from a colleague that I cannot answer. The Authentication mechanism sets a ss-pid and an ss-id cookie, which is explained here: https://github.com/ServiceStack/ServiceStack/wiki/Sessions

When trying to access a restricted resource, these cookies need to be provided, otherwise you'll receive a 401 Not Authorized result.

My question is this. Why use a cookie rather than a custom HTTP header value that includes the sessionId or equivalent cookie values? Is it because the cookie inherently has its own mechanism to maintain expiration? What were the design decisions undelying the use of cookies over HTTP headers?

like image 442
Rebecca Avatar asked Feb 17 '23 03:02

Rebecca


1 Answers

HTTP Cookies are inherently sticky and is the most appropriate way for maintaining sessions over HTTP. After the server instructs the client to add a Cookie, every subsequent request that the client makes back to the same server will also retain that cookie - this what enables the Client/Server session.

like image 103
mythz Avatar answered Apr 26 '23 14:04

mythz