Ejemplo n.º 1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var cerificateThumbprint   = CloudConfigurationManager.GetSetting(Constants.KeyVaultAuthCertThumbprintSetting);
            var authenticationClientId = CloudConfigurationManager.GetSetting(Constants.KeyVaultAuthClientIdSetting);

            var certificate   = CertificateHelper.FindCertificateByThumbprint(cerificateThumbprint);
            var assertionCert = new ClientAssertionCertificate(authenticationClientId, certificate);

            // initializes configuration manager with key vault authentication and the secret cache default timespan
            ConfigurationManager.Initialize(
                new KeyVaultClient.AuthenticationCallback(
                    (authority, resource, scope) => GetAccessToken(authority, resource, scope, assertionCert)),
                Constants.KeyVaultSecretCacheDefaultTimeSpan);

            RoleEnvironment.Changed += RoleEnvironment_Changed;
        }