【发布时间】:2015-11-07 01:00:21
【问题描述】:
ASP.NET 团队已经发布了展示如何使用身份包的新示例。它们包含在以下 nuget 包中:Microsoft Asp.Net Identity Samples
这些示例非常有帮助,但与最初发布的模板中的操作方式相比,已经发生了很多变化。
我的具体问题:在原来的SPA模板中,有如下代码:
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
AllowInsecureHttp = true
};
...
// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthOptions);
但在 nuget 包中的新示例中,该代码已消失,取而代之的是以下代码:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(validateInterval: TimeSpan.FromMinutes(30), regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
谁能帮我理解 app.UseOAuthBearerTokens 和 app.UseCookieAuthentication 之间的区别(以及为什么要进行此更改)?它们似乎都允许应用程序以相同的方式运行,我可以对此更改进行一些说明。
谢谢...
-本
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-identity