【发布时间】:2014-09-04 04:52:50
【问题描述】:
我写了一个提供者,它通过用户名/密码制作不记名令牌 10 年:
public partial class Startup
{
private readonly TimeSpan _tokenLifetime = TimeSpan.FromDays(3600);
public void ConfigureAuth(IAppBuilder app)
{
var config = new HttpConfiguration();
WebApiConfig.Register(config);
app.UseCors(CorsOptions.AllowAll);
app.CreatePerOwinContext(UsersDB.Create);
app.CreatePerOwinContext<UserManager>(UserManager.Create);
app.CreatePerOwinContext<RoleManager>(RoleManager.Create);
app.UseOAuthBearerTokens(new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/getToken"),
Provider = new ApplicationOAuthProvider(new UserManager(new ApiUserStore(new UsersDB()))),
AccessTokenExpireTimeSpan = _tokenLifetime,
AllowInsecureHttp = true,
});
app.UseWebApi(config);
}
}
客户端必须获取令牌,并且必须将其用于 Web API 服务的所有方法。 如果客户端获得了新令牌,则旧令牌不会失效。并且客户端可以同时使用这两个令牌。
如何使第一个令牌无效?
【问题讨论】:
标签: c# security oauth-2.0 token asp.net-web-api