Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationInsightsTelemetry(Configuration);

            ContainerSetup.Setup(services, Configuration);

            services.AddAuthorization(auth =>
            {
                auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder()
                               .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                               .RequireAuthenticatedUser().Build());
            });
            // Add framework services.
            services.AddMvc(options => { options.Filters.Add(new ApiExceptionFilter()); })
            .AddJsonOptions(o =>
            {
                o.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
            });
            ;
            services.AddNodeServices();

            // Register the Swagger generator, defining one or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Expenses", Version = "v1"
                });
                c.OperationFilter <AuthorizationHeaderParameterOperationFilter>();
            });
        }
Esempio n. 2
0
        public void Configuration(IAppBuilder app)
        {
            Container = ContainerSetup.Setup(app);
            OwinSetup.Setup(app);
            ChannelSetup.Setup(app, Container);

            #region handles all api requests
            // CQRS EXECUTION
            app.Run((context =>
            {
                var router = Container.Create <IRouter>();
                var body = new Hashtable();

                context.Response.StatusCode = 404; // default status code
                context.Response.Headers.Add("Content-Type", new string[] { "application/json" });

                try
                {
                    // CQRS
                    ICommand command = router.Route(context.Request);
                    body = command.Invoke(context).Result;
                }
                catch (Exception error)
                {
                    context.Response.StatusCode = 500;
                    body.Add("error", error.ToHashtable());
                }

                return(context.Response.WriteAsync(JsonConvert.SerializeObject(body)));
            }));

            #endregion handles all api requests
        }
Esempio n. 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            ContainerSetup.Setup(services, Configuration);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, (o) =>
            {
                o.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidAudience            = TokenAuthOption.Audience,
                    IssuerSigningKey         = TokenAuthOption.key,
                    ValidIssuer              = TokenAuthOption.Issuer,
                    ValidateLifetime         = true,
                    ValidateAudience         = true,
                    ValidateIssuerSigningKey = true,
                    ValidateIssuer           = true,
                    ClockSkew = TimeSpan.FromMinutes(0)
                };
            });

            services.AddAuthorization(auth =>
            {
                auth.AddPolicy(JwtBearerDefaults.AuthenticationScheme, new AuthorizationPolicyBuilder()
                               .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                               .RequireAuthenticatedUser().Build());
            });

            //services.AddMvc();
            services.AddMvc(setupAction =>
            {
                setupAction.Filters.Add(new ApiExceptionFilter());

                var policy = new AuthorizationPolicyBuilder()
                             .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                             .RequireAuthenticatedUser().Build();

                // setupAction.Filters.Add(new CustomAuthorizeFilter(policy));
            })
            .AddJsonOptions(o =>
            {
                o.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;
            });

            services.AddNodeServices();

            // Register the Swagger generator, defining one or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Monefy", Version = "v1"
                });
                c.OperationFilter <AuthorizationHeaderParameterOperationFilter>();
            });

            services.AddCors();
        }
Esempio n. 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <MainDbContext>();
            services.AddApplicationInsightsTelemetry(Configuration);
            ContainerSetup.Setup(services, Configuration);

            //services.AddControllers();
            services.AddMvc(options => { options.Filters.Add(new ApiExceptionFilter()); })
            .AddNewtonsoftJson(o =>
            {
                o.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
            });
        }
Esempio n. 5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddMvc(options => { options.Filters.Add(new ApiExceptionFilter()); })
            .AddJsonOptions(o =>
            {
                o.SerializerSettings.DateTimeZoneHandling  = DateTimeZoneHandling.Local;
                o.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            })
            ;

            ContainerSetup.Setup(services, Configuration);
        }
Esempio n. 6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            ContainerSetup.Setup(services, Configuration);

            services.AddControllersWithViews(options => { options.Filters.Add(new ApiExceptionFilter()); });

            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Processor", Version = "v1"
                });
            });
        }
Esempio n. 7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            ContainerSetup.Setup(services, Configuration);

            services.AddControllersWithViews().
            AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "OMSWeb", Version = "v1"
                });
            });
        }
Esempio n. 8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            //services.AddApplicationInsightsTelemetry(Configuration);
            ContainerSetup.Setup(services, Configuration);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, (o) =>
            {
                o.TokenValidationParameters = new TokenValidationParameters()
                {
                    IssuerSigningKey         = TokenAuthOption.Key,
                    ValidAudience            = TokenAuthOption.Audience,
                    ValidIssuer              = TokenAuthOption.Issuer,
                    ValidateIssuerSigningKey = true,
                    ValidateLifetime         = true,
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ClockSkew = TimeSpan.FromMinutes(0)
                };
            });

            services.AddAuthorization(auth =>
            {
                auth.AddPolicy(JwtBearerDefaults.AuthenticationScheme, new AuthorizationPolicyBuilder()
                               .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                               .RequireAuthenticatedUser().Build());
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Loggifyio", Version = "v1"
                });
            });

            services.AddCors(options =>
                             options.AddPolicy("loggifyio-client", p => p.WithOrigins("http://localhost:8080")
                                               .AllowAnyMethod()
                                               .AllowAnyHeader()));


            services.AddMvc(options => { options.Filters.Add(new ApiExceptionFilter()); })
            .AddJsonOptions(o =>
            {
                o.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
            });
        }
