1

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 中间件在其中扮演什么角色?

4

1 回答 1

1

它可以替代表单身份验证。以前,用户会使用表单身份验证登录,然后它会发出一个 cookie,并创建一个代表用户身份的主体对象。使用 OWIN,cookie 身份验证中间件执行相同的任务。

它还将处理诸如登录/重定向(禁止请求)之类的事情,正如您在上面的代码行中看到的那样:

LoginPath = new PathString("/Account/Login"),
于 2015-10-09T12:11:28.370 回答