WebApi Owin令牌太快回归401了

时间:2015-04-24 04:24:11

标签: asp.net-web-api token owin

主要使用默认的WebAPI 2.2 Owin身份验证,并且在令牌发布后不久我们就会获得401未授权。代码配置为在90天后过期...任何想法为什么?是的,我们也想使用刷新令牌,但没有机会实施......

        OAuthOptions = new OAuthAuthorizationServerOptions
        {
            TokenEndpointPath = new PathString("/authenticate"),
            Provider = new MyTokenProvider(PublicClientId),
            AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
            AccessTokenExpireTimeSpan = TimeSpan.FromDays(90),
            //AllowInsecureHttp = true
        };

1 个答案:

答案 0 :(得分:0)

尝试以这种方式使用

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        ConfigureOAuth(app);
    //Rest of code is here;
    }

    public void ConfigureOAuth(IAppBuilder app)
    {
        OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
        {
            AllowInsecureHttp = true,
            TokenEndpointPath = new PathString("/token"),
            AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
            Provider = new SimpleAuthorizationServerProvider()
        };

        // Token Generation
        app.UseOAuthAuthorizationServer(OAuthServerOptions);
        app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

    }
}