diff options
author | Sebastian <sebasjm@gmail.com> | 2024-03-22 13:56:16 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-03-26 16:57:58 -0300 |
commit | e2bfbced7ab027c901913e83ff7dd82240661990 (patch) | |
tree | 33752605ccaf19498f8c2a64e0117db16f22ce26 /packages/taler-util/src/http-client/authentication.ts | |
parent | 0c265558c4b7b78a13272abf1c4c84e3cf93c987 (diff) | |
download | wallet-core-e2bfbced7ab027c901913e83ff7dd82240661990.tar.gz wallet-core-e2bfbced7ab027c901913e83ff7dd82240661990.tar.bz2 wallet-core-e2bfbced7ab027c901913e83ff7dd82240661990.zip |
work in progress, new api being used. merchant now should move into using the full API
Diffstat (limited to 'packages/taler-util/src/http-client/authentication.ts')
-rw-r--r-- | packages/taler-util/src/http-client/authentication.ts | 30 |
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, { |