public static void Register(HttpConfiguration config) { //Create and instance of TokenInspector setting the default inner handler var tokenInspector = new TokenInspector { InnerHandler = new HttpControllerDispatcher(config) }; //Just exclude the users controllers from need to provide valid token, so they could authenticate config.Routes.MapHttpRoute( name: "Authentication", routeTemplate: "api/users/{id}", defaults: new { controller = "users" } ); // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }, constraints: null, handler: tokenInspector ); config.MessageHandlers.Add(new HTTPSGuard()); var cors = new EnableCorsAttribute("*", "*", "GET,POST,PUT"); config.EnableCors(cors); }
//void Application_Start(object sender, EventArgs e) //{ // // Code that runs on application startup // GlobalConfiguration.Configure(WebApiConfig.Register); //} protected void Application_Start() { var config = GlobalConfiguration.Configuration; var tokenInspector = new TokenInspector() { InnerHandler = new HttpControllerDispatcher(config) }; //config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; //config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects; #if (!DEBUG) //For HTTPS config.MessageHandlers.Add(new HttpsGuard()); #endif config.Routes.MapHttpRoute( name: "Authentication", routeTemplate: "api/users/{action}/{id}", defaults: new { controller = "users", id = RouteParameter.Optional } ); config.Routes.MapHttpRoute( name: "StQuoteData", routeTemplate: "api/data/{action}/{id}", constraints: null, handler: tokenInspector, defaults: new { controller = "StQuoteData", id = RouteParameter.Optional } ); }
public static void Register(HttpConfiguration config) { // Web API configuration and services TokenInspector tokenInspector = new TokenInspector { InnerHandler = new HttpControllerDispatcher(config) }; // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }, constraints: null, handler: tokenInspector ); }
public static void ApplyTokenInspectorHandlerToServicesRoute(RouteCollection routes, UserManager userManager) { var servicesRoute = routes[0]; string servicesRouteUrl = (string)servicesRoute.GetType().GetProperty("Url").GetValue(servicesRoute); var tokenInspector = new TokenInspector(userManager) { InnerHandler = new HttpControllerDispatcher(GlobalConfiguration.Configuration) }; routes.Clear(); routes.MapHttpRoute( name: "ServicesRoute", routeTemplate: servicesRouteUrl, defaults: null, constraints: null, handler: tokenInspector ); }
public static void Register(HttpConfiguration config) { //Create and instance of TokenInspector setting the default inner handler TokenInspector tokenInspector = new TokenInspector() { InnerHandler = new HttpControllerDispatcher(config) }; config.Routes.MapHttpRoute( name: "Authentication", routeTemplate: "api/users/{id}", defaults: new { controller = "users" } ); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }, constraints: null, handler: tokenInspector ); config.MessageHandlers.Add(new HTTPSGuard()); //Global handler - applicable to all the requests }
public static void Register(HttpConfiguration config) { //Register token inspector TokenInspector tokenInspector = new TokenInspector() { InnerHandler = new HttpControllerDispatcher(config) }; // Web API configuration and services config.EnableCors(); #region Anonymous Route config.Routes.MapHttpRoute( name: "Authentication", routeTemplate: "api/account/authenticate", defaults: new { controller = "Account", action = "Authenticate" }, constraints: null ); config.Routes.MapHttpRoute( name: "IsValidServerIP", routeTemplate: "api/account/isValidServerIP", defaults: new { controller = "Account", action = "IsValidServerIP" }, constraints: null ); config.Routes.MapHttpRoute( name: "GetTokenIssueExpireDate", routeTemplate: "api/account/getTokenIssueExpireDate", defaults: new { controller = "Account", action = "GetTokenIssueExpireDate" }, constraints: null ); config.Routes.MapHttpRoute( name: "GetValidUserInfoByToken", routeTemplate: "api/account/getValidUserInfoByToken", defaults: new { controller = "Account", action = "GetValidUserInfoByToken" }, constraints: null ); config.Routes.MapHttpRoute( name: "LogAccessToken", routeTemplate: "api/account/logAccessToken", defaults: new { controller = "Account", action = "LogAccessToken" }, constraints: null ); config.Routes.MapHttpRoute( name: "SetLoginData", routeTemplate: "api/account/setLoginData", defaults: new { controller = "Account", action = "SetLoginData" }, constraints: null ); config.Routes.MapHttpRoute( name: "GetFilesToCache", routeTemplate: "api/Manifest/GetFilesToCache", defaults: new { controller = "Manifest", action = "GetFilesToCache" }, constraints: null ); config.Routes.MapHttpRoute( name: "VerifyRolePermission", routeTemplate: "api/Security/VerifyRolePermission", defaults: new { controller = "Security", action = "VerifyRolePermission" }, constraints: null ); config.Routes.MapHttpRoute( name: "SendResetLink", routeTemplate: "api/forgotPassword/sendResetLink", defaults: new { controller = "ForgotPassword", action = "SendResetLink" }, constraints: null ); config.Routes.MapHttpRoute( name: "GetSecurityQuestions", routeTemplate: "api/forgotPassword/getSecurityQuestions", defaults: new { controller = "ForgotPassword", action = "GetSecurityQuestions" }, constraints: null ); config.Routes.MapHttpRoute( name: "VerifySecurityDetails", routeTemplate: "api/forgotPassword/verifySecurityDetails", defaults: new { controller = "ForgotPassword", action = "VerifySecurityDetails" }, constraints: null ); config.Routes.MapHttpRoute( name: "ResetPassword", routeTemplate: "api/forgotPassword/resetPassword", defaults: new { controller = "ForgotPassword", action = "ResetPassword" }, constraints: null ); config.Routes.MapHttpRoute( name: "VerifyResetIdentifier", routeTemplate: "api/forgotPassword/verifyResetIdentifier", defaults: new { controller = "ForgotPassword", action = "VerifyResetIdentifier" }, constraints: null ); config.Routes.MapHttpRoute( name: "GetSettingsToCache", routeTemplate: "api/settings/getSettingsToCache", defaults: new { controller = "Settings", action = "GetSettingsToCache" }, constraints: null ); #endregion Anonymous Route #region Secure Route config.Routes.MapHttpRoute( name: ControllerOnlyRoute, routeTemplate: "api/{controller}", defaults: null, constraints: null, handler: tokenInspector ); config.Routes.MapHttpRoute( name: ControllerWithIdRoute, routeTemplate: "api/{controller}/{id}", defaults: null, constraints: new { id = @"\d+" }, handler: tokenInspector ); config.Routes.MapHttpRoute( name: ControllerWithActionRoute, routeTemplate: "api/{controller}/{action}", defaults: null, constraints: null, handler: tokenInspector ); config.Routes.MapHttpRoute( name: ControllerWithActionAndIdRoute, routeTemplate: "api/{controller}/{action}/{id}", defaults: null, constraints: null, handler: tokenInspector ); #endregion Secure Route config.Filters.Add(new ExceptionFilter()); config.Filters.Add(new LogActionFilter()); }