.net - OWIN OAuth 2.0 - 不记名 token 永不过期

我正在使用以下 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 中也提到了它.

https://stackoverflow.com/questions/23951859/

相关文章:

r - 使用 gbm() 分类 - 错误

c# - 如何将列表项添加到在代码隐藏中生成的下拉列表?

php - 如何为 PHP 类提供表单操作

bash - 如何确定哪些主机名未解析为 IP 地址?

hornetq - 在同一个虚拟机中启动多个嵌入式 HornetQ 代理

sql - insert into.. select 语句是事务性的吗?

perforce - 如何查找特定用户提交的所有文件

image - 我需要缩小图像尺寸?有人可以帮助我吗?

php - 如何通过表格中的表单发送复选框状态

netlogo - 如何在Netlogo中直接保存.txt文件的数据?