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(validateInterval: TimeSpan.FromMinutes(30), regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) } });
任何人都可以帮助我理解app.UseOAuthBearerTokens和app.UseCookieAuthentication之间的区别(以及为什么要进行此更改)?它们似乎都允许应用程序以相同的方式运行,我可以对此更改使用一些说明.
谢谢...
-ben