Ejemplo n.º 1
0
        /// <summary>
        /// Configures a Microsoft SQL Server Storage implementation of <see cref="IWebHookStore"/>
        /// which provides a persistent store for registered WebHooks used by the custom WebHooks module.
        /// </summary>
        /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
        /// <param name="encryptData">Indicates whether the data should be encrypted using <see cref="IDataProtector"/> while persisted.</param>
        public static void InitializeCustomWebHooksSqlStorage(this HttpConfiguration config, bool encryptData)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            WebHooksConfig.Initialize(config);

            ILogger            logger   = config.DependencyResolver.GetLogger();
            SettingsDictionary settings = config.DependencyResolver.GetSettings();

            // We explicitly set the DB initializer to null to avoid that an existing DB is initialized wrongly.
            Database.SetInitializer <WebHookStoreContext>(null);

            IWebHookStore store;

            if (encryptData)
            {
                IDataProtector protector = DataSecurity.GetDataProtector();
                store = new SqlWebHookStore(settings, protector, logger);
            }
            else
            {
                store = new SqlWebHookStore(settings, logger);
            }
            CustomServices.SetStore(store);
        }
        /// <summary>
        /// Configures a Microsoft Azure Table Storage implementation of <see cref="IWebHookStore"/>
        /// which provides a persistent store for registered WebHooks used by the custom WebHooks module.
        /// </summary>
        /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
        /// <param name="encryptData">Indicates whether the data should be encrypted using <see cref="IDataProtector"/> while persisted.</param>
        public static void InitializeCustomWebHooksAzureStorage(this HttpConfiguration config, bool encryptData)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            WebHooksConfig.Initialize(config);

            ILogger            logger   = config.DependencyResolver.GetLogger();
            SettingsDictionary settings = config.DependencyResolver.GetSettings();

            IStorageManager storageManager = StorageManager.GetInstance(logger);
            IWebHookStore   store;

            if (encryptData)
            {
                IDataProtector protector = DataSecurity.GetDataProtector();
                store = new AzureWebHookStore(storageManager, settings, protector, logger);
            }
            else
            {
                store = new AzureWebHookStore(storageManager, settings, logger);
            }
            CustomServices.SetStore(store);
        }
