summaryrefslogtreecommitdiff
path: root/packages/taler-util/src/http-client/authentication.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-util/src/http-client/authentication.ts')
-rw-r--r--packages/taler-util/src/http-client/authentication.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/packages/taler-util/src/http-client/authentication.ts b/packages/taler-util/src/http-client/authentication.ts
index e8ef6a274..00ef21a06 100644
--- a/packages/taler-util/src/http-client/authentication.ts
+++ b/packages/taler-util/src/http-client/authentication.ts
@@ -34,6 +34,7 @@ import {
AccessToken,
TalerAuthentication,
codecForTokenSuccessResponse,
+ codecForTokenSuccessResponseMerchant,
} from "./types.js";
import { makeBearerTokenAuthHeader } from "./utils.js";
@@ -85,6 +86,35 @@ export class TalerAuthenticationHttpClient {
}
}
+ /**
+ *
+ * @returns
+ */
+ async createAccessTokenMerchant(
+ password: string,
+ body: TalerAuthentication.TokenRequest,
+ ) {
+ const url = new URL(`token`, this.baseUrl);
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ headers: {
+ Authorization: makeBearerTokenAuthHeader(password as AccessToken),
+ },
+ body,
+ });
+ switch (resp.status) {
+ case HttpStatusCode.Ok:
+ return opSuccessFromHttp(resp, codecForTokenSuccessResponseMerchant());
+ //FIXME: missing in docs
+ case HttpStatusCode.Unauthorized:
+ return opKnownHttpFailure(resp.status, resp);
+ case HttpStatusCode.NotFound:
+ return opKnownHttpFailure(resp.status, resp);
+ default:
+ return opUnknownFailure(resp, await resp.text());
+ }
+ }
+
async deleteAccessToken(token: AccessToken) {
const url = new URL(`token`, this.baseUrl);
const resp = await this.httpLib.fetch(url.href, {