Example #1
0
        private static IServiceCollection AddSecurityForUI(this IServiceCollection services, BaseStartup startup)
        {
            var config = OptionsHelper.GetConfiguration <SecurityUIOptions>(startup.Configuration);

            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

            services.AddAuthentication(options =>
            {
                options.DefaultScheme          = "Cookies";
                options.DefaultChallengeScheme = "oidc";
            })
            .AddCookie("Cookies")
            .AddOpenIdConnect("oidc", options =>
            {
                options.SignInScheme = "Cookies";

                options.Authority            = config.Authority;
                options.RequireHttpsMetadata = false;

                options.ClientId     = config.ClientId;
                options.ClientSecret = config.ClientSecret;
                options.ResponseType = "code id_token";

                options.SaveTokens = true;
                options.GetClaimsFromUserInfoEndpoint = true;

                foreach (var item in config.Scopes)
                {
                    options.Scope.Add(item);
                }
            });

            return(services);
        }
Example #2
0
        public void GetConfiguration_Success()
        {
            var teste = OptionsHelper.GetConfiguration <TestOptions>(Configuration);

            Assert.AreEqual("string", teste.OptionString);
            Assert.AreEqual(999, teste.OptionInteger);
            Assert.AreEqual(true, teste.OptionBoolean);
            Assert.AreEqual(99.1, teste.OptionDouble);
        }
Example #3
0
        private static IServiceCollection AddSecurityForAPI(this IServiceCollection services, BaseStartup startup)
        {
            var config = OptionsHelper.GetConfiguration <SecurityApiOptions>(startup.Configuration);

            services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
            .AddIdentityServerAuthentication(options =>
            {
                options.Authority            = config.Authority;
                options.RequireHttpsMetadata = false;
                options.ApiName   = config.ApiName;
                options.ApiSecret = config.ApiSecret;
            });

            return(services);
        }
Example #4
0
        /// <summary>
        /// Configura os valores padrões para as chaves de configuração do sistema.
        /// </summary>
        /// <param name="services">Configurador de serviços da aplicação web.</param>
        /// <param name="configuration">Configuração de inicilização.</param>
        /// <returns>Configurador de serviços da aplicação web.</returns>
        public static IServiceCollection AddLog(this IServiceCollection services, IConfiguration configuration)
        {
            var config = OptionsHelper.GetConfiguration <StackdriverOptions>(configuration);

            services.AddGoogleExceptionLogging(options =>
            {
                options.ProjectId   = config.ProjectId;
                options.ServiceName = ApplicationHelper.Name();
                options.Version     = ApplicationHelper.Version();
            });

            services.AddGoogleTrace(options =>
            {
                options.ProjectId = config.ProjectId;
            });

            return(services);
        }
Example #5
0
        /// <summary>
        /// Configura os valores padrões para as chaves de configuração do sistema.
        /// </summary>
        /// <param name="services">Configurador de serviços da aplicação web.</param>
        /// <param name="startup">Inicializador da hospedagem.</param>
        /// <returns>Configurador de serviços da aplicação web.</returns>
        public static IServiceCollection AddRepositories(this IServiceCollection services, BaseStartup startup)
        {
            var all = ReflectionHelper.ListClassesInheritFromGeneric(typeof(MongoRepository <>));

            var mongoOptions = Options.Create(OptionsHelper.GetConfiguration <MongoOptions>(startup.Configuration));

            var provider = new MongoDatabaseProvider(mongoOptions);

            foreach (var item in all)
            {
                services.AddSingleton(item);

                var nameMethod = item.GetMethod("CreateIndexes");

                nameMethod.Invoke(Activator.CreateInstance(item, provider, null), null);
            }

            return(services);
        }
Example #6
0
        static MongoRepositoryTest()
        {
            MongoOptions = OptionsHelper.GetConfiguration <MongoOptions>(Configuration);

            MongoOptions.DatabaseName = GetUniqueName(MongoOptions.DatabaseName);
        }
Example #7
0
 public void GetConfiguration_Null_Throw_Exception()
 {
     OptionsHelper.GetConfiguration <TestOptions>(null);
 }
Example #8
0
 public MongoDatabaseProviderTest()
 {
     _options = OptionsHelper.GetConfiguration <MongoOptions>(Configuration);
 }