作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用以下 OAuth 提供程序和选项:
UserManagerFactory = () => new UserManager<IdentityUser>(new UserStore<IdentityUser>(new ApplicationDbContext()));
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
AuthorizeEndpointPath = new PathString("/api/AccountOwin/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(2),
AllowInsecureHttp = true
};
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthOptions);
Oauth Provider 类来自以下链接: https://github.com/gustavo-armenta/BearerTokenAuthenticationSample/blob/master/BearerTokenAuthenticationSample/Providers/ApplicationOAuthProvider.cs
我想实现刷新 token 提供程序,因此我将过期时间设置为 2 分钟。但我注意到 WEB API 即使在 2 分钟后也允许访问资源。
提前致谢!
最佳答案
我遇到这个问题是因为我忘记正确配置 WebAPI。将以下代码添加到我的 WebApiConfig Register() 方法中解决了它。
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
我在 the sample I used 中找到了这个this post 中也提到了它.
关于.net - OWIN OAuth 2.0 - 不记名 token 永不过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23951859/
我是一名优秀的程序员,十分优秀!