示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureContainer(ServiceRegistry services)
        {
            services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true);
            services.AddRazorPages();

            // Build authentication configuration. Can't use fluent syntax because we want to support running without configurations in place.
            var authBuilder = services.AddAuthentication();

            var googleOptions = Configuration.GetSection("Authentication:Google");

            if (googleOptions.Exists())
            {
                authBuilder.AddGoogle(configureOptions =>
                {
                    configureOptions.ClientId     = googleOptions["ClientId"];
                    configureOptions.ClientSecret = googleOptions["ClientSecret"];
                });
            }

            var microsoftOptions = Configuration.GetSection("Authentication:Microsoft");

            if (microsoftOptions.Exists())
            {
                authBuilder.AddMicrosoftAccount(configureOptions =>
                {
                    configureOptions.ClientId     = microsoftOptions["ClientId"];
                    configureOptions.ClientSecret = microsoftOptions["ClientSecret"];
                });
            }

            var twitterOptions = Configuration.GetSection("Authentication:Twitter");

            if (twitterOptions.Exists())
            {
                authBuilder.AddTwitter(configureOptions =>
                {
                    configureOptions.ConsumerKey         = twitterOptions["ConsumerKey"];
                    configureOptions.ConsumerSecret      = twitterOptions["ConsumerSecret"];
                    configureOptions.RetrieveUserDetails = true;
                });
            }

            // Load our custom services *after* Microsoft's so that our services win.

            // Bind options pattern classes.
            services.Configure <SendGridOptions>(Configuration.GetSection(SendGridOptions.SectionName));
            services.Configure <TwoFactorAuthenticationOptions>(Configuration.GetSection(TwoFactorAuthenticationOptions.SectionName));

            // Need to use a lamba to resolve the SqlConnection because trying to bind by type was going off into setter injection land.
            services.For <IDbConnection>().Use(_ => new SqlConnection(Configuration.GetConnectionString("DefaultConnection"))).Scoped();

            // Load Lamar registries in our DLLs. (These are our preferred way of resolving things that are not part of the framework; but anything
            // needing IConfiguration like above is more easily handled in this method.)
            services.Scan(s =>
            {
                s.AssembliesFromApplicationBaseDirectory(f => f?.FullName?.StartsWith("Fulgoribus.", StringComparison.OrdinalIgnoreCase) ?? false);

                s.LookForRegistries();
            });
        }
示例#2
0
        public void ConfigureContainer(ServiceRegistry registry)
        {
            var containerConfig = ContainerConfiguration.CreateFromAssembly(typeof(Startup).Assembly);

            ServiceProvisioningInitializer.PopulateRegistry(containerConfig, registry);

            var dropboxLocator = new Container(registry).GetService <IDropboxLocator>();
            var dropboxPath    = dropboxLocator.LocateDropboxPath();

            var completePath = Path.Combine(dropboxPath, "Apps", "LinkedInPoc", "Secrets.txt");
            var textLines    = File.ReadAllLines(completePath);

            registry.AddAuthentication(
                options =>
            {
                options.DefaultScheme          = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = "LinkedIn";
            })
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddLinkedIn("LinkedIn", options =>
            {
                options.ClientId     = textLines[0];
                options.ClientSecret = textLines[1];
                options.CallbackPath = new PathString("/signin-linkedin");

                options.SaveTokens = true;
                options.Scope.Clear();
                options.Scope.Add("r_liteprofile");
                options.Scope.Add("r_emailaddress");
                options.Scope.Add("w_member_social");

                options.Events.OnCreatingTicket = ticket =>
                {
                    // For some reason, HttpContext.GetTokenAsync("access_token") doesn't work;
                    LinkedInAccessTokenSingleton.Value = ticket.AccessToken;
                    return(Task.CompletedTask);
                };
            });

            registry.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             Configuration.GetConnectionString("DefaultConnection")));
            registry.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddEntityFrameworkStores <ApplicationDbContext>();
            registry.AddControllersWithViews();
            registry.AddRazorPages();
        }
示例#3
0
        public void ConfigureContainer(ServiceRegistry services)
        {
            services.AddLogging(config =>
            {
                config.ClearProviders();

                config.AddConfiguration(Configuration.GetSection("Logging"));
                config.AddApplicationInsights();
            });

            //Response Compression - https://docs.microsoft.com/en-us/aspnet/core/performance/response-compression?view=aspnetcore-5.0
            services.AddResponseCompression();

            services.AddCors(options =>
            {
                options.AddPolicy("SpecificOrigins",
                                  builder =>
                {
                    builder.WithOrigins("https://tmireact.azurewebsites.net", "https://theminiindex.com", "https://wwww.theminiindex.com", "http://localhost:3000")
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });

            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddSwaggerGen();

            services.AddDefaultIdentity <IdentityUser>()
            .AddRoles <IdentityRole>()
            .AddEntityFrameworkStores <MiniIndexContext>();

            services.AddHangfire(configuration => configuration
                                 .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
                                 .UseSimpleAssemblyNameTypeSerializer()
                                 .UseRecommendedSerializerSettings()
                                 .UseSqlServerStorage(Configuration.GetConnectionString("HangfireConnection"), new SqlServerStorageOptions
            {
                CommandBatchMaxTimeout       = TimeSpan.FromMinutes(5),
                SlidingInvisibilityTimeout   = TimeSpan.FromMinutes(5),
                QueuePollInterval            = TimeSpan.Zero,
                UseRecommendedIsolationLevel = true,
                DisableGlobalLocks           = true
            }));
            services.AddHangfireServer();

            services
            .AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
            .AddRazorOptions(ConfigureRazor);

            services.AddDbContext <MiniIndexContext>(ConfigureEntityFramework);

            string facebookAppId     = Configuration["Authentication:Facebook:AppId"];
            string facebookAppSecret = Configuration["Authentication:Facebook:AppSecret"];

            if (facebookAppId != null && facebookAppSecret != null)
            {
                services.AddAuthentication()
                .AddFacebook(facebookOptions =>
                {
                    facebookOptions.AppId     = facebookAppId;
                    facebookOptions.AppSecret = facebookAppSecret;
                });
            }

            services.AddTransient <IEmailSender, EmailSender>();
            services.Configure <AuthMessageSenderOptions>(Configuration);
            services.AddApplicationInsightsTelemetry();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <ITelemetryInitializer, TelemetryEnrichment>();
            services.AddApplicationInsightsTelemetryProcessor <AppInsightsFilter>();
            services.Configure <AzureStorageConfig>(Configuration.GetSection("AzureStorageConfig"));

            services.IncludeRegistry <CoreServices>();
            services.IncludeRegistry <WebAppServices>();
        }