Added factor verification and credential request methods

This commit is contained in:
2026-10-26 22:38:14 +01:00
parent 1fb7936be9
commit 5dad7ab0ad
2 changed files with 40 additions and 3 deletions

View File

@@ -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);
}
}

View File

@@ -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<Challenge> {
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<Challenge> {
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;
}
}
}