Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
91 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Net.Http; | ||
|
||
namespace Griesoft.AspNetCore.ReCaptcha.Clients | ||
{ | ||
/// <summary> | ||
/// Constructs http client used for verifying captcha result with Google | ||
/// </summary> | ||
public interface IRecaptchaHttpClientFactory | ||
{ | ||
/// <summary> | ||
/// Create HttpClient with preconfigured options to communicate with Google reCatpcha REST service | ||
/// </summary> | ||
/// <returns></returns> | ||
HttpClient CreateClient(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Runtime.CompilerServices; | ||
using Griesoft.AspNetCore.ReCaptcha.Configuration; | ||
using Microsoft.Extensions.Options; | ||
|
||
[assembly: InternalsVisibleTo("ReCaptcha.Tests")] | ||
namespace Griesoft.AspNetCore.ReCaptcha.Clients | ||
{ | ||
internal class RecaptchaClientFactory : IRecaptchaHttpClientFactory | ||
{ | ||
private readonly RecaptchaOptions _options; | ||
|
||
public RecaptchaClientFactory(IOptionsMonitor<RecaptchaOptions> options) | ||
{ | ||
_options = options.CurrentValue; | ||
} | ||
|
||
|
||
public HttpClient CreateClient() | ||
{ | ||
var httpClientHandler = new HttpClientHandler(); | ||
if (_options.UseProxy.HasValue && _options.UseProxy.Value && !String.IsNullOrEmpty(_options.ProxyAddress)) | ||
{ | ||
httpClientHandler.UseProxy = true; | ||
httpClientHandler.Proxy = new WebProxy(_options.ProxyAddress, false); | ||
} | ||
|
||
var httpClient = new HttpClient(httpClientHandler) | ||
{ | ||
BaseAddress = new Uri(RecaptchaServiceConstants.GoogleRecaptchaEndpoint) | ||
}; | ||
|
||
return httpClient; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters