OWIN Login slow performance >30 Seconds
<p>I have a big performance issue when i try to login with my application. The application is a Web api app hosted in Azure. I use react js for my front end.</p>

<p>And in my SimpleAuthorizationprovider i am fetching the user and adding claims to the ClaimsIdentity property. If i debug it locally i only have slow performance issue the first time i login but the next time i login the login is instant access. When i upload it to my test environment in Azure the problem is there every request. </p>

<p>I have switched on the "Always on" property in Azure for the web app. I have timed the request and the thing that takes a lot of time is the this piece of code in SimpleAuthorizationprovider </p>

<pre><code>  context.Validated(ticket);
</code></pre>

<p>It takes in my test environment 15 sek to just authorize the user. There is maybe some delays in my front end as well. IN my front end we are using superagent to make requests to the web api.</p>

<p>Here is my configuration in my startup class:</p>

<pre><code>public void Configuration(IAppBuilder app)
    {
        app.UseCors(CorsOptions.AllowAll);

        ConfigureOAuth(app);
        var physicalFileSystem = new PhysicalFileSystem(@"./Html");
         var options = new FileServerOptions
        {
            EnableDefaultFiles = true,
            FileSystem = physicalFileSystem,
            StaticFileOptions =
            {
                FileSystem = physicalFileSystem,
                ServeUnknownFileTypes = true
            },
            DefaultFilesOptions = {DefaultFileNames = new[] {"Startup.html"}}
        };
        app.UseFileServer(options);

        // Get your HttpConfiguration.
        var config = GetInjectionConfiguration(); 
        config.MessageHandlers.Add(new QueryStringBearerToken());

        WebApiConfig.Register(config);

        // Setup WebApi
        app.UseWebApi(config);
        SetupWebApi(config);

        Application_Start(config);
        config.EnsureInitialized();
    }

  public void ConfigureOAuth(IAppBuilder app)
    {
        var oAuthServerOptions = new OAuthAuthorizationServerOptions
        {
            TokenEndpointPath = new PathString("/api/token"),
            AuthorizeEndpointPath = new PathString("/Login"),
            AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(120),
            Provider = new SimpleAuthorizationServerProvider(),
            RefreshTokenProvider = new ApplicationRefreshTokenProvider(),
            AllowInsecureHttp = true,

        };

        var oAuthBearerOptions = new OAuthBearerAuthenticationOptions
        {
            Provider = new QueryStringOAuthBearerProvider(),
            AccessTokenProvider = new AuthenticationTokenProvider(),
        };

        app.UseOAuthBearerAuthentication(oAuthBearerOptions);
        app.UseOAuthAuthorizationServer(oAuthServerOptions);
    }
</code></pre>

<p><strong>EDIT:</strong></p>

<p>I can now say that the context.validated(ticket) is not the problem. I have connected application insights in Azure to see if i can get any more useful information from there. My guess is still that the api process is not "warmed" up before the request hits and that results in that the process needs to boost everytime. When i debug it locally it takes about 10 sek for the first request to hit my token endpoint. After that request i sent another one and everything works as expected. Some more digging needs to be done here ;)</p>