private void RegisterHandlers() { var logManager = WebContainerManager.Get <ILogManager>(); var userSession = WebContainerManager.Get <IUserSession>(); GlobalConfiguration.Configuration.MessageHandlers.Add( new BasicAuthenticationMessageHandler(logManager, WebContainerManager.Get <IBasicSecurityService>())); GlobalConfiguration.Configuration.MessageHandlers.Add(new TaskDataSecurityMessageHandler(logManager, userSession)); GlobalConfiguration.Configuration.MessageHandlers.Add(new PagedTaskDataSecurityMessageHandler(logManager, userSession)); var builder = new SecurityTokenBuilder(); var reader = new ConfigurationReader(); GlobalConfiguration.Configuration.MessageHandlers.Add( new JwtAuthenticationMessageHandler { AllowedAudience = reader.AllowedAudience, Issuer = reader.Issuer, SigningToken = builder.CreateFromKey(reader.SymmetricKey) }); }
public static void Register(HttpConfiguration config) { // Web API configuration and services config.Filters.Add(new AuthorizeAttribute()); // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); var builder = new SecurityTokenBuilder(); var jwtHandler = new JwtAuthenticationMessageHandler { AllowedAudience = "http://www.rac.com.au", Issuer = "Satalyst", SigningToken = builder.CreateFromKey(ConfigurationManager.AppSettings["ApplicationKey"]) }; config.MessageHandlers.Add(jwtHandler); JsonMediaTypeFormatter jsonFormatter = config.Formatters.JsonFormatter; JsonSerializerSettings settings = jsonFormatter.SerializerSettings; settings.Formatting = Formatting.None; settings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }
public static void Register(HttpConfiguration config) { config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); var tokenBuilder = new SecurityTokenBuilder(); var configReader = new ConfigurationReader(); var jwtHandler = new JwtAuthenticationMessageHandler { AllowedAudience = configReader.AllowedAudience, Issuer = configReader.Issuer, SigningToken = tokenBuilder.CreateFromKey(configReader.SymmetricKey), PrincipalTransformer = new PrincipalPersonalizadoTransformer() }; config.MessageHandlers.Add(jwtHandler); //WebApiConfig.Register(GlobalConfiguration.Configuration); //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type. // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries. // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712. //config.EnableQuerySupport(); // To disable tracing in your application, please comment out or remove the following line of code // For more information, refer to: http://www.asp.net/web-api config.EnableSystemDiagnosticsTracing(); }
public static void Register(HttpConfiguration config) { //Register CacheCow var cacheCow = new CacheCow.Server.CachingHandler(config, ""); config.MessageHandlers.Add(cacheCow); //Enable CORS //http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api //var cors = new EnableCorsAttribute(ConfigurationManager.AppSettings["CORSSites"].ToString(), "*", "*"); //cors.SupportsCredentials = true; //the HTTP response will include an 'Access-Control-Allow-Credentials' header //config.EnableCors(cors); // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); var tokenBuilder = new SecurityTokenBuilder(); var configReader = new ConfigurationReader(); //var jwtHandlerCert = new JwtAuthenticationMessageHandler //{ // AllowedAudience = configReader.AllowedAudience, // AllowedAudiences = configReader.AllowedAudiences, // Issuer = configReader.Issuer, // SigningToken = tokenBuilder.CreateFromCertificate(configReader.SubjectCertificateName), // PrincipalTransformer = new SamplePrincipalTransformer() //}; var jwtHandlerSharedKey = new JwtAuthenticationMessageHandler { AllowedAudience = configReader.AllowedAudience, Issuer = configReader.Issuer, SigningToken = tokenBuilder.CreateFromKey(configReader.SymmetricKey), PrincipalTransformer = new SamplePrincipalTransformer(), CookieNameToCheckForToken = configReader.CookieNameToCheckForToken }; //config.MessageHandlers.Add(jwtHandlerCert); config.MessageHandlers.Add(jwtHandlerSharedKey); }
public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); var tokenBuilder = new SecurityTokenBuilder(); var configReader = new ConfigurationReader(); var jwtHandlerCert = new JwtAuthenticationMessageHandler(Logger.Instance) { AllowedAudience = configReader.AllowedAudience, AllowedAudiences = configReader.AllowedAudiences, Issuer = configReader.Issuer, SigningToken = tokenBuilder.CreateFromCertificate(configReader.SubjectCertificateName), PrincipalTransformer = new SamplePrincipalTransformer() }; var jwtHandlerSharedKey = new JwtAuthenticationMessageHandler(Logger.Instance) { AllowedAudience = configReader.AllowedAudience, Issuer = configReader.Issuer, SigningToken = tokenBuilder.CreateFromKey(configReader.SymmetricKey), PrincipalTransformer = new SamplePrincipalTransformer(), CookieNameToCheckForToken = configReader.CookieNameToCheckForToken }; config.MessageHandlers.Add(jwtHandlerCert); config.MessageHandlers.Add(jwtHandlerSharedKey); // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type. // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries. // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712. //config.EnableQuerySupport(); // To disable tracing in your application, please comment out or remove the following line of code // For more information, refer to: http://www.asp.net/web-api config.EnableSystemDiagnosticsTracing(); }
public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new {id = RouteParameter.Optional} ); var tokenBuilder = new SecurityTokenBuilder(); var configReader = new ConfigurationReader(); var jwtHandlerCert = new JwtAuthenticationMessageHandler { AllowedAudience = configReader.AllowedAudience, AllowedAudiences = configReader.AllowedAudiences, Issuer = configReader.Issuer, SigningToken = tokenBuilder.CreateFromCertificate(configReader.SubjectCertificateName), PrincipalTransformer = new SamplePrincipalTransformer() }; var jwtHandlerSharedKey = new JwtAuthenticationMessageHandler { AllowedAudience = configReader.AllowedAudience, Issuer = configReader.Issuer, SigningToken = tokenBuilder.CreateFromKey(configReader.SymmetricKey), PrincipalTransformer = new SamplePrincipalTransformer(), CookieNameToCheckForToken = configReader.CookieNameToCheckForToken }; config.MessageHandlers.Add(jwtHandlerCert); config.MessageHandlers.Add(jwtHandlerSharedKey); // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type. // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries. // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712. //config.EnableQuerySupport(); // To disable tracing in your application, please comment out or remove the following line of code // For more information, refer to: http://www.asp.net/web-api config.EnableSystemDiagnosticsTracing(); }