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)
        {
            //Adding the Azure AD integration for User authentication
            services.AddAuthentication(sharedOptions =>
            {
                sharedOptions.DefaultScheme          = CookieAuthenticationDefaults.AuthenticationScheme;
                sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
            })
            .AddAzureAd(options => Configuration.Bind("AzureAd", options))
            .AddCookie();

            services.AddMvc();

            //Add the Key Vault Service Client Connection to the Context Object
            AKVServiceClient servClient = new AKVServiceClient(Configuration["AzureKeyVault:ClientIdWeb"],
                                                               Configuration["AzureKeyVault:AuthCertThumbprint"], Configuration["AzureKeyVault:VaultName"],
                                                               Configuration["AzureKeyVault:KeyName"]);

            services.AddSingleton <AKVServiceClient>(servClient);

            //Get the Connection string to Azure SQL Database from Azure Key Vault Secret
            string connection = servClient.GetDbConnectionString();

            //Add the Azure SQL Database connection to the Context Object
            services.AddDbContext <ContosoinsauthdbContext>(options => options.UseSqlServer(connection));

            services.AddOptions();
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(sharedOptions =>
            {
                sharedOptions.DefaultScheme          = CookieAuthenticationDefaults.AuthenticationScheme;
                sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
            })
            .AddAzureAdB2C(options => Configuration.Bind("AzureAdB2C", options))
            .AddCookie();

            services.AddMvc();

            var clientId             = Configuration["AzureKeyVault:ClientIdWeb"];
            var cerificateThumbprint = Configuration["AzureKeyVault:AuthCertThumbprint"];


            AKVServiceClient servClient = new AKVServiceClient(Configuration["AzureKeyVault:ClientIdWeb"],
                                                               Configuration["AzureKeyVault:AuthCertThumbprint"], Configuration["AzureKeyVault:VaultName"],
                                                               Configuration["AzureKeyVault:KeyName"]);


            services.AddSingleton <AKVServiceClient>(servClient);
            string connection = servClient.GetDbConnectionString();

            services.AddDbContext <ContosoinsauthdbContext>(options => options.UseSqlServer(connection));

            services.AddOptions();
        }
Ejemplo n.º 3
0
 public ValidationController(ContosoinsauthdbContext context, AKVServiceClient akvclient)
 {
     _context   = context;
     _akvclient = akvclient;
 }
 public VehiclePoliciesController(ContosoinsauthdbContext context, AKVServiceClient akvclient)
 {
     _context   = context;
     _akvclient = akvclient;
 }