繁体   English   中英

SPA模板中cookie中间件的作用是什么

[英]What is the role of the cookie middleware in SPA Template

VS 2013 SPA模板配置有cookie中间件,以及其他中间件,例如OAuth MW或ExternalCookie MW。

    // Enable the application to use a cookie to store information for the signed in user
    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login"),
        Provider = new CookieAuthenticationProvider
        {
            OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                validateInterval: TimeSpan.FromMinutes(20),
                regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
        }
    });
    // Use a cookie to temporarily store information about a user logging in with a third party login provider
    app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

    // Enable the application to use bearer tokens to authenticate users
    app.UseOAuthBearerTokens(OAuthOptions);

由于WebApi将授权通过承载令牌从客户端进行的调用,并且外部cookie中间件在那里支持外部登录提供程序,因此cookie中间件在其中起什么作用?

它在那里是表单身份验证的替代品。 在此之前,用户将使用表单auth登录,然后将发布cookie,并创建一个代表用户身份的主体对象。 使用OWIN,cookie身份验证中间件执行相同的任务。

如上一行代码所示,它还将处理诸如登录/重定向(禁止请求)之类的事情:

LoginPath = new PathString("/Account/Login"),

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM