|
|
|
|
|
by different_sort
2112 days ago
|
|
Storing tokens in cookies would be against the spec wouldn’t it? I’m not putting rfc6749 on some sort of pedestal, but it clearly states that the tokens are in the response body and not set in cookies. Do you have any examples of Authorization servers in the wild doing this or front end SDKs that work with that? I’m very curious, I’m doing an SPA security research project at work and I’m very interested in these stories and learning more. I’ve seen some folks do refresh in an httponly cookie, and Access in the js space. I’ve seen another example (auth0) put the refresh token in a web worker and access token accessible in js. And I’ve seen things like msal.js just say F it and make them all accessible to js. |
|
Sorry, I was wrong. According to the spec you definitely have to send the access token back in the response body[0].
However, a client can store them as cookies (or, as you mention, other places, such as a service worker[1]). This is useful if the client is a single page application (SPA), which may need to present the access token to other resource servers.
RFC 6750 has something to say about how to store the bearer token [2]:
> Don't store bearer tokens in cookies: Implementations MUST NOT store bearer tokens within cookies that can be sent in the clear (which is the default transmission mode for cookies). Implementations that do store bearer tokens in cookies MUST take precautions against cross-site request forgery.
So, I apologize. The authorization server wouldn't send the access token as a cookie. Instead, there'd be a server side proxy which would request the token and then send it down as a secure cookie. Again, best practice would be to keep the access token on the server side proxy and just send a session id down to the client, but that sometimes doesn't work. Here is a diagram illustrating that path (with the 'store' entity acting as the proxy mentioned above)[3].
0: https://tools.ietf.org/html/rfc6749#section-5.1
1: https://gitlab.com/jimdigriz/oauth2-worker
2: https://tools.ietf.org/html/rfc6750#page-13
3: https://fusionauth.io/learn/expert-advice/authentication/web...