// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
            services.AddMvc();

            services.AddCors(options =>
            {
                options.AddDefaultPolicy(
                    builder =>
                {
                    builder.WithOrigins("http://localhost:4200", "https://netcoreauth.web.app")
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });

            services.AddControllers();

            var key = Path.Combine(Directory.GetCurrentDirectory(), "key", "firebase_netcoreauth.json");

            var registerService = DiRegisterServices.GetServiceList();

            foreach (var item in registerService)
            {
                services.AddScoped(item.GetInterface(), item.GetClass());
            }

            string value = Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS");

            //var defaultApp = FirebaseApp.Create(new AppOptions()
            //{
            //    Credential = GoogleCredential.GetApplicationDefault(),
            //});

            FirebaseApp.Create(new AppOptions
            {
                Credential = GoogleCredential.FromFile(key)
            });

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                var firebaseProjectName           = Configuration["FirebaseProjectName"];
                options.Authority                 = "https://securetoken.google.com/" + firebaseProjectName;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer   = true,
                    ValidIssuer      = "https://securetoken.google.com/" + firebaseProjectName,
                    ValidateAudience = true,
                    ValidAudience    = firebaseProjectName,
                    ValidateLifetime = true
                };
                options.RequireHttpsMetadata = false;
            });

            services.AddDbContext <DB_Context>(options =>
                                               options.UseSqlServer(Configuration.GetConnectionString("CS_AA_Challenge")));
        }
Exemple #2
0
        public static void RegisterTypes(IUnityContainer container)
        {
            var registerService = DiRegisterServices.GetServiceList();

            foreach (var item in registerService)
            {
                container.RegisterType(item.GetInterface(), item.GetClass());
            }
        }