Exemplo n.º 1
0
        private static IAppBuilder UseRecaptchaValidationEndpointCore(this IAppBuilder app,
                                                                      RecaptchaValidationOptions options, bool enableRecaptcha)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            app.Map(options.ProtectedPath, challenge =>
            {
                challenge.UseRequestedChallengeType(options);
                if (enableRecaptcha)
                {
                    challenge.Use <RecaptchaValidationMiddleware>(options);
                }
                challenge.Run(ctx =>
                {
                    ctx.Response.StatusCode = (int)HttpStatusCode.NoContent;
                    return(Task.FromResult(0));
                });
            });

            return(app);
        }
 public RecaptchaValidationMiddleware(OwinMiddleware next, RecaptchaValidationOptions options)
     : base(next)
 {
     _options = options;
 }
Exemplo n.º 3
0
 /// <summary>
 ///     Serves the URL 'options.ProtectedPath' and will yield a Recaptcha challenge if shields are up
 /// </summary>
 public static IAppBuilder UseRecaptchaValidationEnabledEndpoint(this IAppBuilder app,
                                                                 RecaptchaValidationOptions options)
 {
     return(app.UseRecaptchaValidationEndpointCore(options, true));
 }