@nestlab/google-recaptcha
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -0,3 +1,7 @@ | ||
/// <reference types="node" /> | ||
import * as https from "https"; | ||
export interface GoogleRecaptchaValidatorOptions { | ||
secretKey: string; | ||
useRecaptchaNet?: boolean; | ||
agent?: https.Agent; | ||
} |
{ | ||
"name": "@nestlab/google-recaptcha", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Google recaptcha module for NestJS.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -28,2 +28,4 @@ # Google recaptcha module | ||
skipIf: () => process.env.NODE_ENV !== 'production', | ||
useRecaptchaNet: false, | ||
agent: null | ||
}) | ||
@@ -36,2 +38,13 @@ ], | ||
**Configuration options** | ||
| Property | | Type | Description | | ||
|-------------------|---|----------------------------|-------------| | ||
| `secretKey` | ✔ | string | Google recaptcha secret key | | ||
| `response` | ✔ | (request) => string | Function that returns response (recaptcha token) by request | | ||
| `skipIf` | ✖ | () => boolean | Function that returns true if you need skip check for development or testing | | ||
| `useRecaptchaNet` | ✖ | boolean | If your server has trouble connecting to https://www.google.com. You can use https://recaptcha.net instead, just set true | | ||
| `agent` | ✖ | https.Agent | If you need to use an agent | | ||
If you want import configs from your [ConfigService](https://docs.nestjs.com/techniques/configuration#getting-started) via [custom getter function](https://docs.nestjs.com/techniques/configuration#custom-getter-functions) that will return `GoogleRecaptchaModuleOptions` object. | ||
@@ -38,0 +51,0 @@ |
@@ -8,2 +8,3 @@ import { HttpService } from '@nestjs/common'; | ||
private readonly apiUrl; | ||
private readonly apiUrlUseRecaptchaNet; | ||
private readonly headers; | ||
@@ -10,0 +11,0 @@ constructor(http: HttpService, options: GoogleRecaptchaValidatorOptions); |
@@ -25,2 +25,3 @@ "use strict"; | ||
this.apiUrl = 'https://www.google.com/recaptcha/api/siteverify'; | ||
this.apiUrlUseRecaptchaNet = 'https://recaptcha.net/recaptcha/api/siteverify'; | ||
this.headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; | ||
@@ -30,3 +31,7 @@ } | ||
const data = qs.stringify({ secret: this.options.secretKey, response }); | ||
return this.http.post(this.apiUrl, data, { headers: this.headers }) | ||
const url = this.options.useRecaptchaNet ? this.apiUrlUseRecaptchaNet : this.apiUrl; | ||
return this.http.post(url, data, { | ||
headers: this.headers, | ||
httpsAgent: this.options.agent | ||
}) | ||
.toPromise() | ||
@@ -33,0 +38,0 @@ .then(res => res.data) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31718
365
149