0
我使用app.UseCookieAuthentication
如下(只是一個簡單的例子);CookieAuthentication中間件提供的cookie是否安全?
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationScheme = "MyAuthScheme",
AutomaticAuthenticate = true,
});
然後某處,我手動創建ClaimsPrincipal
和用戶簽約:
var claimCollection = new List<Claim>()
{
new Claim(ClaimTypes.Name, "First user"),
new Claim(ClaimTypes.Role, "User"),
new Claim(ClaimTypes.Email, "[email protected]")
};
var claimsIdentity = new ClaimsIdentity(claimCollection);
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
await context.Authentication.SignInAsync("MyAuthScheme", claimsPrincipal);
所以生成的cookie將包含有關用戶角色的信息。
現在的問題是:這樣生成的cookie安全嗎?我的意思是ASP.NET以某種方式加密它,所以最終用戶不能以某種方式手動修改它,例如,服務器會認爲用戶是管理員? 服務器會在用戶修改Cookie時注意到Cookie被損壞嗎?