TimothyMeadows / reCAPTCHA.AspNetCore

Google reCAPTCHA v2/v3 for .NET Core 3.x
MIT License
144 stars 51 forks source link

ReCAPTCHA settings null after using AddRecaptcha options #62

Closed samuelgrant closed 4 years ago

samuelgrant commented 4 years ago

Hi..

Your fix for #60 has worked so far as it stops the application from crashing on runtime, however it seems the settings set using the options method do not persist when they are injected into a controller...

Read me example being used:

// Or configure recaptcha via options
services.AddRecaptcha(options =>
{
    options.SecretKey = "Your secret key";
    options.SiteKey = "Your site key";
});

image

I noticed this issue when trying to validate responses. The Validate(code) method was returning a new response object with all fields set to the default value. It may be worth throwing some sort of exception if a validation is attempted without a secret key..

image

TimothyMeadows commented 4 years ago

Interesting, will look into this.

TimothyMeadows commented 4 years ago

image

Seems to be just fine? Where are you getting the settings object from?

TimothyMeadows commented 4 years ago

Seems fine with @inject too image

TimothyMeadows commented 4 years ago

Looks like this is a result of not using services.Configure in the AddRecaptcha methods that were recently added by @mo-esmp . Rather services.AddSingleton is called for the object which is injecting settings as RecatpchaSettings and not IOptions.

In the future to follow proper standard you should always call services.Configure with the "options". This method supports Action by default on it's own.

TimothyMeadows commented 4 years ago

This is now fixed in 3.0.5.

mo-esmp commented 4 years ago

Yes, I removed IOptions but you rolled back code to IOptions. I added some integration tests to validate captcha registration and I think it worth to run tests after any change.