From a0dba1f108ec38ab0cce120d32fa9a75862071ed Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 27 Sep 2023 10:44:10 -0400 Subject: [PATCH] Adding new TOTP generate and update methods. Fixes #191 --- copy_generated_types_from_lemmy.sh | 0 src/http.ts | 35 ++++++++++++++++++++++++++++++ src/index.ts | 2 +- src/types/SaveUserSettings.ts | 1 - 4 files changed, 36 insertions(+), 2 deletions(-) mode change 100644 => 100755 copy_generated_types_from_lemmy.sh diff --git a/copy_generated_types_from_lemmy.sh b/copy_generated_types_from_lemmy.sh old mode 100644 new mode 100755 diff --git a/src/http.ts b/src/http.ts index 8ec7c51..8703ccd 100644 --- a/src/http.ts +++ b/src/http.ts @@ -129,6 +129,9 @@ import { UploadImage, UploadImageResponse, VERSION } from "./types/others"; import { HideCommunity } from "./types/HideCommunity"; import { BlockInstance } from "./types/BlockInstance"; import { BlockInstanceResponse } from "./types/BlockInstanceResponse"; +import { GenerateTotpSecretResponse } from "./types/GenerateTotpSecretResponse"; +import { UpdateTotp } from "./types/UpdateTotp"; +import { UpdateTotpResponse } from "./types/UpdateTotpResponse"; enum HttpType { Get = "GET", @@ -212,6 +215,38 @@ export class LemmyHttp { ); } + /** + * Generate a TOTP / two-factor secret. + * + * Afterwards you need to call `/user/totp/update` with a valid token to enable it. + * + * `HTTP.POST /user/totp/generate` + */ + generateTotpSecret() { + return this.#wrapper( + HttpType.Post, + "/user/totp/generate", + {}, + ); + } + + /** + * Enable / Disable TOTP / two-factor authentication. + * + * To enable, you need to first call `/user/totp/generate` and then pass a valid token to this. + * + * Disabling is only possible if 2FA was previously enabled. Again it is necessary to pass a valid token. + * + * `HTTP.POST /user/totp/update` + */ + updateTotp(form: UpdateTotp) { + return this.#wrapper( + HttpType.Post, + "/user/totp/update", + form, + ); + } + /** * Get the modlog. * diff --git a/src/index.ts b/src/index.ts index 1b77295..05f9aea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -241,4 +241,4 @@ export { UpdateTotp } from "./types/UpdateTotp"; export { UpdateTotpResponse } from "./types/UpdateTotpResponse"; export { VerifyEmail } from "./types/VerifyEmail"; export { VerifyEmailResponse } from "./types/VerifyEmailResponse"; -export { ImageFile, UploadImage, UploadImageResponse } from "./types/others"; +export { UploadImage, UploadImageResponse, ImageFile } from "./types/others"; diff --git a/src/types/SaveUserSettings.ts b/src/types/SaveUserSettings.ts index 31182a3..fb9e89f 100644 --- a/src/types/SaveUserSettings.ts +++ b/src/types/SaveUserSettings.ts @@ -25,7 +25,6 @@ export interface SaveUserSettings { show_read_posts?: boolean; show_new_post_notifs?: boolean; discussion_languages?: Array; - generate_totp_2fa?: boolean; open_links_in_new_tab?: boolean; infinite_scroll_enabled?: boolean; }