Ejemplo n.º 3
0
        public ReceiverServicesTests()
        {
            HttpConfiguration config = new HttpConfiguration();

            WebHooksConfig.Initialize(config);
            ReceiverServices.Reset();
        }
 public DependencyScopeExtensionsTests()
 {
     _resolverMock = new Mock <IDependencyScope>();
     _config       = new HttpConfiguration();
     WebHooksConfig.Initialize(_config);
     ReceiverServices.Reset();
 }
        public void GetFilterManager_ReturnsDefaultInstance_IfNoneRegistered()
        {
            // Arrange
            WebHooksConfig.Initialize(_config);

            // Act
            IWebHookFilterManager actual = _resolverMock.Object.GetFilterManager();

            // Assert
            Assert.IsType <WebHookFilterManager>(actual);
        }
        public void GetFilterProviders_ReturnsSameInstances_IfNoneRegistered()
        {
            // Arrange
            WebHooksConfig.Initialize(_config);

            // Act
            IEnumerable <IWebHookFilterProvider> actual1 = _resolverMock.Object.GetFilterProviders();
            IEnumerable <IWebHookFilterProvider> actual2 = _resolverMock.Object.GetFilterProviders();

            // Assert
            Assert.Same(actual1, actual2);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Configures an EPiServer DDS Storage implementation of <see cref="IWebHookStore"/>
        /// </summary>
        /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
        public static void InitializeCustomWebHooksEPiServerStorage(this HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            WebHooksConfig.Initialize(config);
            ILogger         logger         = config.DependencyResolver.GetLogger();
            IStorageManager storageManager = new StorageManager(logger);
            IWebHookStore   store          = new EpiWebHookStore(storageManager, logger);

            CustomServices.SetStore(store);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes support for receiving MyGet WebHooks.
        /// A sample WebHook URI is '<c>https://&lt;host&gt;/api/webhooks/incoming/myget/{id}?code=83699ec7c1d794c0c780e49a5c72972590571fd8</c>'.
        /// For security reasons the WebHook URI must be an <c>https</c> URI and contain a 'code' query parameter with the
        /// same value as configured in the '<c>MS_WebHookReceiverSecret_MyGet</c>' application setting.
        /// The 'code' parameter must be between 32 and 128 characters long.
        /// For details about MyGet WebHooks, see <c>http://docs.myget.org/docs/reference/webhooks</c>.
        /// </summary>
        /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
        public static void InitializeReceiveMyGetWebHooks(this HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            WebHooksConfig.Initialize(config);

            // Register media type with JSON formatter
            MediaTypeHeaderValue mediaType = MediaTypeHeaderValue.Parse(MyGetWebHookReceiver.MediaType);

            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(mediaType);
        }
        /// <summary>
        /// Initializes support for receiving Stripe WebHooks without any follow-up HTTP GET request to get the WebHook data.
        /// A sample WebHook URI is '<c>https://&lt;host&gt;/api/webhooks/incoming/stripe/{id}?code=83699ec7c1d794c0c780e49a5c72972590571fd8</c>'.
        /// For security reasons the WebHook URI must be an <c>https</c> URI and contain a 'code' query parameter with the
        /// same value as configured in the '<c>MS_WebHookReceiverSecret_Stripe</c>' application setting.
        /// The 'code' parameter must be between 32 and 128 characters long.
        /// For details about Stripe WebHooks, see <c>https://stripe.com/docs/webhooks</c>.
        /// </summary>
        /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
        public static void InitializeReceiveStripeDirectWebHooks(this HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            // Enable direct mode
            IDependencyResolver resolver = config.DependencyResolver;
            SettingsDictionary  settings = resolver.GetSettings();

            settings[StripeWebHookReceiver.DirectWebHook] = bool.TrueString;

            WebHooksConfig.Initialize(config);
        }
        /// <summary>
        /// Configures a Microsoft Azure Table Storage implementation of <see cref="IWebHookStore"/>
        /// which provides a persistent store for registered WebHooks used by the custom WebHooks module.
        /// </summary>
        /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
        public static void InitializeCustomWebHooksAzureQueueSender(this HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            WebHooksConfig.Initialize(config);

            ILogger            logger   = config.DependencyResolver.GetLogger();
            SettingsDictionary settings = config.DependencyResolver.GetSettings();

            IStorageManager storageManager = StorageManager.GetInstance(logger);
            IWebHookSender  sender         = new AzureWebHookSender(storageManager, settings, logger);

            CustomServices.SetSender(sender);
        }
Ejemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="config"></param>
        public static void InitializeAuthenticatedWebHooksSender(this HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            WebHooksConfig.Initialize(config);

            ILogger    logger = config.DependencyResolver.GetLogger();
            HttpClient client = config.DependencyResolver.GetService <HttpClient>();

            // setting the custom sender
            IWebHookSender sender = new AuthorizedWebHookSender(logger, client);

            CustomServices.SetSender(sender);
        }
        public WebHookReceiverManager(SecretManager secretManager)
        {
            _httpConfiguration = new HttpConfiguration();

            var builder = new ContainerBuilder();

            builder.RegisterInstance <IWebHookHandler>(new DelegatingWebHookHandler());
            builder.RegisterInstance <IWebHookReceiverConfig>(new DynamicWebHookReceiverConfig(secretManager));
            var container = builder.Build();

            WebHooksConfig.Initialize(_httpConfiguration);

            _httpConfiguration.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            IEnumerable <IWebHookReceiver> receivers = _httpConfiguration.DependencyResolver.GetReceivers();

            _receiverLookup = receivers.ToDictionary(p => p.Name, p => p, StringComparer.OrdinalIgnoreCase);
        }
Ejemplo n.º 13
0
        public WebHookReceiverManager(TraceWriter trace)
        {
            _trace             = trace;
            _httpConfiguration = new HttpConfiguration();

            var     builder = new ContainerBuilder();
            ILogger logger  = new WebHookLogger(_trace);

            builder.RegisterInstance <ILogger>(logger);
            builder.RegisterInstance <IWebHookHandler>(new WebJobsWebHookHandler());
            var container = builder.Build();

            WebHooksConfig.Initialize(_httpConfiguration);

            _httpConfiguration.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            IEnumerable <IWebHookReceiver> receivers = _httpConfiguration.DependencyResolver.GetReceivers();

            _receiverLookup = receivers.ToDictionary(p => p.Name, p => p, StringComparer.OrdinalIgnoreCase);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Configures a Microsoft Azure Table Storage implementation of <see cref="IWebHookStore"/>
        /// which provides a persistent store for registered WebHooks used by the custom WebHooks module.
        /// </summary>
        /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
        public static void InitializeCustomWebHooksAzureStorage(this HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            WebHooksConfig.Initialize(config);

            ILogger            logger   = config.DependencyResolver.GetLogger();
            SettingsDictionary settings = config.DependencyResolver.GetSettings();

            IDataProtectionProvider provider  = GetDataProtectionProvider();
            IDataProtector          protector = provider.CreateProtector(Purpose);

            IStorageManager storageManager = new StorageManager(logger);
            IWebHookStore   store          = new AzureWebHookStore(storageManager, settings, protector, logger);

            CustomServices.SetStore(store);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Configures the MongoDB Storage implementation of <see cref="IWebHookStore"/>
        /// which provides a persistent store for registered WebHooks used by the custom WebHooks module.
        /// </summary>
        /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
        /// <param name="nameOrConnectionString">The name of the connection string application setting. Used to initialize <see cref="WebHookStoreContext"/>.</param>
        /// <param name="encryptData">Indicates whether the data should be encrypted using <see cref="IDataProtector"/> while persisted.</param>
        /// <param name="databaseName">The custom name of database schema. Used to initialize <see cref="WebHookStoreContext"/>.</param>
        /// <param name="collectionName">The custom name of database table. Used to initialize <see cref="WebHookStoreContext"/>.</param>
        public static void InitializeCustomWebHooksMongoStorage(this HttpConfiguration config, string nameOrConnectionString, bool encryptData, string databaseName, string collectionName)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            IWebHookRepository repository;
            IWebHookStore      store;

            WebHooksConfig.Initialize(config);
            ILogger            logger   = config.DependencyResolver.GetLogger();
            SettingsDictionary settings = config.DependencyResolver.GetSettings();

            if (!string.IsNullOrEmpty(nameOrConnectionString) && string.IsNullOrEmpty(databaseName) && string.IsNullOrEmpty(collectionName))
            {
                repository = new WebHookRepository(new WebHookStoreContext(nameOrConnectionString));
            }
            else if (!string.IsNullOrEmpty(nameOrConnectionString) && !string.IsNullOrEmpty(databaseName) && (!string.IsNullOrEmpty(collectionName) || string.IsNullOrEmpty(collectionName)))
            {
                repository = new WebHookRepository(new WebHookStoreContext(nameOrConnectionString, databaseName, collectionName));
            }
            else
            {
                repository = new WebHookRepository(new WebHookStoreContext());
            }

            if (encryptData)
            {
                IDataProtector protector = DataSecurity.GetDataProtector();
                store = new MongoWebHookStore(protector, logger, repository);
            }
            else
            {
                store = new MongoWebHookStore(logger, repository);
            }

            CustomServices.SetStore(store);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Configures a Microsoft SQL Server Storage implementation of <see cref="IWebHookStore"/>
        /// which provides a persistent store for registered WebHooks used by the custom WebHooks module.
        /// </summary>
        /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
        public static void InitializeCustomWebHooksSqlStorage(this HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            WebHooksConfig.Initialize(config);

            ILogger            logger   = config.DependencyResolver.GetLogger();
            SettingsDictionary settings = config.DependencyResolver.GetSettings();

            // We explicitly set the DB initializer to null to avoid that an existing DB is initialized wrongly.
            Database.SetInitializer <WebHookStoreContext>(null);

            IDataProtectionProvider provider  = GetDataProtectionProvider();
            IDataProtector          protector = provider.CreateProtector(Purpose);

            IWebHookStore store = new SqlWebHookStore(settings, protector, logger);

            CustomServices.SetStore(store);
        }
 /// <summary>
 ///  Initializes support for adding custom WebHook support to your ASP.NET project. The functionality
 ///  enables users to manage WebHook subscribers, and to send WebHooks to subscribers with matching
 ///  registrations.
 /// </summary>
 /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
 public static void InitializeCustomWebHooks(this HttpConfiguration config)
 {
     WebHooksConfig.Initialize(config);
 }
 /// <summary>
 /// Initializes support for receiving Instagram WebHooks.
 /// Set the '<c>MS_WebHookReceiverSecret_Instagram</c>' application setting to the application secrets, optionally using IDs
 /// to differentiate between multiple WebHooks, for example '<c>secret0, id1=secret1, id2=secret2</c>'.
 /// The corresponding WebHook URI is of the form '<c>https://&lt;host&gt;/api/webhooks/incoming/instagram/{id}</c>'.
 /// For details about Instagram WebHooks, see <c>https://www.instagram.com/developer/subscriptions/</c>.
 /// </summary>
 /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
 public static void InitializeReceiveInstagramWebHooks(this HttpConfiguration config)
 {
     WebHooksConfig.Initialize(config);
 }
Ejemplo n.º 19
0
        public CustomServicesTests()
        {
            HttpConfiguration config = new HttpConfiguration();

            WebHooksConfig.Initialize(config);
        }
 public static void InitializeIuguWebHooksReceiver(this HttpConfiguration configuration)
 {
     WebHooksConfig.Initialize(configuration);
 }
 /// <summary>
 /// Initializes support for receiving Zendesk WebHooks.
 /// A sample WebHook URI is '<c>https://&lt;host&gt;/api/webhooks/incoming/zendesk/{id}?code=83699ec7c1d794c0c780e49a5c72972590571fd8</c>'.
 /// For security reasons the WebHook URI must be an <c>https</c> URI and contain a 'code' query parameter with the
 /// same value as configured in the '<c>MS_WebHookReceiverSecret_Zendesk</c>' application setting.
 /// The 'code' parameter must be between 32 and 128 characters long.
 /// For details about Zendesk WebHooks, see <c>https://developer.zendesk.com/embeddables/docs/ios/push_notifications_webhook</c>.
 /// For complete details about Zendesk APIs, see <c>https://developer.zendesk.com/rest_api/docs/core/introduction</c>.
 /// </summary>
 /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
 public static void InitializeReceiveZendeskWebHooks(this HttpConfiguration config)
 {
     WebHooksConfig.Initialize(config);
 }
 /// <summary>
 /// Initializes support for receiving generic WebHooks containing valid JSON
 /// with no special validation logic or security requirements. This can for example be used
 /// to receive WebHooks from IFTTT's Maker Channel or a Zapier WebHooks Action.
 /// A sample WebHook URI is '<c>https://&lt;host&gt;/api/webhooks/incoming/genericjson/{id}?code=83699ec7c1d794c0c780e49a5c72972590571fd8</c>'.
 /// For security reasons the WebHook URI must be an <c>https</c> URI and contain a 'code' query parameter with the
 /// same value as configured in the '<c>MS_WebHookReceiverSecret_GenericJson</c>' application setting, optionally using IDs
 /// to differentiate between multiple WebHooks, for example '<c>secret0, id1=secret1, id2=secret2</c>'.
 /// The 'code' parameter must be between 32 and 128 characters long.
 /// The URI may optionally include an '<c>action</c>' query parameter which will serve as the WebHook action.
 /// </summary>
 /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
 public static void InitializeReceiveGenericJsonWebHooks(this HttpConfiguration config)
 {
     WebHooksConfig.Initialize(config);
 }
 /// <summary>
 /// Initializes support for receiving WebHooks generated by Microsoft Dynamics CRM.
 /// A sample WebHook URI is '<c>https://&lt;host&gt;/api/webhooks/incoming/dynamicscrm/{id}?code=83699ec7c1d794c0c780e49a5c72972590571fd8</c>'.
 /// For security reasons the WebHook URI must be an <c>https</c> URI and contain a 'code' query parameter with the
 /// same value as configured in the '<c>MS_WebHookReceiverSecret_DynamicsCRM</c>' application setting, optionally using IDs
 /// to differentiate between multiple WebHooks, for example '<c>secret0, id1=secret1, id2=secret2</c>'.
 /// The 'code' parameter must be between 32 and 128 characters long.
 /// For details about Microsoft Dynamics CRM WebHooks, see <c>https://go.microsoft.com/fwlink/?LinkId=722218</c>.
 /// </summary>
 /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
 public static void InitializeReceiveDynamicsCrmWebHooks(this HttpConfiguration config)
 {
     WebHooksConfig.Initialize(config);
 }
 /// <summary>
 /// Initializes support for receiving WebHooks generated by the Azure Alert Service.
 /// A sample WebHook URI is '<c>https://&lt;host&gt;/api/webhooks/incoming/azurealert/{id}?code=83699ec7c1d794c0c780e49a5c72972590571fd8</c>'.
 /// For security reasons the WebHook URI must be an <c>https</c> URI and contain a 'code' query parameter with the
 /// same value as configured in the '<c>MS_WebHookReceiverSecret_AzureAlert</c>' application setting, optionally using IDs
 /// to differentiate between multiple WebHooks, for example '<c>secret0, id1=secret1, id2=secret2</c>'.
 /// The 'code' parameter must be between 32 and 128 characters long.
 /// For details about Azure WebHooks, see <c>https://azure.microsoft.com/en-us/documentation/articles/insights-webhooks-alerts/</c>.
 /// </summary>
 /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
 public static void InitializeReceiveAzureAlertWebHooks(this HttpConfiguration config)
 {
     WebHooksConfig.Initialize(config);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Initializes support for receiving WordPress WebHooks.
 /// A sample WebHook URI is '<c>https://&lt;host&gt;/api/webhooks/incoming/wordpress?code=83699ec7c1d794c0c780e49a5c72972590571fd8</c>'.
 /// For security reasons the WebHook URI must be an <c>https</c> URI and contain a 'code' query parameter with the
 /// same value as configured in the '<c>MS_WebHookReceiverSecret_WordPress</c>' application setting.
 /// The 'code' parameter must be between 16 and 64 characters long.
 /// For details about WordPress WebHooks, see <c>https://en.support.wordpress.com/webhooks/</c>.
 /// </summary>
 /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
 public static void InitializeReceiveWordPressWebHooks(this HttpConfiguration config)
 {
     WebHooksConfig.Initialize(config);
 }
Ejemplo n.º 26
0
 /// <summary>
 ///  Initializes support for adding custom WebHook support to your ASP.NET project. The functionality
 ///  enables users to manage WebHook subscribers, and to send WebHooks to subscribers with matching
 ///  registrations.
 /// </summary>
 /// <param name="serviceCollection"></param>
 public static void InitializeCustomWebHooks(this IServiceCollection serviceCollection)
 {
     WebHooksConfig.Initialize(serviceCollection);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Initializes support for receiving Bitbucket WebHooks.
 /// A sample WebHook URI is '<c>https://&lt;host&gt;/api/webhooks/incoming/bitbucket/{id}?code=83699ec7c1d794c0c780e49a5c72972590571fd8</c>'.
 /// For security reasons the WebHook URI must be an <c>https</c> URI and contain a 'code' query parameter with the
 /// same value as configured in the '<c>MS_WebHookReceiverSecret_Bitbucket</c>' application setting.
 /// The 'code' parameter must be between 32 and 128 characters long.
 /// For details about Bitbucket WebHooks, see <c>https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html</c>.
 /// </summary>
 /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
 public static void InitializeReceiveBitbucketWebHooks(this HttpConfiguration config)
 {
     WebHooksConfig.Initialize(config);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes support for receiving Salesforce SOAP-based Outbound Messages as a WebHook.
 /// A sample WebHook URI is of the form '<c>https://&lt;host&gt;/api/webhooks/incoming/sfsoap/{id}</c>'.
 /// For security reasons, the WebHook URI must be an <c>https</c> URI and the '<c>MS_WebHookReceiverSecret_SalesforceSoap</c>'
 /// application setting must be configured to the Salesforce Organization IDs. Organizational IDs can be found at
 /// <c>http://www.salesforce.com</c> under <c>Setup | Company Profile | Company Information</c>.
 /// For details about Salesforce Outbound Messages, see <c>https://go.microsoft.com/fwlink/?linkid=838587</c>.
 /// </summary>
 /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
 public static void InitializeReceiveSalesforceWebHooks(this HttpConfiguration config)
 {
     WebHooksConfig.Initialize(config);
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Initializes support for receiving MailChimp WebHooks.
 /// A sample WebHook URI is '<c>https://&lt;host&gt;/api/webhooks/incoming/mailchimp/{id}?code=83699ec7c1d794c0c780e49a5c72972590571fd8</c>'.
 /// For security reasons the WebHook URI must be an <c>https</c> URI and contain a 'code' query parameter with the
 /// same value as configured in the '<c>MS_WebHookReceiverSecret_MailChimp</c>' application setting.
 /// The 'code' parameter must be between 32 and 128 characters long.
 /// For details about MailChimp WebHooks, see <c>https://apidocs.mailchimp.com/webhooks/</c>.
 /// </summary>
 /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
 public static void InitializeReceiveMailChimpWebHooks(this HttpConfiguration config)
 {
     WebHooksConfig.Initialize(config);
 }