Create and delete tokens from web ui

This commit is contained in:
2025-03-19 21:08:59 +01:00
parent 544513d118
commit 7155d91bed
14 changed files with 822 additions and 1 deletions

View File

@ -6,7 +6,11 @@ export interface ServerConfig {
constraints: ServerConstraints;
}
export interface ServerConstraints {}
export interface ServerConstraints {
token_name: LenConstraint;
token_ip_net: LenConstraint;
token_max_inactivity: LenConstraint;
}
export interface LenConstraint {
min: number;

View File

@ -0,0 +1,70 @@
import { APIClient } from "./ApiClient";
export interface Token {
id: number;
name: string;
time_create: number;
user_id: number;
time_used: number;
max_inactivity: number;
ip_net?: string;
read_only: boolean;
right_account: boolean;
right_movement: boolean;
right_inbox: boolean;
right_attachment: boolean;
right_auth: boolean;
}
export interface TokenWithSecret extends Token {
token: string;
}
export interface NewToken {
name: string;
ip_net?: string;
max_inactivity: number;
read_only: boolean;
right_account: boolean;
right_movement: boolean;
right_inbox: boolean;
right_attachment: boolean;
right_auth: boolean;
}
export class TokensApi {
/**
* Get the list of tokens of the current user
*/
static async GetList(): Promise<Token[]> {
return (
await APIClient.exec({
uri: "/tokens/list",
method: "GET",
})
).data;
}
/**
* Create a new token
*/
static async Create(t: NewToken): Promise<TokenWithSecret> {
return (
await APIClient.exec({
uri: "/tokens",
method: "POST",
jsonData: t,
})
).data;
}
/**
* Delete a token
*/
static async Delete(t: Token): Promise<void> {
await APIClient.exec({
uri: `/tokens/${t.id}`,
method: "DELETE",
});
}
}