Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding RecaptchaApiSource to RecaptchaConfiguration. #61

Merged
merged 1 commit into from
Jan 22, 2023

Conversation

PSTDylan
Copy link
Contributor

With these changes, one may optionally add RecaptchaApiSource to Web.config to override the default url used to fetch google's reCAPTCHA resources:

<appSettings>
    <add key="RecaptchaSiteKey" value="..." />
    <add key="RecaptchaSecretKey" value="..." />
    <add key="RecaptchaApiVersion" value="2"/>
    <add key="RecaptchaApiSource" value="www.recaptcha.net/recaptcha" />
</appSettings>

By using the above, the package will use https://www.recaptcha.net/recaptcha/api.js and https://www.recaptcha.net/recaptcha/api/siteverify rather than https://www.google.com/recaptcha/api.js and https://www.google.com/recaptcha/api/siteverify

If RecaptchaApiSource is not specified, the default is www.google.com/recaptcha.

These changes are required to allow access to users who are unable to request resources from google.com domains, as is the case for many users in China. By editing one's host file ("C:\Windows\System32\drivers\etc\hosts") to include the following, it can be tested that the reCAPTCHA widget with RecaptchaApiSource overridden works without access to google.com:

127.0.0.1 google.com www.google.com

@SquareDen
Copy link

Hello @tanveery! Could you please watch this PR and merge it? It is very necessary and relevant. Thanks!

@PSTDylan
Copy link
Contributor Author

#55 and #54 are related. I see the other solution for this was closed, but this PR allows either source.

@SquareDen
Copy link

#55 and #54 are related. I see the other solution for this was closed, but this PR allows either source.

Yes, it would be great to solve this problem.

@@ -30,6 +33,7 @@ public RecaptchaConfiguration(string siteKey, string secretKey, string apiVersio
Theme = theme;
Size = size;
UseSsl = useSsl;
ApiSource = apiSource;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line must be updated because otherwise a null value will be used when the appsetting not present in the configuration.

ApiSource = string.IsNullOrEmpty(apiSource) ? DEFAULT_API_SOURCE : apiSource;

@tanveery tanveery merged commit eb3e05f into tanveery:master Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants