diff options
author | Sebastian <sebasjm@gmail.com> | 2024-04-15 12:01:16 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-04-15 12:01:16 -0300 |
commit | a7c8f0f3edd738a59d719105cda3aa8821886b90 (patch) | |
tree | acb402075b7b0c0788ec0c5fbecfb58ece64357d /packages/taler-util/src/http-client | |
parent | 56a6c92c814547fcf8af25f183f6ecd75fbbfbb9 (diff) | |
download | wallet-core-a7c8f0f3edd738a59d719105cda3aa8821886b90.tar.xz |
fix #8604
Diffstat (limited to 'packages/taler-util/src/http-client')
-rw-r--r-- | packages/taler-util/src/http-client/authentication.ts | 4 | ||||
-rw-r--r-- | packages/taler-util/src/http-client/types.ts | 16 | ||||
-rw-r--r-- | packages/taler-util/src/http-client/utils.ts | 2 |
3 files changed, 18 insertions, 4 deletions
diff --git a/packages/taler-util/src/http-client/authentication.ts b/packages/taler-util/src/http-client/authentication.ts index b8affee7b..8897a2fa0 100644 --- a/packages/taler-util/src/http-client/authentication.ts +++ b/packages/taler-util/src/http-client/authentication.ts @@ -92,14 +92,14 @@ export class TalerAuthenticationHttpClient { * @returns */ async createAccessTokenBearer( - token: string, + token: AccessToken, body: TalerAuthentication.TokenRequest, ) { const url = new URL(`token`, this.baseUrl); const resp = await this.httpLib.fetch(url.href, { method: "POST", headers: { - Authorization: makeBearerTokenAuthHeader(token as AccessToken), + Authorization: makeBearerTokenAuthHeader(token), }, body, }); diff --git a/packages/taler-util/src/http-client/types.ts b/packages/taler-util/src/http-client/types.ts index 35603264a..94eafb329 100644 --- a/packages/taler-util/src/http-client/types.ts +++ b/packages/taler-util/src/http-client/types.ts @@ -185,10 +185,24 @@ export interface LoginToken { } declare const __ac_token: unique symbol; +/** + * Use `createAccessToken(string)` function to build one. + */ export type AccessToken = string & { [__ac_token]: true; }; +/** + * Create a rfc8959 access token. + * Adds secret-token: prefix if there is none. + * + * @param token + * @returns + */ +export function createAccessToken(token: string): AccessToken { + return (token.startsWith("secret-token:") ? token : `secret-token:${token}`) as AccessToken +} + declare const __officer_signature: unique symbol; export type OfficerSignature = string & { [__officer_signature]: true; @@ -3604,7 +3618,7 @@ export namespace TalerMerchantApi { // After the auth token has been set (with method "token"), // the value must be provided in a "Authorization: Bearer $token" // header. - token?: string; + token?: AccessToken; } export interface InstanceReconfigurationMessage { diff --git a/packages/taler-util/src/http-client/utils.ts b/packages/taler-util/src/http-client/utils.ts index c579cd852..bf186ce46 100644 --- a/packages/taler-util/src/http-client/utils.ts +++ b/packages/taler-util/src/http-client/utils.ts @@ -39,7 +39,7 @@ export function makeBasicAuthHeader( * @returns */ export function makeBearerTokenAuthHeader(token: AccessToken): string { - return `Bearer secret-token:${token}`; + return `Bearer ${token}`; } /** |