Esempio n. 9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            ILoggerFactory loggerFactory = new LoggerFactory();
            ILogger        logger        = loggerFactory.CreateLogger("");

            logger.LogInformation("Got Log Configuraiton");

            services.AddSingleton(logger);
            services.AddApplicationInsightsTelemetry(Configuration);

            ContainerSetup.Setup(services, Configuration);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, (o) =>
            {
                o.TokenValidationParameters = new TokenValidationParameters()
                {
                    IssuerSigningKey         = TokenAuthOption.Key,
                    ValidAudience            = TokenAuthOption.Audience,
                    ValidIssuer              = TokenAuthOption.Issuer,
                    ValidateIssuerSigningKey = true,
                    ValidateLifetime         = true,
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ClockSkew = TimeSpan.FromMinutes(0)
                };
            });

            services.AddAuthorization(auth =>
            {
                auth.AddPolicy(JwtBearerDefaults.AuthenticationScheme, new AuthorizationPolicyBuilder()
                               .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                               .RequireAuthenticatedUser().Build());
            });
            // Add framework services.
            services.AddMvc(options => { options.Filters.Add(new ApiExceptionFilter()); });

            // Register the Swagger generator, defining one or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo {
                    Title = "Expenses", Version = "v1"
                });
                c.OperationFilter <AuthorizationHeaderParameterOperationFilter>();
            });
        }
Esempio n. 10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationInsightsTelemetry(Configuration);

            ContainerSetup.Setup(services, Configuration);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, (o) =>
            {
                o.TokenValidationParameters = new TokenValidationParameters()
                {
                    IssuerSigningKey         = TokenAuthOption.Key,
                    ValidAudience            = TokenAuthOption.Audience,
                    ValidIssuer              = TokenAuthOption.Issuer,
                    ValidateIssuerSigningKey = true,
                    ValidateLifetime         = true,
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ClockSkew = TimeSpan.FromMinutes(0)
                };
            });

            services.AddAuthorization(auth =>
            {
                auth.AddPolicy(JwtBearerDefaults.AuthenticationScheme, new AuthorizationPolicyBuilder()
                               .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                               .RequireAuthenticatedUser().Build());
            });
            // Add framework services.
            services.AddMvc(options => { options.Filters.Add(new ApiExceptionFilter()); })
            .AddJsonOptions(o =>
            {
                o.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
            });
            ;
            services.AddNodeServices();

            // Register the Swagger generator, defining one or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Faisal League", Version = "v1"
                });
                c.OperationFilter <AuthorizationHeaderParameterOperationFilter>();
            });
        }
Esempio n. 11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(config => {
                config.Filters.Add <UnitOfWorkFilterAttribute>();
                config.Filters.Add <ExceptionFilter>();
            })
            .AddJsonOptions(o =>
            {
                o.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
            });

            ContainerSetup.Setup(services, Configuration);
            LogSecurityModule.Setup(services, Configuration);

            services.AddAuthentication(options => {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(jwtBearerOptions =>
            {
                jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateActor            = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = Configuration["Auth:Issuer"],
                    ValidAudience    = Configuration["Auth:Audience"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Auth:SecretKey"]))
                };
            });

            services.AddAuthorization(auth =>
            {
                auth.AddPolicy(JwtBearerDefaults.AuthenticationScheme, new AuthorizationPolicyBuilder()
                               .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                               .RequireAuthenticatedUser().Build());
            });
        }
Esempio n. 12
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            //IoC Setup
            ContainerSetup.Setup(services, Configuration);

            services.AddMvc(options => { options.Filters.Add(new ApiExceptionFilter()); options.RespectBrowserAcceptHeader = true; })
            .AddJsonOptions(o =>
            {
                // Newtonsoft JSON
                // o.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
                o.JsonSerializerOptions.Converters.Add(new DateTimeConverter());
            });


            services.AddLogging(config =>
            {
                config.AddDebug();
                config.AddConsole();
                //etc
            });
        }
Esempio n. 13
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationInsightsTelemetry(Configuration);
            ContainerSetup.Setup(services, Configuration);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, (option) =>
            {
                option.TokenValidationParameters = new TokenValidationParameters()
                {
                    IssuerSigningKey         = TokenAuthOption.Key,
                    ValidAudience            = TokenAuthOption.Audience,
                    ValidIssuer              = TokenAuthOption.Issuer,
                    ValidateIssuerSigningKey = true,
                    ValidateLifetime         = true,
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ClockSkew = TimeSpan.FromMinutes(0)
                };
            });

            services.AddAuthorization(auth =>
            {
                auth.AddPolicy(JwtBearerDefaults.AuthenticationScheme, new AuthorizationPolicyBuilder()
                               .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                               .RequireAuthenticatedUser().Build());
            });

            // Add framework services.
            //services.AddMvc(options => { options.Filters.Add(new ApiExceptionFilter()); })
            //    .AddJsonOptions(option =>
            //    {
            //        option.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
            //    });

            services.AddControllers();
        }
