Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var contentRoot = Path.Combine(
                Configuration.GetValue <string>(WebHostDefaults.ContentRootKey),
                CurrentEnvironment.IsDevelopment()
                    ? "DevResources"
                    : "Resources"
                );

            var secretsFilePath = Path.Combine(contentRoot, "secrets.json");
            var secretsProvider = DefaultSecretsProvider.LoadFromFile(secretsFilePath);

            services.AddSingleton <IConfigProvider>(new DefaultConfigProvider(contentRoot, secretsProvider));

            var clientsFile     = Path.Combine(contentRoot, "clients.json");
            var clientsProvider = new FileBasedClientsProvider(clientsFile);

            services.AddSingleton <IClientsProvider>(clientsProvider);
            services.AddSingleton <IAuthorizationService>(new AuthorizationService(clientsProvider));


            services.AddAuthentication()
            .AddScheme <AuthenticationSchemeOptions, DefaultBasicIdentityService>(
                BasicAuthSchemaName.Name, null);

            services.AddUrlBasedHttpMetrics();

            services.AddControllers(opt => opt.AddExceptionProcessing());
            services.AddRazorPages();
        }
        public void ShouldApplySecrets()
        {
            //Arrange
            var secretProvider = new DefaultSecretsProvider("[{ \"key\": \"some-secret\", \"value\": \"some-val\" }]");
            var config         = ConfigDocument.Load("{\"secret\":\"[secret:some-secret]\"}");

            //Act
            config.ApplySecrets(secretProvider);

            //Assert
            Assert.Equal("{\"secret\":\"some-val\"}", config.Serialize(false));
        }