Spaier.Recaptcha
3.2.0
너겟
Install-Package Spaier.Recaptcha
.NET CLI
dotnet add package Spaier.Recaptcha
public void ConfigureServices ( IServiceCollection services ) {
// Your Code
services . AddRecaptcha ( )
// Use appsettings.json
//.AddInMemoryConfigurationStore(Configuration.GetSection("Recaptcha"))
. AddInMemoryConfigurationStore ( new Dictionary < string , RecaptchaConfiguration >
{
[ "Sitekey1" ] = new RecaptchaConfiguration ( RecaptchaDefaults . TestSecretKey , RecaptchaSecretType . V2 ) ,
[ "Sitekey2" ] = new RecaptchaConfiguration ( RecaptchaDefaults . TestSecretKey , RecaptchaSecretType . V2Android ) ,
[ "Sitekey3" ] = new RecaptchaConfiguration ( RecaptchaDefaults . TestSecretKey , RecaptchaSecretType . V3 ) ,
} )
. AddTokenHeaderProvider ( )
. AddConfigurationHeaderProvider ( )
. AddRecaptchaHttpClient ( configureHttpBuilder : httpBuilder =>
{
// You can setup Polly here
httpBuilder . AddTransientHttpErrorPolicy ( builder => builder . WaitAndRetryAsync ( new [ ]
{
TimeSpan . FromSeconds ( 1 ) ,
TimeSpan . FromSeconds ( 5 ) ,
TimeSpan . FromSeconds ( 10 )
} ) ) ;
} )
. UseGoogleUrl ( ) ;
// UseGlobalUrl(); // will use recaptcha.net mirror. Useful for countries where google.com is blocked.
// UseCustomUrl("your_url"); // will use custom url for validation.
}
ValidateRecaptcha
속성을 작업에 적용합니다. Configurations
작업에 허용되는 구성을 정의합니다. 아무것도 지정하지 않으면 모든 구성을 사용할 수 있습니다. 하나만 지정하는 경우 구성 토큰을 생략할 수 있습니다.
AllowedAction
V2 또는 V3에서 작동합니다. 작업 확인을 건너뛰도록 지정하지 마세요.
MinimumScore
V3에서 작동합니다. 기본값은 0.5
입니다.
UseModelErrors
MVC 모델에 오류를 추가할지 여부를 결정합니다. 기본적으로 True입니다.
IRecaptchaResponse
에서 파생된 메서드 매개 변수와 함께 FromRecaptchaResponseAttribute
를 사용하여 작업에 recaptcha 응답을 전달할 수 있습니다.
[ HttpPost ]
[ AllowAnonymous ]
[ ValidateRecaptcha ( Configurations = new [ ] { "Sitekey1" , "Sitekey2" } , MinimumScore = 0.7 , AllowedAction = "register" ) ]
public async Task < ActionResult > ProtectedByV3AndV2 ( [ FromRecaptchaResponse ] RecaptchaResponse response )
{
// Your Code
}
reCAPTCHA의 응답은 지정된 키 또는 g-recaptcha-response
사용하여 HTTP 헤더로 전달되어야 합니다.
저장소에 둘 이상의 구성이 있거나 Configurations
에 지정된 경우 reCAPTCHA의 구성 키는 지정된 키 또는 g-recaptcha-type
사용하여 HTTP 헤더로 전달되어야 합니다.
클라이언트 측에서 전달한 토큰이 유효하지 않은 경우 모델 오류가 ModelState
에 추가됩니다. RecaptchaErrorCodes
, ValidateRecaptchaAttribute.ErrorCodes
및 공식 문서를 참조하세요.
MIT