e63dc12dff
Logger and exceptionManager
97 lines
3.3 KiB
C#
97 lines
3.3 KiB
C#
using System;
|
|
using Microsoft.Owin;
|
|
using Owin;
|
|
using System.Web.Http;
|
|
using Microsoft.Owin.StaticFiles;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using Microsoft.Owin.FileSystems;
|
|
using System.Configuration;
|
|
using Microsoft.Owin.Security.OAuth;
|
|
using Microsoft.Owin.Cors;
|
|
using Step.Provider;
|
|
using Microsoft.AspNet.SignalR;
|
|
using Microsoft.AspNet.SignalR.Hubs;
|
|
using Step.Attributes;
|
|
|
|
[assembly: OwinStartup(typeof(Step.App_Start.Startup))]
|
|
|
|
namespace Step.App_Start
|
|
{
|
|
public class Startup
|
|
{
|
|
public static OAuthAuthorizationServerOptions OAuthOptions;
|
|
public void Configuration(IAppBuilder app)
|
|
{
|
|
// Configure HTTP
|
|
HttpConfiguration config = new HttpConfiguration();
|
|
|
|
// Register Web API config
|
|
WebApiConfig.Register(config);
|
|
|
|
// Register Swagger config
|
|
SwaggerConfig.Register(config);
|
|
|
|
// Configure api authentication
|
|
ConfigureWebApiOAuth(app);
|
|
|
|
app.UseWebApi(config);
|
|
|
|
// SignalR config & startup
|
|
SignalRConfig(app);
|
|
|
|
var directoryBrowsing = ConfigurationManager.AppSettings["enableDirectoryBrowsing"] == "true";
|
|
|
|
string rootDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", "wwwroot");
|
|
var options = new FileServerOptions()
|
|
{
|
|
EnableDefaultFiles = !directoryBrowsing,
|
|
EnableDirectoryBrowsing = directoryBrowsing,
|
|
RequestPath = PathString.Empty,
|
|
FileSystem = new PhysicalFileSystem(rootDir)
|
|
};
|
|
|
|
app.UseFileServer(options);
|
|
}
|
|
|
|
private void ConfigureWebApiOAuth(IAppBuilder app)
|
|
{
|
|
// Create new authorization options
|
|
OAuthOptions = new OAuthAuthorizationServerOptions
|
|
{
|
|
// Login and Token generation end point
|
|
TokenEndpointPath = new PathString("/Token"),
|
|
Provider = new ApplicationOAuthProvider(),
|
|
// Bearer token expiration time
|
|
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
|
|
//TODO: In modalità di produzione impostare AllowInsecureHttp = false
|
|
AllowInsecureHttp = true
|
|
};
|
|
// Set authorization options
|
|
app.UseOAuthAuthorizationServer(OAuthOptions);
|
|
// Set bearer oAuth as authentication method
|
|
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
|
|
}
|
|
|
|
public void SignalRConfig(IAppBuilder app)
|
|
{
|
|
//// Set up signalR config
|
|
//app.Map("/signalr", map =>
|
|
//{
|
|
// map.UseCors(CorsOptions.AllowAll);
|
|
// // Debug
|
|
// HubConfiguration hubConfiguration = new HubConfiguration
|
|
// {
|
|
// EnableDetailedErrors = true
|
|
// };
|
|
// // Create an istance of custom authorize attribute
|
|
// SignalRAuthorizeAttribute authorizer = new SignalRAuthorizeAttribute();
|
|
// AuthorizeModule module = new AuthorizeModule(authorizer, authorizer);
|
|
// GlobalHost.HubPipeline.AddModule(module);
|
|
// map.RunSignalR();
|
|
//});
|
|
app.MapSignalR();
|
|
}
|
|
}
|
|
}
|