【发布时间】:2018-11-22 22:35:46
【问题描述】:
我一直在看很多教程,他们总是说 asp.net Core cookie authentication 用户在具有会话 ID 的 Session 对象中保持服务器端的身份验证。但是在 CookieAuthenticationHandler.cs SignInAsync 仅在存在 Options.SessionStore 时保存 sessionId ,如果不是这种情况,我想在每个请求中发送所有加密声明而不需要将所有数据存储到 Session object (如令牌认证)。所以,请有人向我澄清一下。
CookieAuthenticationHandler.cs源码;
var ticket = new AuthenticationTicket(signInContext.Principal, signInContext.Properties, signInContext.Scheme.Name);
if (Options.SessionStore != null)
{
if (_sessionKey != null)
{
await Options.SessionStore.RemoveAsync(_sessionKey);
}
_sessionKey = await Options.SessionStore.StoreAsync(ticket);
var principal = new ClaimsPrincipal(
new ClaimsIdentity(
new[] { new Claim(SessionIdClaim, _sessionKey, ClaimValueTypes.String, Options.ClaimsIssuer) },
Options.ClaimsIssuer));
ticket = new AuthenticationTicket(principal, null, Scheme.Name);
}
var cookieValue = Options.TicketDataFormat.Protect(ticket, GetTlsTokenBinding());
【问题讨论】:
-
我不相信 SessionStore 意味着一个 asp.net 会话。根据文档,它是“跨请求存储票证的可选容器”
标签: session authentication cookies asp.net-core .net-core