Esempio n. 14
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new ProjectMapping()); });

            IMapper mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);

            services.AddMvc(option => option.EnableEndpointRouting = false);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
            //services.AddMvc().AddFluentValidation(fv =>
            //{
            //    fv.RegisterValidatorsFromAssemblyContaining<InsertIndividualCommandValidator>();
            //    fv.RunDefaultMvcValidationAfterFluentValidationExecutes = false;
            //});


            // Register Swagger
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Sample API", Version = "version 1"
                });
                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    Description = @"JWT Authorization header using the Bearer scheme. \r\n\r\n 
                      Enter 'Bearer' [space] and then your token in the text input below.
                      \r\n\r\nExample: 'Bearer 12345abcdef'",
                    Name        = "Authorization",
                    In          = ParameterLocation.Header,
                    Type        = SecuritySchemeType.ApiKey,
                    Scheme      = "Bearer"
                });
                c.AddSecurityRequirement(new OpenApiSecurityRequirement()
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            },
                            Scheme = "oauth2",
                            Name   = "Bearer",
                            In     = ParameterLocation.Header,
                        },
                        new List <string>()
                    }
                });
            });

            services.AddCors(o => o.AddPolicy("MyPolicy", builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));
            //services.Configure<CloudinarySettings>(Configuration.GetSection("CloudinarySettings"));
            //services.AddScoped<UserRepository>();
            //services.AddScoped<PhotoRepository>();
            //services.AddScoped<IndividualRepository>();
            //services.AddScoped<RelationShipRepository>();
            //services.AddScoped<CountryRepository>();
            //services.AddScoped<LocationRepository>();
            //services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            //    .AddJwtBearer(options =>
            //    {
            //        options.TokenValidationParameters = new TokenValidationParameters
            //        {
            //            ValidateIssuerSigningKey = true,
            //            IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration.GetSection("AppSettings:Token").Value)),
            //            ValidateIssuer = false,
            //            ValidateAudience = false
            //        };
            //    });
            services.AddMediatR(Assembly.GetExecutingAssembly());
            services.AddScoped(typeof(RequestHandlerBase));
            ContainerSetup.Setup(services, Configuration);
        }
Esempio n. 15
0
 static IoC()
 {
     IoC.Container = ContainerSetup.Setup();
 }
Esempio n. 16
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //services.AddApplicationInsightsTelemetry(Configuration);

            ContainerSetup.Setup(services, Configuration);



            //services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, (o) =>
            //{
            //    o.TokenValidationParameters = new TokenValidationParameters()
            //    {
            //        IssuerSigningKey = TokenAuthOption.Key,
            //        ValidAudience = TokenAuthOption.Audience,
            //        ValidIssuer = TokenAuthOption.Issuer,
            //        ValidateIssuerSigningKey = true,
            //        ValidateLifetime = true,
            //        ValidateIssuer = true,
            //        ValidateAudience = true,
            //        ClockSkew = TimeSpan.FromMinutes(0)
            //    };
            //});
            //=============== NEW Support for SignaalR
            services.AddAuthentication(options =>
            {
                // Identity made Cookie authentication the default.
                // However, we want JWT Bearer Auth to be the default.
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options =>
            {
                // Configure JWT Bearer Auth to expect our security key
                options.TokenValidationParameters =
                    new TokenValidationParameters
                {
                    LifetimeValidator = (before, expires, token, param) =>
                    {
                        return(expires > GlobalSettings.CURRENT_DATETIME);
                    },
                    ValidateAudience = false,
                    ValidateIssuer   = false,
                    ValidateActor    = false,
                    ValidateLifetime = true,
                    IssuerSigningKey = TokenAuthOption.Key
                };

                // We have to hook the OnMessageReceived event in order to
                // allow the JWT authentication handler to read the access
                // token from the query string when a WebSocket or
                // Server-Sent Events request comes in.
                options.Events = new JwtBearerEvents
                {
                    OnMessageReceived = context =>
                    {
                        var accessToken = context.Request.Query["access_token"];

                        // If the request is for our hub...
                        var path = context.HttpContext.Request.Path;
                        if (!string.IsNullOrEmpty(accessToken) &&
                            (path.StartsWithSegments("/signalhub")))
                        {
                            // Read the token out of the query string
                            context.Token = accessToken;
                        }
                        return(Task.CompletedTask);
                    }
                };
            });
            //===============



            services.AddAuthorization(auth =>
            {
                auth.AddPolicy(JwtBearerDefaults.AuthenticationScheme, new AuthorizationPolicyBuilder()
                               .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                               .RequireAuthenticatedUser().Build());
            });
            // Add framework services.
            services.AddMvc(options => { options.Filters.Add(new ApiExceptionFilter()); })
            .AddJsonOptions(o =>
            {
                o.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
            });
            ;
            services.AddNodeServices();

            // Register the Swagger generator, defining one or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Faisal League", Version = "v1"
                });
                //c.AddAutoQueryable(); // add this line
                c.OperationFilter <AuthorizationHeaderParameterOperationFilter>();
                c.AddAutoQueryable(); // add this line

                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });

            services.AddElm();

            // for client
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });
        }