From 5f03d94b7cc98a79a318d7289d9b44f1fb266d97 Mon Sep 17 00:00:00 2001 From: Pepijn Fens Date: Fri, 15 Sep 2023 11:57:08 +0200 Subject: [PATCH] FIX api endpoints in v5&v6 classes --- src/bankid.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/bankid.ts b/src/bankid.ts index 7024c6c..49ae61d 100644 --- a/src/bankid.ts +++ b/src/bankid.ts @@ -197,7 +197,7 @@ export class RequestError extends Error { export class BankIdClient { readonly options: Required; - readonly axios: AxiosInstance; + axios: AxiosInstance; version = "v5.1"; @@ -236,11 +236,7 @@ export class BankIdClient { : path.resolve(__dirname, "../cert/", "test.ca"); } - const baseUrl = this.options.production - ? `https://appapi2.bankid.com/rp/${this.version}/` - : `https://appapi2.test.bankid.com/rp/${this.version}/`; - - this.axios = this.#createAxiosInstance(baseUrl); + this.axios = this.createAxiosInstance(); return this; } @@ -363,7 +359,11 @@ export class BankIdClient { }); } - #createAxiosInstance(baseURL: string): AxiosInstance { + createAxiosInstance(): AxiosInstance { + const baseURL = this.options.production + ? `https://appapi2.bankid.com/rp/${this.version}/` + : `https://appapi2.test.bankid.com/rp/${this.version}/`; + const ca = Buffer.isBuffer(this.options.ca) ? this.options.ca : fs.readFileSync(this.options.ca, "utf-8"); @@ -387,6 +387,7 @@ interface AuthOptionalRequirementsV6 { cardReader?: "class1" | "class2"; mrtd: boolean; certificatePolicies?: string[]; + personalNumber: string; } export interface AuthRequestV6 { @@ -436,11 +437,12 @@ interface BankIdClientSettingsV6 extends BankIdClientSettings { * @see https://www.bankid.com/en/utvecklare/guider/teknisk-integrationsguide/webbservice-api */ export class BankIdClientV6 extends BankIdClient { - version = "v6"; + version = "v6.0"; options: Required; constructor(options: BankIdClientSettingsV6) { super(options); + this.axios = this.createAxiosInstance(); this.options = { // @ts-expect-error this.options not typed after super() call. ...(this.options as Required),