From 4bb0adb96516a55c3036252ac088493b3d6155da Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 25 Jun 2024 18:01:11 -0300 Subject: expect json --- packages/taler-util/src/http-client/challenger.ts | 47 ++++++++++++++++------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'packages/taler-util/src/http-client/challenger.ts') diff --git a/packages/taler-util/src/http-client/challenger.ts b/packages/taler-util/src/http-client/challenger.ts index aa530570d..1c1ad28d9 100644 --- a/packages/taler-util/src/http-client/challenger.ts +++ b/packages/taler-util/src/http-client/challenger.ts @@ -1,7 +1,10 @@ import { HttpRequestLibrary, readTalerErrorResponse } from "../http-common.js"; import { HttpStatusCode } from "../http-status-codes.js"; import { createPlatformHttpLib } from "../http.js"; -import { TalerCoreBankCacheEviction } from "../index.node.js"; +import { + codecForChallengeSolveResponse, + codecForOAuthErrorResponse, +} from "../index.js"; import { LibtoolVersion } from "../libtool-version.js"; import { FailCasesByMethod, @@ -23,7 +26,11 @@ import { codecForChallengerTermsOfServiceResponse, codecForInvalidPinResponse, } from "./types.js"; -import { CacheEvictor, makeBearerTokenAuthHeader, nullEvictor } from "./utils.js"; +import { + CacheEvictor, + makeBearerTokenAuthHeader, + nullEvictor, +} from "./utils.js"; export type ChallengerResultByMethod = ResultByMethod; @@ -32,6 +39,7 @@ export type ChallengerErrorsByMethod = export enum ChallengerCacheEviction { CREATE_CHALLENGE, + SOLVE_CHALLENGE, } /** @@ -45,7 +53,7 @@ export class ChallengerHttpClient { readonly baseUrl: string, httpClient?: HttpRequestLibrary, cacheEvictor?: CacheEvictor, - ) { + ) { this.httpLib = httpClient ?? createPlatformHttpLib(); this.cacheEvictor = cacheEvictor ?? nullEvictor; } @@ -116,7 +124,6 @@ export class ChallengerHttpClient { if (state) { url.searchParams.set("state", state); } - // url.searchParams.set("scope", "code"); const resp = await this.httpLib.fetch(url.href, { method: "POST", }); @@ -160,13 +167,19 @@ export class ChallengerHttpClient { ); return opSuccessFromHttp(resp, codecForChallengeCreateResponse()); } - case HttpStatusCode.Found: - const redirect = resp.headers.get("Location")!; - return opFixedSuccess({ - redirectURL: new URL(redirect), - }); + // case HttpStatusCode.Found: + // const redirect = resp.headers.get("Location")!; + // return opFixedSuccess({ + // redirectURL: new URL(redirect), + // }); case HttpStatusCode.BadRequest: return opKnownHttpFailure(resp.status, resp); + case HttpStatusCode.Forbidden: + return opKnownAlternativeFailure( + resp, + resp.status, + codecForOAuthErrorResponse(), + ); case HttpStatusCode.NotFound: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.NotAcceptable: @@ -197,11 +210,17 @@ export class ChallengerHttpClient { redirect: "manual", }); switch (resp.status) { - case HttpStatusCode.Found: - const redirect = resp.headers.get("Location")!; - return opFixedSuccess({ - redirectURL: new URL(redirect), - }); + case HttpStatusCode.Ok: { + await this.cacheEvictor.notifySuccess( + ChallengerCacheEviction.SOLVE_CHALLENGE, + ); + return opSuccessFromHttp(resp, codecForChallengeSolveResponse()); + } + // case HttpStatusCode.Found: + // const redirect = resp.headers.get("Location")!; + // return opFixedSuccess({ + // redirectURL: new URL(redirect), + // }); case HttpStatusCode.BadRequest: return opKnownHttpFailure(resp.status, resp); case HttpStatusCode.Forbidden: -- cgit v1.2.3