Exemple #1
0
        /// <summary>
        /// Gets the Client ID and Client Secret for the Instagram Client application.
        /// </summary>
        /// <param name="id">A (potentially empty) ID of a particular configuration for this WebHook.</param>
        /// <returns>A <see cref="Tuple{T1,T2}"/> containing the Client ID and Client Secret.</returns>
        protected virtual async Task <Tuple <string, string> > GetClientConfig(string id)
        {
            IWebHookReceiverConfig receiverConfig = _config.DependencyResolver.GetReceiverConfig();

            string clientId = await receiverConfig.GetReceiverConfigAsync(ClientIdKey, id, InstagramWebHookReceiver.SecretMinLength, InstagramWebHookReceiver.SecretMaxLength);

            ValidateConfig(ClientIdKey, clientId, id, InstagramWebHookReceiver.SecretMinLength, InstagramWebHookReceiver.SecretMaxLength);

            string clientSecret = await receiverConfig.GetReceiverConfigAsync(InstagramWebHookReceiver.ReceiverName, id, InstagramWebHookReceiver.SecretMinLength, InstagramWebHookReceiver.SecretMaxLength);

            ValidateConfig(InstagramWebHookReceiver.ReceiverName, clientSecret, id, InstagramWebHookReceiver.SecretMinLength, InstagramWebHookReceiver.SecretMaxLength);

            return(Tuple.Create(clientId, clientSecret));
        }
Exemple #2
0
        protected virtual async Task <string> GetReceiverConfig(HttpRequestMessage request, string name, string id, int minLength, int maxLength)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            // Look up configuration for this receiver and instance
            HttpConfiguration      httpConfig     = request.GetConfiguration();
            IWebHookReceiverConfig receiverConfig = httpConfig.DependencyResolver.GetReceiverConfig();
            string secret = await receiverConfig.GetReceiverConfigAsync(name, id, minLength, maxLength);

            if (secret == null)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, ReceiverResources.Receiver_BadSecret, name, id, minLength, maxLength);
                httpConfig.DependencyResolver.GetLogger().Error(msg);
                HttpResponseMessage noSecret = request.CreateErrorResponse(HttpStatusCode.InternalServerError, msg);
                throw new HttpResponseException(noSecret);
            }
            return(secret);
        }
        /// <summary>
        /// Gets the receiver configuration with the given <paramref name="configurationName"/> and
        /// <paramref name="id"/>.
        /// </summary>
        /// <param name="config">The current <see cref="IWebHookReceiverConfig"/>.</param>
        /// <param name="configurationName">
        /// The name of the configuration to obtain. Typically this is the name of the receiver, e.g. <c>github</c>.
        /// </param>
        /// <param name="id">
        /// A (potentially empty) ID of a particular configuration for this <see cref="IWebHookReceiver"/>. This
        /// allows an <see cref="IWebHookReceiver"/> to support multiple WebHook endpoints with individual
        /// configurations.
        /// </param>
        /// <param name="minLength">The minimum length of the key value.</param>
        /// <param name="maxLength">The maximum length of the key value.</param>
        public static async Task <string> GetReceiverConfigAsync(
            this IWebHookReceiverConfig config,
            string configurationName,
            string id,
            int minLength,
            int maxLength)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (configurationName == null)
            {
                throw new ArgumentNullException(nameof(configurationName));
            }

            // Look up configuration for this name and id.
            var secret = await config.GetReceiverConfigAsync(configurationName, id);

            // Verify that configuration value matches length requirements
            if (secret == null || secret.Length < minLength || secret.Length > maxLength)
            {
                return(null);
            }

            return(secret);
        }