我从安全角度理解httponly标志的概念,该标志用于设置Cookie响应头的值并防止XSS攻击。
我不明白的是,ServiceStack对保存BeareToken的“ss tok”cookie做了什么。
根据
ServiceStack documentation
我可以通过发出无状态JWT Cookie将其转换为无状态会话,如下所示:
var authResponse = client.Send(new Authenticate {
provider = "credentials",
UserName = username,
Password = password,
UseTokenCookie = true
});
UseTokenCookie设置为true。并且在成功验证后创建仅HTTPS的“ss tok”cookie。
然而,我似乎不能用这个名为“ss tok”的令牌cookie做任何事情。显然,我无法用Javascript检索它,而且我似乎无法将其发送进来
JsonServiceClient
请求。
我的ServiceStack资源微服务在任何安全请求中都不会收到“ss tok”的值。我必须为任何安全请求明确设置bearerToken。
我必须明确地将BeareToken或refreshToken传递给我的
JsonServiceClient
如
ServiceStack documentation on this matter
.
我一定做错什么了,
I thought this documentation
是我缺少的部分,这里的代码:
var client = new JsonServiceClient(baseUrl);
client.SetCookie("ss-tok", jwtToken);
但这段代码实际上毫无意义,因为“ss tok”的值没有被发送到我的资源微服务,我必须明确设置bearerToken值,就像我前面说的那样:
var client = new JsonServiceClient(baseUrl);
client.bearerToken = jwtToken;
这意味着我必须将jwtToken存储在我自己的cookie值中,因为我的应用程序需要在应用程序的不同区域创建多个JsonServiceClient实例。