diff --git a/api/oauth2-api.ts b/api/oauth2-api.ts index 2507301..a897d71 100644 --- a/api/oauth2-api.ts +++ b/api/oauth2-api.ts @@ -1,11 +1,16 @@ import { BaseApi } from "./base-api.ts"; +export type Oauth2ApplicationCreateParams = { + name: string, + redirect_uris: string[], + confidential_client?: boolean, +} + export type Oauth2Application = { id: number, name: string, redirect_uris: string[], client_id: string, - client_secret: string, confidential_client: boolean, /** * @format date-time @@ -13,6 +18,10 @@ export type Oauth2Application = { created: string, } +export type Oauth2ApplicationResponse = { + client_secret: string, +} & Oauth2Application + export class OAuth2Api extends BaseApi { private token: string; @@ -21,17 +30,8 @@ export class OAuth2Api extends BaseApi { 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`, { + async createOauth2Application(params: Oauth2ApplicationCreateParams): Promise { + return await this.request(`/api/v1/user/applications/oauth2`, { method: "POST", headers: { "Authorization": `Bearer ${this.token}`, @@ -41,7 +41,7 @@ export class OAuth2Api extends BaseApi { }); } - async getOauth2Applications(): Promise { + async getOauth2Applications(): Promise { return await this.request(`/api/v1/user/applications/oauth2`, { method: "GET", headers: { @@ -65,12 +65,8 @@ export class OAuth2Api extends BaseApi { }); } - async updateOauth2Application(id: number, params: { - name: string, - redirect_uris: string[], - confidential_client?: boolean, - }): Promise { - return await this.request(`/api/v1/user/applications/oauth2/${id}`, { + async updateOauth2Application(id: number, params: Oauth2ApplicationCreateParams): Promise { + return await this.request(`/api/v1/user/applications/oauth2/${id}`, { method: "PATCH", headers: { "Authorization": `Bearer ${this.token}`,