-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from chvarkov/develop
Added support reCAPTCHA v3. Updated external interfaces. Updated vers…
- Loading branch information
Showing
16 changed files
with
178 additions
and
34 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { applyDecorators, SetMetadata, UseGuards } from '@nestjs/common'; | ||
import { GoogleRecaptchaGuard } from '../guards/google-recaptcha.guard'; | ||
import { RecaptchaResponseProvider } from '../types'; | ||
import { RECAPTCHA_RESPONSE_PROVIDER } from '../provider.declarations'; | ||
import { VerifyResponseDecoratorOptions } from '../interfaces/verify-response-decorator-options'; | ||
import { RECAPTCHA_VALIDATION_OPTIONS } from '../provider.declarations'; | ||
|
||
export function Recaptcha(response?: RecaptchaResponseProvider): MethodDecorator & ClassDecorator { | ||
export function Recaptcha(options?: VerifyResponseDecoratorOptions): MethodDecorator & ClassDecorator { | ||
return applyDecorators( | ||
SetMetadata(RECAPTCHA_RESPONSE_PROVIDER, response), | ||
SetMetadata(RECAPTCHA_VALIDATION_OPTIONS, options), | ||
UseGuards(GoogleRecaptchaGuard), | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { RecaptchaResponseProvider } from '../types'; | ||
import { RecaptchaResponseProvider, ScoreValidator } from '../types'; | ||
import { ApplicationType } from '../enums/application-type'; | ||
|
||
export interface GoogleRecaptchaGuardOptions { | ||
response: RecaptchaResponseProvider; | ||
applicationType?: ApplicationType; | ||
skipIf?: boolean | ((request: any) => boolean | Promise<boolean>); | ||
score?: ScoreValidator; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { RecaptchaResponseProvider, ScoreValidator } from '../types'; | ||
|
||
export interface VerifyResponseDecoratorOptions { | ||
response?: RecaptchaResponseProvider; | ||
score?: ScoreValidator; | ||
action?: string; | ||
} | ||
|
||
export interface VerifyResponseOptions { | ||
response: string; | ||
score?: ScoreValidator; | ||
action?: string; | ||
} |
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,13 @@ | ||
import { ErrorCode } from '../enums/error-code'; | ||
|
||
export interface VerifyResponseV2 { | ||
success: boolean; | ||
challenge_ts: string; | ||
hostname: string; | ||
errors: ErrorCode[] | ||
} | ||
|
||
export interface VerifyResponseV3 extends VerifyResponseV2 { | ||
score: number; | ||
action: string; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const RECAPTCHA_OPTIONS = Symbol('RECAPTCHA_OPTIONS'); | ||
|
||
export const RECAPTCHA_RESPONSE_PROVIDER = Symbol('RECAPTCHA_RESPONSE_PROVIDER'); | ||
export const RECAPTCHA_VALIDATION_OPTIONS = Symbol('RECAPTCHA_VALIDATION_OPTIONS'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export type RecaptchaResponseProvider = (req) => string | Promise<string>; | ||
|
||
export type ScoreValidator = number | ((score: number) => boolean); |
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