Angularjs Web API 2令牌到期/被拒绝
我正在使用WebAPI2基于令牌的身份验证、本地存储和我编写的Angular应用程序。感谢Taiseer Joudeh的文章。一切都很顺利,只是在一个小时左右之后,用户被web api[Authorize]拒绝访问,使用的令牌与首次登录时相同。令牌仍存在于本地存储中。我使用默认的14天超时。令牌可能在哪里超时/过期?以下是我正在使用的ConfigureAuth函数:Angularjs Web API 2令牌到期/被拒绝,angularjs,token,asp.net-web-api2,Angularjs,Token,Asp.net Web Api2,我正在使用WebAPI2基于令牌的身份验证、本地存储和我编写的Angular应用程序。感谢Taiseer Joudeh的文章。一切都很顺利,只是在一个小时左右之后,用户被web api[Authorize]拒绝访问,使用的令牌与首次登录时相同。令牌仍存在于本地存储中。我使用默认的14天超时。令牌可能在哪里超时/过期?以下是我正在使用的ConfigureAuth函数: public partial class Startup { public static OAuthAuthorizati
public partial class Startup
{
public static OAuthAuthorizationServerOptions OAuthOptions { get; private set; }
public static string PublicClientId { get; private set; }
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context and user manager to use a single instance per request
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Configure the application for OAuth based flow
PublicClientId = "self";
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId),
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);
}
}
公共部分类启动
{
公共静态OAuthAuthorizationServerOptions OAuthOptions{get;private set;}
公共静态字符串PublicClientId{get;private set;}
//有关配置身份验证的详细信息,请访问http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder应用程序)
{
//将db上下文和用户管理器配置为每个请求使用一个实例
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext(ApplicationUserManager.Create);
//使应用程序能够使用cookie存储登录用户的信息
//以及使用cookie临时存储用户登录第三方登录提供商的信息
app.UseCookieAuthentication(新的CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
//为基于OAuth的流配置应用程序
PublicClientId=“self”;
OAuthOptions=新的OAuthAuthorizationServerOptions
{
TokenEndpointPath=新路径字符串(“/Token”),
Provider=新的ApplicationAuthProvider(PublicClientId),
AuthorizeEndpointPath=新路径字符串(“/api/Account/ExternalLogin”),
AccessTokenExpireTimeSpan=TimeSpan.FromDays(14),
AllowInsecureHttp=true
};
//使应用程序能够使用承载令牌对用户进行身份验证
应用程序使用OAuthBealerTokens(OAuthOptions);
}
}
也许这与你允许的那些Cookies有关。他们什么时候休息?谢谢,我去查firebug的饼干。我不认为我需要或使用cookies,因为我使用本地存储来存储用户名和令牌数据。我是否应该注释掉上面代码中的两行cookie enable?问题的解决方案是增加IIS中应用程序池/工作进程的空闲超时值,该值默认为20分钟。@AustinHarris-您是否找到了在客户端删除用户令牌的方法?i、 e.如果用户单击注销
按钮,删除该身份验证令牌的最佳方式是什么。