Add totp token (#192)

* Adding new TOTP generate and update methods. Fixes #191

* Fix husky mode.
This commit is contained in:
Dessalines 2023-09-27 10:55:29 -04:00 committed by GitHub
parent e270d67086
commit b4f1bbcd63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 2 deletions

0
.husky/pre-commit Normal file → Executable file
View file

0
copy_generated_types_from_lemmy.sh Normal file → Executable file
View file

View file

@ -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<object, GenerateTotpSecretResponse>(
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<object, UpdateTotpResponse>(
HttpType.Post,
"/user/totp/update",
form,
);
}
/**
* Get the modlog.
*

View file

@ -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";

View file

@ -25,7 +25,6 @@ export interface SaveUserSettings {
show_read_posts?: boolean;
show_new_post_notifs?: boolean;
discussion_languages?: Array<LanguageId>;
generate_totp_2fa?: boolean;
open_links_in_new_tab?: boolean;
infinite_scroll_enabled?: boolean;
}