Skip to content

Commit

Permalink
Merge pull request #77 from ava-labs/fix/v2-recaptcha-2
Browse files Browse the repository at this point in the history
Fix/v2 recaptcha 2
  • Loading branch information
rajranjan0608 authored Nov 22, 2022
2 parents 0a90118 + f6581a5 commit a488015
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions middlewares/verifyCaptcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,24 @@ export class VerifyCaptcha {
}

async verifyV2Token(v2Token: string): Promise<boolean> {
console.log("Recaptcha V2 Token:", v2Token)
if(v2Token) {
const URL = "https://www.google.com/recaptcha/api/siteverify"
const URL = `https://www.google.com/recaptcha/api/siteverify?secret=${this.v2secret}&response=${v2Token}`

let response

let recaptchaBody = {
secret: `${this.v2secret}`,
response: `${v2Token}`,
}


try {
response = await axios
.get(URL, {
headers: { "Content-Type": "application/x-www-form-urlencoded" },
params: recaptchaBody,
})
.then((r: any) => {
return r
})
response = await axios.post(URL)
.then((r: any) => {
return r
})
} catch (err: any) {
console.log("Recaptcha V2 error:", err?.message)
console.log("Recaptcha V2 error:", err?.message)
}

const data = response?.data

const data = response?.data
console.log("Recaptcha V2 verify response:", data)

if(data?.success) {
return true
}
Expand All @@ -47,6 +41,8 @@ export class VerifyCaptcha {
}

async verifyV3Token(v3Token: string): Promise<boolean> {
console.log("Recaptcha V3 Token:", v3Token)

const URL = `https://www.google.com/recaptcha/api/siteverify?secret=${this.secret}&response=${v3Token}`
let response

Expand All @@ -57,6 +53,7 @@ export class VerifyCaptcha {
}

const data = response?.data
console.log("Recaptcha V3 verify response:", data)

if(data?.success) {
if(data?.action == 'faucetdrip') {
Expand All @@ -70,13 +67,15 @@ export class VerifyCaptcha {
}

async shouldAllow(token: string, v2Token: string): Promise<boolean> {
console.log("Recaptcha tokens:", token, v2Token)
if(await this.verifyV3Token(token)) {
return true
} else {
if(await this.verifyV2Token(v2Token)) {
return true
}
}
console.log("Recaptcha verification failed!")
return false
}

Expand Down

0 comments on commit a488015

Please sign in to comment.