// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <CourseActivityContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); CanvasOAuth canvasOAuth = new CanvasOAuth(); var canvasOAuthSection = Configuration.GetSection(nameof(CanvasOAuth)); canvasOAuthSection.Bind(canvasOAuth); services.Configure <CanvasOAuth>(canvasOAuthSection); CanvasApiAuth apiAuth = new CanvasApiAuth(); var canvasApiAuthSection = Configuration.GetSection(nameof(CanvasApiAuth)); canvasApiAuthSection.Bind(apiAuth); services.Configure <CanvasApiAuth>(canvasApiAuthSection); services.AddHttpClient("CanvasClient", client => { client.BaseAddress = new Uri(apiAuth.BaseUrl); client.DefaultRequestHeaders.Add("Accept", "application/json"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiAuth.ApiKey); }); services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; }).AddCookie(options => { options.AccessDeniedPath = "/Home/AccessDenied"; options.LoginPath = "/login"; options.LogoutPath = "/signout"; }).AddCanvas(options => { options.UserInformationEndpoint = canvasOAuth.BaseUrl; options.AuthorizationEndpoint = canvasOAuth.AuthorizationEndpoint; options.TokenEndpoint = canvasOAuth.TokenEndpoint; options.ClientId = canvasOAuth.ClientId; options.ClientSecret = canvasOAuth.ClientSecret; options.ApiToken = apiAuth.ApiKey; }); 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; }); // BLLs services.AddScoped <ICourseUploadBLL, CourseUploadBLL>(); // Repository services.AddScoped <ICourseUploadRepository, CourseUploadRepository>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { CanvasOAuth canvasOAuth = new CanvasOAuth(); var canvasOAuthSection = Configuration.GetSection(nameof(CanvasOAuth)); canvasOAuthSection.Bind(canvasOAuth); services.Configure <CanvasOAuth>(canvasOAuthSection); CanvasApiAuth apiAuth = new CanvasApiAuth(); var canvasApiAuthSection = Configuration.GetSection(nameof(CanvasApiAuth)); canvasApiAuthSection.Bind(apiAuth); services.Configure <CanvasApiAuth>(canvasApiAuthSection); services.AddHttpClient("CanvasClient", client => { client.BaseAddress = new Uri(apiAuth.BaseUrl); client.DefaultRequestHeaders.Add("Accept", "application/json"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiAuth.ApiKey); }); services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; }).AddCookie(options => { options.AccessDeniedPath = "/Home/AccessDenied"; options.LoginPath = "/login"; options.LogoutPath = "/signout"; }).AddCanvas(options => { options.UserInformationEndpoint = canvasOAuth.BaseUrl; options.AuthorizationEndpoint = canvasOAuth.AuthorizationEndpoint; options.TokenEndpoint = canvasOAuth.TokenEndpoint; options.ClientId = canvasOAuth.ClientId; options.ClientSecret = canvasOAuth.ClientSecret; options.ApiToken = apiAuth.ApiKey; }); services.Configure <CookiePolicyOptions>(options => { options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }