aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-06-25 18:01:11 -0300
committerSebastian <sebasjm@gmail.com>2024-06-25 18:01:11 -0300
commit4bb0adb96516a55c3036252ac088493b3d6155da (patch)
tree066e10bb94c9581d8d50c8fbda272b4c41d35773 /packages
parent5f614a10014faac707b902bab0195e1bc30bb08b (diff)
downloadwallet-core-4bb0adb96516a55c3036252ac088493b3d6155da.tar.xz
expect json
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-util/src/http-client/challenger.ts47
-rw-r--r--packages/taler-util/src/http-client/types.ts26
2 files changed, 59 insertions, 14 deletions
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<prop extends keyof ChallengerHttpClient> =
ResultByMethod<ChallengerHttpClient, prop>;
@@ -32,6 +39,7 @@ export type ChallengerErrorsByMethod<prop extends keyof ChallengerHttpClient> =
export enum ChallengerCacheEviction {
CREATE_CHALLENGE,
+ SOLVE_CHALLENGE,
}
/**
@@ -45,7 +53,7 @@ export class ChallengerHttpClient {
readonly baseUrl: string,
httpClient?: HttpRequestLibrary,
cacheEvictor?: CacheEvictor<ChallengerCacheEviction>,
- ) {
+ ) {
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<RedirectResult>({
- redirectURL: new URL(redirect),
- });
+ // case HttpStatusCode.Found:
+ // const redirect = resp.headers.get("Location")!;
+ // return opFixedSuccess<RedirectResult>({
+ // 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<RedirectResult>({
- 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<RedirectResult>({
+ // redirectURL: new URL(redirect),
+ // });
case HttpStatusCode.BadRequest:
return opKnownHttpFailure(resp.status, resp);
case HttpStatusCode.Forbidden:
diff --git a/packages/taler-util/src/http-client/types.ts b/packages/taler-util/src/http-client/types.ts
index 88a4a76d5..3069db7e8 100644
--- a/packages/taler-util/src/http-client/types.ts
+++ b/packages/taler-util/src/http-client/types.ts
@@ -1592,6 +1592,12 @@ export const codecForChallengeCreateResponse =
.property("next_tx_time", codecForString())
.build("ChallengerApi.ChallengeCreateResponse");
+export const codecForChallengeSolveResponse =
+ (): Codec<ChallengerApi.ChallengeSolveResponse> =>
+ buildCodecForObject<ChallengerApi.ChallengeSolveResponse>()
+ .property("redirect_url", codecForString())
+ .build("ChallengerApi.ChallengeSolveResponse");
+
export const codecForInvalidPinResponse =
(): Codec<ChallengerApi.InvalidPinResponse> =>
buildCodecForObject<ChallengerApi.InvalidPinResponse>()
@@ -1604,6 +1610,15 @@ export const codecForInvalidPinResponse =
.property("no_challenge", codecForBoolean())
.build("ChallengerApi.InvalidPinResponse");
+export const codecForOAuthErrorResponse =
+ (): Codec<ChallengerApi.OAuthErrorResponse> =>
+ buildCodecForObject<ChallengerApi.OAuthErrorResponse>()
+ .property("state", codecForString())
+ .property("error", codecForString())
+ .property("description", codecOptional(codecForString()))
+ .property("uri", codecOptional(codecForString()))
+ .build("ChallengerApi.OAuthErrorResponse");
+
export const codecForChallengerAuthResponse =
(): Codec<ChallengerApi.ChallengerAuthResponse> =>
buildCodecForObject<ChallengerApi.ChallengerAuthResponse>()
@@ -5396,6 +5411,11 @@ export namespace ChallengerApi {
changes_left: Integer;
}
+ export interface ChallengeSolveResponse {
+ // location where the user should be redirected
+ redirect_url: string;
+ }
+
export interface ChallengeCreateResponse {
// how many more attempts are allowed, might be shown to the user,
// highlighting might be appropriate for low values such as 1 or 2 (the
@@ -5415,6 +5435,12 @@ export namespace ChallengerApi {
next_tx_time: string;
}
+ export interface OAuthErrorResponse {
+ state: string;
+ error: string;
+ description: string | undefined;
+ uri: string | undefined;
+ }
export interface InvalidPinResponse {
// numeric Taler error code, should be shown to indicate the error
// compactly for reporting to developers