基于ASP.NET令牌的授权太长

时间:2015-05-05 19:59:50

标签: asp.net authentication oauth authorization owin

我有ASP.NET REST API服务,它的工作非常快速和精细,除了授权,我使用标准的Token auth,基于Owin.Security,这是它的样子:

    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.FromMinutes(10),
            AllowInsecureHttp = true,

        };

        // Enable the application to use bearer tokens to authenticate users
        app.UseOAuthBearerTokens(OAuthOptions);

}

我没有改变任何东西,它来自模板项目,除了时间之外它工作正常。从服务器返回一个持票人令牌需要大约30秒。 我对ASP.NET开发很陌生,我不知道它为什么这么久,我的数据库中有10个用户和3个角色,我确信它可以更快地工作,但不要#39 ; t知道如何

其他休息请求(POST,GET)工作得很快,很好,只有/ Token请求需要30秒

好吧,我已经重新发布了我的服务器解决方案,现在需要从3到30秒内随机获取身份验证令牌,这是非常奇怪的行为,不是吗? < / p>

1 个答案:

答案 0 :(得分:0)

1)如果您在应用程序启动后立即请求令牌,则在首次执行任何控制器方法之前会出现一些应用程序初始化逻辑。
2)如果您使用远程SQL服务器实例,这可能导致长请求处理。尝试使用本地SQL服务器进行本地分析。