// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy(name: MyAllowSpecificOrigins, builder => { builder.WithOrigins("*"); }); }); services.AddControllers(); String connectionString = Configuration.GetConnectionString("DefaultConnection"); services.AddDbContextPool <MainContext>( options => options.UseMySql(Configuration.GetConnectionString("DefaultConnection") )); services.AddScoped <IUserRepository, UserRepository>(); services.AddScoped <IPostRepository, PostRepository>(); services.AddScoped <IPostComment, PostComment>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = false, ValidateAudience = false, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"])), ClockSkew = TimeSpan.Zero }; }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); }
public void ConfigureServices(IServiceCollection services) { services.AddDbContext <RomiContext>(options => options.UseSqlServer(Configuration.GetConnectionString("RomiConnection"))); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"])), ClockSkew = TimeSpan.Zero }; services.AddCors(); }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); services.AddControllersWithViews(); services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"])), ClockSkew = TimeSpan.Zero // Override the default clock skew of 5 mins }; services.AddCors(); }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); services.AddControllersWithViews(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add Jwt Auth services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = false, ValidateAudience = false, ValidateLifetime = false, ValidateIssuerSigningKey = false, ValidIssuer = _configuration["Jwt:Issuer"], ValidAudience = _configuration["Jwt:Issuer"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["Jwt:SecretKey"])) }; }); // Add Auth Policies services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); // Auto Mapper services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); services.AddControllers(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddControllers().AddNewtonsoftJson(options => { options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }); services.AddDbContext <CeltisITContext>(opt => opt.UseSqlServer(Configuration["ConnectionStrings:CeltisIT"])); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"].ToString())), ClockSkew = TimeSpan.Zero }; }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); }
public void ConfigureServices(IServiceCollection services) { services.AddDbContext <MovieDBContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:DefaultConnection"])); services.AddTransient <IMovie, MovieDataAccessLayer>(); services.AddTransient <IUser, UserDataAccessLayer>(); services.AddTransient <IWatchlist, WatchlistDataAccessLayer>(); services.AddControllersWithViews(); services.AddRazorPages(); services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; }).AddCookie(options => { options.Cookie.Name = "authCookie"; }); services.AddAuthorization(config => { config.AddPolicy(UserRoles.Admin, Policies.AdminPolicy()); config.AddPolicy(UserRoles.User, Policies.UserPolicy()); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <EmployeeContext>(opts => opts.UseSqlServer(Configuration["ConnectionString:EmployeeDB"])); services.AddScoped <IDataRepository <Employee>, EmployeeManager>(); services.AddControllers(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"])), ClockSkew = TimeSpan.Zero }; }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); }
public static void AddJwtAuthentication(this IServiceCollection serviceCollection, string secretKey) { serviceCollection.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = false, ValidateAudience = false, ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey( Encoding.UTF8.GetBytes(secretKey)), ClockSkew = TimeSpan.Zero }; }); serviceCollection.AddAuthorization(config => { config.AddPolicy(UserRoles.Admin, Policies.AdminPolicy()); config.AddPolicy(UserRoles.User, Policies.UserPolicy()); }); }
private void ConfigureJsonWebToken(IServiceCollection services) { JwtOptions jwtOptions = Configuration.GetSection(JsonWebTokenSectionName).Get <JwtOptions>(); var tokenValidationParameters = new TokenValidationParameters() { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = jwtOptions.Issuer, ValidAudience = jwtOptions.Audience, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtOptions.SecretKey)), ClockSkew = TimeSpan.Zero }; services .AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = tokenValidationParameters; }); services .AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:ClaveSecreta"])), ClockSkew = TimeSpan.Zero }; }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); services.AddDbContext <LibraryDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddControllers(); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //services.AddControllers(); services.AddControllers(); services.Add(new ServiceDescriptor(typeof(AppDb), new AppDb(Configuration.GetConnectionString("DefaultConnection")))); services.AddTransient <AppDb>(_ => new AppDb(Configuration["ConnectionStrings:DefaultConnection"])); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"])), ClockSkew = TimeSpan.Zero }; }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); }
public static void ConfigureAuthentication(this IServiceCollection services, IConfiguration configuration) { services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = configuration["Jwt:Issuer"], ValidAudience = configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:SecretKey"])), ClockSkew = TimeSpan.Zero }; }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); services.AddSingleton <JwtTokenProvider>(); services.AddSingleton <IAuthenticationService, AuthenticationService>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddApplicationServices(Configuration); // Prevent Circle Problem In Entities services.AddControllers().AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); // Configure JWT services.AddAuthenticationService(Configuration); // Configure Authorization Policy services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "EliqIntegrationApp", Version = "v1" }); }); // Add CORS services.AddCors(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"])), ValidateIssuer = false, ValidateAudience = false, ValidateLifetime = true, ClockSkew = TimeSpan.Zero }; }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); services.AddCors(options => { options.AddPolicy("AllowAllOriginsPolicy", builder => { builder.AllowAnyOrigin(); }); }); }
public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add <App>("#app"); builder.Services.AddOptions(); builder.Services.AddAuthorizationCore(config => { config.AddPolicy(UserRoles.Admin, Policies.AdminPolicy()); config.AddPolicy(UserRoles.User, Policies.UserPolicy()); }); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); builder.Services.AddScoped <CustomAuthStateProvider>(); builder.Services.AddScoped <AuthenticationStateProvider>(provider => provider.GetRequiredService <CustomAuthStateProvider>()); builder.Services.AddScoped <AppStateContainer>(); builder.Services.AddBlazoredToast(); await builder.Build().RunAsync(); }
public static void PolicyAuthorization(this IServiceCollection services) { services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("ClientPermission", policy => { policy.SetIsOriginAllowed(origin => true) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); }); services.AddDbContext <ApplicationContext>(opt => opt.UseSqlServer (Configuration.GetConnectionString("ApiConnection"))); services.AddScoped <IEFRepository, SqlRepository>(); services.AddScoped <IUserService, UserService>(); services.AddScoped <ISlaMarkerService, SlaMarkerService>(); services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); services.AddControllers(); // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(); // Register the JwtBearer Authentication services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes( Configuration["Jwt:Key"])) }; }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); services.AddSignalR(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { ApplicationConfig config = new ApplicationConfig(Configuration); services.AddScoped(provider => config.DbContextConfiguration); services.AddDbContext <PizzaShopDbContext>((provider, builder) => { builder.UseSqlServer(provider.GetService <DbContextConfiguration>().ConnectionString); }); services.AddEntityFrameworkSqlServer(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"])), ClockSkew = TimeSpan.Zero }; services.AddCors(); }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.Client, Policies.UserPolicy()); }); services.AddScoped <IAccountRepository, AccountRepository>(); services.AddScoped <IAccountService, AccountService>(); services.AddScoped <IPizzaService, PizzaService>(); services.AddScoped <IPizzaRepository, PizzaRepository>(); services.AddScoped <IRepository <Pizza>, GenericRepository <Pizza> >(); services.AddScoped <IPizzaIngredientRepository, PizzaIngredientRepository>(); services.AddScoped <IRepository <Price>, GenericRepository <Price> >(); services.AddScoped <IRepository <Ingredient>, GenericRepository <Ingredient> >(); services.AddScoped <IIngredientService, IngredientSerivce>(); services.AddScoped <IRepository <Order>, GenericRepository <Order> >(); services.AddScoped <IOrderService, OrderService>(); services.AddScoped <IRepository <OrderPrice>, GenericRepository <OrderPrice> >(); services.AddControllersWithViews(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddDefaultIdentity <ApplicationUser>(options => { options.SignIn.RequireConfirmedAccount = false; options.Password.RequiredLength = 6; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; options.Password.RequireDigit = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequiredUniqueChars = 0; options.ClaimsIdentity.UserIdClaimType = "UserID"; }) .AddRoles <IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>(); services.AddAuthentication(options => { //options.DefaultAuthenticateScheme = "ClientCookie"; //options.DefaultSignInScheme = "ClientCookie"; //options.DefaultChallengeScheme = "Server"; }) .AddCookie("ClientCookie", options => options.SlidingExpiration = true) .AddJwtBearer("Server", options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = SD.Issuer, ValidAudience = SD.Audience, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(SD.SecretKey)), ClockSkew = TimeSpan.Zero }; }); services.AddAuthorization(options => { options.AddPolicy(Policies.User, Policies.UserPolicy()); options.AddPolicy(Policies.Admin, Policies.AdminPolicy()); options.AddPolicy(Policies.UserAndAdmin, Policies.UserAndAdminPolicy()); options.AddPolicy(Policies.Adult, Policies.AdultPolicy()); }); services.AddScoped <IAuthorizationHandler, AdultsOnlyHandler>(); services.AddScoped <IUnitOfWork, UnitOfWork>(); services.AddScoped <IDataService, DataService>(); services.AddScoped <IShopService, ShopService>(); services.AddControllersWithViews().AddRazorRuntimeCompilation(); }
public static void ConfigureAuthorization(this IServiceCollection services) { services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); config.FallbackPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build(); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddMvc().AddNewtonsoftJson(); services.AddIdentity <IdentityUser, IdentityRole>(options => { options.Password.RequireDigit = true; options.Password.RequireLowercase = true; options.Password.RequiredLength = 5; }).AddEntityFrameworkStores <MarketplaceDB>(); services.AddScoped <IJWTService, JWTService>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"])), ClockSkew = TimeSpan.Zero }; }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.Customer, Policies.CustomerPolicy()); config.AddPolicy(Policies.Seller, Policies.SellerPolicy()); }); services.AddDbContext <MarketplaceDB>( options => options.UseSqlServer(Configuration.GetConnectionString("MarketPlaceDatabase")) ); services.AddTransient <IMailService, MailService>(); services.AddScoped <ISellerService, SellerService>(); services.AddScoped <ICustomerService, CustomerService>(); services.AddScoped <IAdminService, AdminService>(); services.AddScoped <IImageService, ImageService>(); services.AddScoped <IEncryptService, EncryptService>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddDbContext <DezCablezDBContext>(opt => opt.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity <User, IdentityRole>(opt => { opt.Password.RequireDigit = false; opt.Password.RequiredLength = 6; opt.Password.RequiredUniqueChars = 0; opt.Password.RequireLowercase = false; opt.Password.RequireNonAlphanumeric = false; opt.Password.RequireUppercase = false; }) .AddEntityFrameworkStores <DezCablezDBContext>() .AddDefaultTokenProviders(); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { options.SaveToken = true; options.RequireHttpsMetadata = false; options.TokenValidationParameters = new TokenValidationParameters() { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidAudience = Configuration["JwtOptions:Audience"], ValidIssuer = Configuration["JwtOptions:Issuer"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JwtOptions:Secret"])), ClockSkew = TimeSpan.Zero }; services.AddCors(); }); services.AddAutoMapper(typeof(Startup)); services.AddTransient <IItemService, ItemService>(); services.AddTransient <IUserService, UserService>(); services.AddTransient <IImageService, ImageService>(); services.AddTransient <IOrderService, OrderService>(); services.AddTransient <IAddressService, AddressService>(); services.AddAuthorization(conf => { conf.AddPolicy(Policies.Admin, Policies.AdminPolicy()); conf.AddPolicy(Policies.User, Policies.UserPolicy()); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(c => { c.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin()); }); services.Configure <FormOptions>(o => { o.ValueLengthLimit = int.MaxValue; o.MultipartBodyLengthLimit = int.MaxValue; o.MemoryBufferThreshold = int.MaxValue; }); services.AddControllers(); services.AddEntityFrameworkSqlServer(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"])), ClockSkew = TimeSpan.Zero // Override the default clock skew of 5 mins }; services.AddCors(); }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); services.AddControllersWithViews(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); services.AddTransient <IDashboardService, DashboradService>(); services.AddTransient <IProducaoService, ProducaoService>(); services.AddTransient <IVendaService, VendaService>(); services.AddTransient <DataBaseContext, DataBaseContext>(); services.AddTransient <IClienteService, ClienteService>(); services.AddTransient <IUsuarioService, UsuarioService>(); }
/// <summary> /// AddAuthorizationConfiguring method /// </summary> /// <param name="services"></param> public static void AddAuthorizationConfiguring(this IServiceCollection services) { services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.Decadev, Policies.DecadevPolicy()); config.AddPolicy(Policies.Vendor, Policies.VendorPolicy()); config.AddPolicy(Policies.FacilityManager, Policies.FacilityPolicy()); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <mysiteContext>(options => options.UseSqlServer(Configuration.GetConnectionString("mysitedb"))); services.AddControllers().AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore );; services.AddHttpContextAccessor(); services.AddControllersWithViews(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"])), ClockSkew = TimeSpan.Zero }; }); services.AddCors(); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.Customer, Policies.CustomerPolicy()); }); services.AddDistributedSqlServerCache(options => { options.ConnectionString = Configuration.GetConnectionString("mysitedb");//"Server =BEAST; Database = mysite; Trusted_Connection = true"; options.SchemaName = "dbo"; options.TableName = "SessionData"; }); services.AddSession(options => { options.Cookie.Name = "KhalisStore.Session"; options.IdleTimeout = System.TimeSpan.FromHours(48); options.Cookie.HttpOnly = false; options.Cookie.IsEssential = true; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().AddJsonOptions(o => { o.JsonSerializerOptions.PropertyNamingPolicy = null; o.JsonSerializerOptions.DictionaryKeyPolicy = null; }); AddDbContext(services); services.AddAutoMapper(Assembly.GetExecutingAssembly()); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"])), ClockSkew = TimeSpan.Zero // Override the default clock skew of 5 mins }; services.AddCors(); }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.AdvancedUser, Policies.AdvancedUserPolicy()); config.AddPolicy(Policies.BasicUser, Policies.BasicUserPolicy()); }); services.AddControllersWithViews(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); services.RegisterAssemblyPublicNonGenericClasses( AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(d => d.ManifestModule.Name.Equals("WatchmanWeb.dll")) ) .Where(x => x.Name.EndsWith("Repository") || x.Name.EndsWith("Service")) .AsPublicImplementedInterfaces(); services.AddScoped <ISmsService, SmsService>(); services.AddTransient <IDatabaseInitializer, DatabaseInitializer>(); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["JWT: Issuer"], ValidAudience = Configuration["Jwt: Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt: SecretKey"])), ClockSkew = TimeSpan.Zero }; }); services.AddDbContext <Context>(options => options.UseNpgsql(Configuration.GetConnectionString("DbConnection"))); // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "ToDo API", Description = "A simple example ASP.NET Core Web API", TermsOfService = new Uri("https://example.com/terms"), Contact = new OpenApiContact { Name = "bleble", Email = "*****@*****.**", Url = new Uri("https://www.zedotech.com"), }, License = new OpenApiLicense { Name = "Use under LICX", Url = new Uri("https://example.com/license"), } }); }); //Autho services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); //Declare DI /*services.AddTransient<UserManager<User>, UserManager<User>>(); * services.AddTransient<SignInManager<User>, SignInManager<User>>(); * services.AddTransient<RoleManager<Role>, RoleManager<Role>>();*/ }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { 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; }); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); services.AddCors(); services.AddAutoMapper(typeof(StudyRepository).Assembly); services.AddControllers(); services.AddControllers().AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; }); services.AddControllers().AddNewtonsoftJson(); services.AddDbContext <ScientificStudiesRecordDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"))); services.AddScoped <IUserRepository, UserRepository>(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration.GetSection("Jwt:SecretKey").Value)), ClockSkew = TimeSpan.Zero }; }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); }); services.AddScoped <IExperimentRepository, ExperimentRepository>(); services.AddScoped <IGroupRepository, GroupRepository>(); services.AddScoped <IStudyRepository, StudyRepository>(); services.AddScoped <ITaskRepository, TaskRepository>(); services.AddScoped <ITestSubjectRepository, TestSubjectRepository>(); services.AddScoped <IUnitOfWork, UnitOfWork>(); }
public void ConfigureServices(IServiceCollection services) { JWTConfig jwtConfig = new JWTConfig() //Zrób to inaczej { AccessTokenExpiration = Convert.ToInt32(Environment.GetEnvironmentVariable("JwtAccessTokenExpiration")), RefreshTokenExpiration = Convert.ToInt32(Environment.GetEnvironmentVariable("JwtRefreshTokenExpiration")), Issuer = Environment.GetEnvironmentVariable("JwtIssuer"), Audience = Environment.GetEnvironmentVariable("JwtAudience"), Secret = Environment.GetEnvironmentVariable("JwtSecret") }; services.AddControllers(); services.AddDbContext <Context>(opt => opt.UseSqlite("Data Source=gameweb.db")); services.AddScoped <IGamesRepository, GamesRepository>(); services.AddScoped <IUsersRepository, UsersRepository>(); services.AddScoped <IGameGenresRepository, GameGenresRepository>(); services.AddScoped <IDevelopersRepository, DevelopersRepository>(); services.AddSwaggerGen(c => { var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); services.AddScoped <IAuthService, AuthService>(); services.AddSingleton <JWTConfig>(jwtConfig); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = jwtConfig.Issuer, ValidAudience = jwtConfig.Audience, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtConfig.Secret)), ClockSkew = TimeSpan.Zero }; }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.User, Policies.UserPolicy()); config.AddPolicy(Policies.Mod, Policies.ModPolicy()); config.AddPolicy(Policies.RefreshToken, Policies.RefreshTokenPolicy()); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Inject AppSettings services.Configure <ApplicationSettings>(Configuration.GetSection("ApplicationSettings")); services.AddControllers(); services.AddDbContext <StoreContext>(options => options.UseSqlServer(Configuration.GetConnectionString("IdentityConnection"))); services.AddCors(); // Add Repository services.AddScoped <AddressRepository>(); services.AddScoped <ApplicationUserRepository>(); services.AddScoped <OrderProductRepository>(); services.AddScoped <OrderRepository>(); services.AddScoped <ProductRepository>(); //Jwt Authentication var key = Encoding.UTF8.GetBytes(Configuration["ApplicationSettings:JWT_Secret"].ToString()); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = false; x.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateIssuer = false, ValidateAudience = false, ClockSkew = TimeSpan.Zero }; }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.Employee, Policies.EmployeePolicy()); config.AddPolicy(Policies.Customer, Policies.CustomerPolicy()); }); // This service fixes an error i get when i try to include in entity framework. MESSAGE ERROR: System.Text.Json.JsonException: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32. at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializerCycleDetected(Int32 maxDepth) at System.Text.Json.JsonSerializer.Write(Utf8JsonWriter writer, Int32 originalWriterDepth, Int32 flushThreshold, JsonSerializerOptions options, WriteStack& state) services.AddControllers().AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore ); }