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)
        {
            var authSettings = Configuration.GetSection("AuthSettings").Get <AuthSettings>();

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
#if (DEBUG)
                options.RequireHttpsMetadata = false;
#endif
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    // укзывает, будет ли валидироваться издатель при валидации токена
                    ValidateIssuer = true,
                    // строка, представляющая издателя
                    ValidIssuer = authSettings.Issuer,
                    // будет ли валидироваться потребитель токена
                    ValidateAudience = false,
                    // установка потребителя токена
                    ValidAudience = authSettings.GetAudience(),
                    // будет ли валидироваться время существования
                    ValidateLifetime = true,
                    // установка ключа безопасности
                    IssuerSigningKey = authSettings.GetSymmetricSecurityKey(),
                    // валидация ключа безопасности
                    ValidateIssuerSigningKey = true,
                    //
                    ClockSkew = authSettings.GetClockCrew()
                };
            });

            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
            .AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            //services.AddDistributedMemoryCache();

            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });

            services.Configure <AuthSettings>(Configuration.GetSection("AuthSettings"));
            services.Configure <ServerSettings>(Configuration.GetSection("PilotServer"));
            services.Configure <AppSettings>(Configuration.GetSection("AppSettings"));
            services.AddSingleton <IConnectionService, ConnectionService>();
            services.AddSingleton <IRemoteServiceFactory, RemoteServiceFactory>();
            services.AddSingleton <IContextService, ContextService>();
            services.AddSingleton <IIdleSessionTimeoutProvider, IdleSessionTimeoutProvider>();
            services.AddScoped <IDocumentConverterFactory, DocumentConverterFactory>();
            services.AddScoped <IDocumentRender, DocumentRender.DocumentRender>();
            services.AddScoped <IFileSaver, FileSaver>();
            services.AddScoped <IFilesStorage, FilesStorage>();
            services.AddScoped <IFilesOperationService, FilesOperationService>();
            services.AddScoped <IFileStorageDirectoryProvider, FileStorageDirectoryProvider>();
            services.AddScoped <IFileDownloadService, FileDownloadService>();
            services.AddSingleton <IFileStorageProvider>(new FileStorageProvider(DirectoryProvider.GetTempPath()));
        }