diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-07-20 14:35:32 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-07-20 14:39:35 +1000 |
commit | 8d9816879fbc838e4a8b54001673c487a3d3a36a (patch) | |
tree | cc26e5a5c503f80a5a6bfec8dbc6f42e56f6785e /api/src/util | |
parent | Hcaptcha support on login/register (diff) | |
download | server-8d9816879fbc838e4a8b54001673c487a3d3a36a.tar.xz |
Hcaptcha backend
Diffstat (limited to 'api/src/util')
-rw-r--r-- | api/src/util/index.ts | 1 | ||||
-rw-r--r-- | api/src/util/utility/captcha.ts | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/api/src/util/index.ts b/api/src/util/index.ts index ffbcf24e..de6b6064 100644 --- a/api/src/util/index.ts +++ b/api/src/util/index.ts @@ -6,3 +6,4 @@ export * from "./utility/RandomInviteID"; export * from "./handlers/route"; export * from "./utility/String"; export * from "./handlers/Voice"; +export * from "./utility/captcha"; \ No newline at end of file diff --git a/api/src/util/utility/captcha.ts b/api/src/util/utility/captcha.ts new file mode 100644 index 00000000..b32bd1c6 --- /dev/null +++ b/api/src/util/utility/captcha.ts @@ -0,0 +1,25 @@ +import { Config } from "@fosscord/util"; +import fetch from "node-fetch"; + +export interface hcaptchaResponse { + success: boolean; + challenge_ts: string; + hostname: string; + credit: boolean; + "error-codes": string[]; + score: number; // enterprise only + score_reason: string[]; // enterprise only +} + +export async function verifyHcaptcha(response: string, ip?: string) { + const { security } = Config.get(); + const { secret, sitekey } = security.captcha; + + const res = await fetch("https://hcaptcha.com/siteverify", { + method: "POST", + body: `response=${response}&secret=${secret}&remoteip=${ip}&sitekey=${sitekey}`, + }) + + const json = await res.json() as hcaptchaResponse; + return json; +} \ No newline at end of file |