예제 #1
0
    public void ConfigureServices(IServiceCollection services)
    {
        var urlConfig = _config.GetSection("UrlConfig").Get <UrlConfig>();

        ConfigureDataProtection(services);

        services
        .Configure <EnvironmentConfig>(_config.GetSection("Environment"))
        .Configure <UploadConfig>(_config.GetSection("FileUpload"))
        .Configure <UrlConfig>(_config.GetSection("UrlConfig"))
        .AddMawCacheServices(_config["Environment:RedisConnectionString"])
        .AddMawDataServices(_config["Environment:DbConnectionString"])
        .AddSolrNet <MultimediaCategory>(_config["Search:CoreUrl"])
        .AddMawDomainServices()
        .AddMawApiServices()
        .AddScoped <ISearchService, SearchService>()
        .AddScoped <IContentTypeProvider, FileExtensionContentTypeProvider>()
        .AddResponseCompression()
        .AddControllers()
        .Services
        .AddSignalR()
        .Services
        .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        .AddJwtBearer(opts => ConfigureJwtBearerOptions(opts, urlConfig))
        .Services
        .AddAuthorization(opts => MawPolicyBuilder.AddMawPolicies(opts))
        .AddCors(opts => ConfigureDefaultCorsPolicy(opts, urlConfig))
        .AddOpenApiDocument(doc => ConfigureOpenApiDocumentOptions(doc));
    }
예제 #2
0
    public void ConfigureServices(IServiceCollection services)
    {
        var config = new Config(
            _config["Environment:WwwUrl"],
            _config["Environment:WwwClientSecret"],
            _config["Environment:PhotosUrl"],
            _config["Environment:FilesUrl"]);

        ConfigureDataProtection(services);

        services
        .Configure <IdentityOptions>(opts =>
        {
            opts.Password.RequiredLength      = 8;
            opts.Password.RequiredUniqueChars = 6;
        })
        .Configure <GmailApiEmailConfig>(_config.GetSection("Gmail"))
        .ConfigureMawTagHelpers(opts => {
            opts.AuthUrl = AddTrailingSlash(_config["Environment:AuthUrl"]);
            opts.WwwUrl  = AddTrailingSlash(_config["Environment:WwwUrl"]);
        })
        .AddMawDataServices(_config["Environment:DbConnectionString"])
        .AddMawDomainAuthServices()
        .AddMawIdentityServerServices(_config["Environment:IdsrvDbConnectionString"], _config["SigningCertDir"])
        .AddTransient <RazorViewToStringRenderer>()
        .AddIdentity <MawUser, MawRole>()
        .AddDefaultTokenProviders()
        .Services
        .ConfigureApplicationCookie(opts => ConfigureCookieOptions(opts))
        .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
        .AddGitHub(opts => ConfigureGithubAuthOptions(opts))
        .AddGoogle(opts => ConfigureGoogleAuthOptions(opts))
        .AddMicrosoftAccount(opts => ConfigureMicrosoftAuthOptions(opts))
        .AddTwitter(opts => ConfigureTwitterAuthOptions(opts))
        .Services
        .AddIdentityServer(opts =>
        {
            // we need to set this especially for dev otherwise the issuer becomes 10.0.2.2 when testing the android app
            opts.IssuerUri = _config["Environment:AuthUrl"];
        })
        .AddMawIdentityServerKeyMaterial(_config["SigningCertDir"])
        .AddInMemoryApiScopes(config.GetApiScopes())
        .AddInMemoryApiResources(config.GetApiResources())
        .AddInMemoryClients(config.GetClients())
        .AddInMemoryIdentityResources(config.GetIdentityResources())
        .AddAspNetIdentity <MawUser>()
        .AddProfileService <IdentityServerProfileService>()
        .Services
        .AddAuthorization(opts => MawPolicyBuilder.AddMawPolicies(opts))
        .AddCors(opts => ConfigureDefaultCorsPolicy(opts))
        .AddResponseCompression()
        .AddControllersWithViews();
    }
예제 #3
0
    public void ConfigureServices(IServiceCollection services)
    {
        JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

        var authConfig = _config.GetSection("AuthConfig").Get <AuthConfig>();

        ConfigureDataProtection(services);

        services
        .Configure <ContactConfig>(_config.GetSection("ContactUs"))
        .Configure <GmailApiEmailConfig>(_config.GetSection("Gmail"))
        .Configure <EnvironmentConfig>(_config.GetSection("Environment"))
        .Configure <GoogleCaptchaConfig>(_config.GetSection("GoogleRecaptcha"))
        .Configure <UrlConfig>(_config.GetSection("UrlConfig"))
        .ConfigureMawTagHelpers(opts =>
        {
            opts.AuthUrl = AddTrailingSlash(_config["UrlConfig:Auth"]);
            opts.WwwUrl  = AddTrailingSlash(_config["UrlConfig:Www"]);
        })
        .AddLogging()
        .AddHttpContextAccessor()
        .AddResponseCompression()
        .AddMawDataServices(_config["Environment:DbConnectionString"])
        .AddMawCacheServices(_config["Environment:RedisConnectionString"])
        .AddMawDomainServices()
        .AddTransient <RazorViewToStringRenderer>()
        .AddScoped <IContentTypeProvider, FileExtensionContentTypeProvider>()
        .AddSingleton <IFileProvider>(x => new PhysicalFileProvider(_config["Environment:AssetsPath"]))
        .AddAntiforgery(opts => opts.HeaderName = "X-XSRF-TOKEN")
        .AddAuthentication(opts => ConfigureAuthenticationOptions(opts))
        .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, opts => ConfigureCookieOptions(opts))
        .AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, opts => ConfigureOidcOptions(opts, authConfig))
        .Services
        .AddAuthorization(opts => MawPolicyBuilder.AddMawPolicies(opts))
        .AddCors(opts => ConfigureDefaultCorsPolicy(opts))
        .AddControllersWithViews();

        if (_env.IsDevelopment())
        {
            services.AddMiniProfiler();
        }
    }