From 5dad7ab0ad426b1faa2b2379dd107a0b53a7ba1b Mon Sep 17 00:00:00 2001 From: chatenium Date: Mon, 26 Oct 2026 22:38:14 +0100 Subject: [PATCH] Added factor verification and credential request methods --- src/index.ts | 5 ++--- src/services/auth.ts | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index f444ac1..fbe7171 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,16 +2,15 @@ import {AuthApi, Configuration} from "./generated"; import {DatabaseAPI} from "./storage/database"; import {KeyringAPI} from "./storage/keyring"; import {KeyValueAPI} from "./storage/keyvalue"; -import {AuthApiExtended} from "./services/auth"; export class ChateniumClient { - public auth: AuthApiExtended; + public auth: AuthApi; constructor(config: { baseUrl: string, storage: {database: DatabaseAPI, keyring: KeyringAPI, keyValue: KeyValueAPI} }) { const apiConfig = new Configuration({ basePath: config.baseUrl+"/v3" }) - this.auth = new AuthApiExtended(apiConfig); + this.auth = new AuthApi(apiConfig); } } \ No newline at end of file diff --git a/src/services/auth.ts b/src/services/auth.ts index f68a7ec..9b3646b 100644 --- a/src/services/auth.ts +++ b/src/services/auth.ts @@ -21,4 +21,42 @@ export class AuthChallenge { this.challenge = resp.data; return resp.data; } + + /** + * Starts a new challenge for the provided endpoint + * @param name Name of the factor to verify (Example: SMS, EMAIL, PASSWORD) + * @param credential The credential to verify the factor (SMS code, password, etc...) + */ + async verifyFactor(name: string, credential: string): Promise { + if (this.challenge === undefined) { + throw new Error("Challenge not started"); + } else { + const resp = await this.authApi.verifyFactor({ + challengeId: this.challenge.challengeId, + factorName: name, + credential: credential + }) + + this.challenge = resp.data; + return resp.data; + } + } + + /** + * Requests the credential for a specific factor when it's not static like a password (E-mail, SMS) + * @param name Name of the factor to verify (Example: SMS, EMAIL) + */ + async requestCredential(name: string): Promise { + if (this.challenge === undefined) { + throw new Error("Challenge not started"); + } else { + const resp = await this.authApi.requestCredential({ + challengeId: this.challenge.challengeId, + factorName: name, + }) + + this.challenge = resp.data; + return resp.data; + } + } } \ No newline at end of file