import { BaseApi } from "./base-api.ts"; export type Oauth2Application = { id: number, name: string, redirect_uris: string[], client_id: string, client_secret: string, confidential_client: boolean, /** * @format date-time */ created: string, } export class OAuth2Api extends BaseApi { private token: string; constructor(baseUrl: string, token: string) { super(baseUrl); this.token = token; } // Method to update token if needed later updateToken(token: string): void { this.token = token; } async createOauth2Application(params: { name: string, redirect_uris: string[], confidential_client?: boolean, }): Promise { return await this.request(`/api/v1/user/applications/oauth2`, { method: "POST", headers: { "Authorization": `Bearer ${this.token}`, "Content-Type": "application/json", }, body: JSON.stringify(params), }); } async getOauth2Applications(): Promise { return await this.request(`/api/v1/user/applications/oauth2`, { method: "GET", headers: { "Authorization": `Bearer ${this.token}`, "Content-Type": "application/json", }, }); } async deleteOauth2Application(id: number): Promise { if (!this.token) { throw new Error("Authentication required. Please login first."); } await this.request(`/api/v1/user/applications/oauth2/${id}`, { method: "DELETE", headers: { "Authorization": `Bearer ${this.token}`, "Content-Type": "application/json", }, }); } async updateOauth2Application(id: number, params: { name: string, redirect_uris: string[], confidential_client?: boolean, }): Promise { return await this.request(`/api/v1/user/applications/oauth2/${id}`, { method: "PATCH", headers: { "Authorization": `Bearer ${this.token}`, "Content-Type": "application/json", }, body: JSON.stringify(params), }); } }