-
Notifications
You must be signed in to change notification settings - Fork 116
feat(recaptcha): add recaptcha #401
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d482ffc
feat: add example file
b332951
feat: init recaptcha
aacca72
feat(recaptcha): reverte some configs
16a828e
feat(recaptcha): add v3 support
541da0e
feat(recaptcha): add possibility to deactivate module and docs
56b45fe
feat(recaptcha): link reCaptcha doc
65556a1
feat(recaptcha): link reCaptcha doc
1439d63
feat(recaptcha): use fetch instead of axios
af0c8ea
feat(recaptcha): add recaptcha to review form
bb64c23
feat(recaptcha): add recaptcha to reset password form
f9bf59d
feat(recaptcha): add recaptcha to checkout form
1bbed43
feat(recaptcha): add recaptcha to forgot password and register forms
bd1ee6c
feat(recaptcha): code review
a52f8d3
feat(recaptcha): refactoring
2cb4724
feat(recaptcha): add tests
flemenach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,52 @@ | ||
| # reCaptcha | ||
|
|
||
| You can activate the reCaptchta feature using this Guidelines. | ||
|
|
||
| ## Activate reCaptcha module | ||
|
|
||
| Uncomment the line below in the `nuxt.config.js` file to activate the module. | ||
|
|
||
| ```js | ||
| ... | ||
| '@vue-storefront/middleware/nuxt', | ||
| '@nuxtjs/html-validator', | ||
| // '@nuxtjs/recaptcha', | ||
| ], | ||
| recaptcha: { | ||
| ... | ||
|
|
||
| ``` | ||
|
|
||
| ## Configure the reCaptcha | ||
|
|
||
| On the `config` folder update the config file (`dev.json` for example) with your configurations. | ||
|
|
||
| ```json5 | ||
| { | ||
| ... | ||
| "recaptchaEnabled": "{YOUR_RECAPTCHA_ENABLED}", // true or false, default value is false | ||
| "recaptchaHideBadge": "{YOUR_RECAPTCHA_HIDE_BADGE}", // true or false, default value is false | ||
| "recaptchaSize": "{YOUR_RECAPTCHA_SIZE}", // Size: 'compact', 'normal', 'invisible' (v2), default value is 'invisible' | ||
| "recaptchaSiteKey": "{YOUR_RECAPTCHA_SITE_KEY}", // Site key for requests, default value is '' | ||
| "recaptchaSecretkey": "{YOUR_RECAPTCHA_SECRET_KEY}", // Secret key for requests, default value is '' | ||
| "recaptchaVersion": "{YOUR_RECAPTCHA_VERSION}", // Version 2 or 3, default value is 3 | ||
| "recaptchaMinScore": "{YOUR_RECAPTCHA_MIN_SCORE}" // The min score used for v3, default value is 0.5 | ||
| ... | ||
| } | ||
| ``` | ||
|
|
||
| ### Sample configuration | ||
|
|
||
| ```json5 | ||
| { | ||
| ... | ||
| "recaptchaEnabled": true, | ||
| "recaptchaHideBadge": false, | ||
| "recaptchaSize": "invisible", | ||
| "recaptchaSiteKey": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", | ||
| "recaptchaSecretkey": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", | ||
| "recaptchaVersion": 3, | ||
| "recaptchaMinScore": 0.5 | ||
| ... | ||
| } | ||
| ``` |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -57,4 +57,4 @@ | |
| "engines": { | ||
| "node": ">=16.x" | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
26 changes: 26 additions & 0 deletions
26
packages/api-client/src/helpers/recaptcha/recaptchaValidator.ts
This file contains hidden or 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,26 @@ | ||
| import { Context } from '../../types/context'; | ||
|
|
||
| interface RecaptchaApiResponse { | ||
| success: boolean, | ||
| challenge_ts: string, | ||
| hostname: string, | ||
| 'error-codes'?: [any], | ||
| score?: number | ||
| } | ||
|
|
||
| export default async ( | ||
| context: Context, | ||
| token: string, | ||
| ): Promise<RecaptchaApiResponse> => { | ||
| try { | ||
| const { secretkey } = context.config.recaptcha; | ||
| const url = `https://www.google.com/recaptcha/api/siteverify?secret=${secretkey}&response=${token}`; | ||
|
|
||
| const result = await fetch(url); | ||
| const response = await result.json(); | ||
|
|
||
| return response; | ||
| } catch (error) { | ||
| throw error.message || error; | ||
| } | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.