Ejemplo 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.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);
        }
Ejemplo n.º 2
0
        // 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);
        }
Ejemplo n.º 3
0
 public HomeController(IHttpClientFactory httpClientFactory, IOptions <CanvasApiAuth> authOptions, ICourseUploadBLL courseUploadBll)
 {
     this.courseUploadBll = courseUploadBll;
     this.canvasClient    = httpClientFactory.CreateClient("CanvasClient");
     this.canvasApiAuth   = authOptions.Value;
 }
Ejemplo n.º 4
0
 public HomeController(IHttpClientFactory httpClientFactory, IOptions <CanvasApiAuth> authOptions)
 {
     this.canvasClient  = httpClientFactory.CreateClient("CanvasClient");
     this.canvasApiAuth = authOptions.Value;
 }