<div>I&#39;m looking for a little help working out the logic for dealing with cookies and basic auth in the same request.</div><div><br></div><div>I use a cookie to hold a session ID.  The session is only created for users that log in -- essentially the session ID stores the user object and is used as an authentication token.  It also avoids the slightly expensive login process for every request.  The session is also useful for tracking a series of related requests.  Some state ends up in the session, but we are trying to move away from that.</div>

<div><br></div><div>There&#39;s a /login method used to pass in credentials, and upon successful &quot;log in&quot; is when then cookie gets set.</div><div><br></div><div>I&#39;d like to make basic auth available as an authentication method for API calls.  I&#39;d still like to use cookies for authentication caching and to provide session tracking.</div>

<div><br></div><div>My question is about the logic to make sure that any valid session id provided via the cookie matches the session that was created with the basic auth header.  Or in other words, what happens if the Authorization header changes but the cookies session id does not change?</div>

<div><br></div><div><br></div><div>One option would be to place the Authorization header&#39;s value into the session and if an Authorization header is provided in the request make sure it matches the value in the session, and if not create a new session.</div>

<div><br></div><div>Another option would be to always require the Authorization header and append that to the session ID.  That way if the Authorization header changed the session lookup would fail.</div><div><br></div><div>

<br></div><div>What kind of logic would you implement in this situation?</div><div><br></div><div><br></div><div><br>-- <br>Bill Moseley<br><a href="mailto:moseley@hank.org" target="_blank">moseley@hank.org</a><br>
</div>