@ekanos/harness 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -237,8 +237,16 @@ async function oauthCallback(ctx) {
237
237
  const stateParam = params.get("state");
238
238
  const consumed = stateParam ? ctx.state.nonces.consume(stateParam) : { status: "unknown" };
239
239
  const returnPath = consumed.status === "unknown" ? defaultReturnPath(ctx.slug) : consumed.entry.returnPath;
240
- if (params.get("error")) {
241
- return oauthError(ctx, returnPath, "denied");
240
+ const providerError = params.get("error");
241
+ if (providerError) {
242
+ console.error(
243
+ `[harness:${ctx.slug}] oauth/callback: provider returned an error (${providerError.slice(0, 200)}): ${(params.get("error_description") ?? "").slice(0, 500)}`
244
+ );
245
+ return oauthError(
246
+ ctx,
247
+ returnPath,
248
+ providerError === "access_denied" ? "denied" : "provider_error"
249
+ );
242
250
  }
243
251
  if (consumed.status === "unknown")
244
252
  return oauthError(ctx, returnPath, "invalid");
@@ -259,7 +267,7 @@ async function oauthCallback(ctx) {
259
267
  });
260
268
  if (!exchange.ok) {
261
269
  console.error(
262
- `[harness:${ctx.slug}] oauth/callback: code exchange failed (${exchange.reason}${exchange.reason === "http_error" ? ` ${exchange.status}` : ""}${exchange.reason === "fetch_failed" ? `: ${exchange.message}` : ""}).`
270
+ `[harness:${ctx.slug}] oauth/callback: code exchange failed (${exchange.reason}${exchange.reason === "http_error" ? ` ${exchange.status}` : ""}${exchange.reason === "fetch_failed" ? `: ${exchange.message}` : ""}).${exchange.reason === "http_error" && exchange.body ? ` Provider response: ${exchange.body}` : ""}`
263
271
  );
264
272
  return oauthError(ctx, returnPath, "exchange_failed");
265
273
  }
@@ -25,7 +25,9 @@ import type { OAuthProviderDeclaration, OAuthTokens } from '@ekanos/sdk/integrat
25
25
  * Identical to the host's, because `partnerOAuthErrorParam()` in `@ekanos/sdk`
26
26
  * maps exactly these codes to user-facing copy.
27
27
  */
28
- export type PartnerOAuthErrorCode = 'denied' | 'expired' | 'invalid' | 'unauthorized' | 'not_configured' | 'exchange_failed' | 'save_failed';
28
+ export type PartnerOAuthErrorCode = 'denied' | 'expired' | 'invalid' | 'unauthorized' | 'not_configured' | 'exchange_failed' | 'save_failed'
29
+ /** The provider redirected back with an `error` other than `access_denied`. */
30
+ | 'provider_error';
29
31
  /** RFC 7636 code verifier: 32 random bytes, base64url (43 chars). */
30
32
  export declare function generateCodeVerifier(): string;
31
33
  /** RFC 7636 S256 challenge: base64url(sha256(verifier)). */
@@ -73,6 +75,20 @@ export declare function buildAuthorizeUrl(input: BuildAuthorizeUrlInput): string
73
75
  * what `raw` is for.
74
76
  */
75
77
  export declare function parseTokenResponse(payload: unknown, now: Date): OAuthTokens | null;
78
+ /**
79
+ * A provider's error body, safe to log: the client secret, the code and any
80
+ * `access_token` / `refresh_token` value are replaced, then it is truncated.
81
+ * Redaction runs before truncation so a secret cut in half cannot slip past.
82
+ */
83
+ export declare function redactProviderErrorBody(text: string, secrets: readonly string[]): string;
84
+ /** Token-endpoint client authentication: HTTP Basic, or `client_id` / `client_secret` in the body. */
85
+ export declare function applyClientAuthentication(input: {
86
+ method: 'client_secret_basic' | 'client_secret_post' | undefined;
87
+ clientId: string;
88
+ clientSecret: string;
89
+ headers: Record<string, string>;
90
+ body: URLSearchParams;
91
+ }): void;
76
92
  export interface ExchangeAuthorizationCodeInput {
77
93
  ctx: Pick<IntegrationContext, 'fetch'>;
78
94
  provider: OAuthProviderDeclaration;
@@ -88,11 +104,12 @@ export type ExchangeAuthorizationCodeResult = {
88
104
  ok: true;
89
105
  tokens: OAuthTokens;
90
106
  }
91
- /** The endpoint answered non-2xx. `status` is safe to log; the body is not. */
107
+ /** The endpoint answered non-2xx. `body` is redacted and truncated for logging. */
92
108
  | {
93
109
  ok: false;
94
110
  reason: 'http_error';
95
111
  status: number;
112
+ body: string;
96
113
  }
97
114
  /** 2xx, but not JSON or not a token response. */
98
115
  | {
@@ -108,7 +125,8 @@ export type ExchangeAuthorizationCodeResult = {
108
125
  /**
109
126
  * POST the declared `tokenUrl` through **`ctx.fetch`** — so the exchange is
110
127
  * subject to the definition's own egress list exactly as it is on the host.
111
- * Client authentication is HTTP Basic, as on the host. The response body is
112
- * NEVER logged, on any path — it is the credential.
128
+ * Client authentication follows `provider.tokenAuthMethod`, as on the host. A
129
+ * SUCCESS body is NEVER logged — it is the credential. A failure body is
130
+ * logged only after `redactProviderErrorBody`.
113
131
  */
114
132
  export declare function exchangeAuthorizationCode(input: ExchangeAuthorizationCodeInput): Promise<ExchangeAuthorizationCodeResult>;
@@ -81,6 +81,26 @@ function parseTokenResponse(payload, now) {
81
81
  raw: record
82
82
  };
83
83
  }
84
+ const ERROR_BODY_MAX_CHARS = 500;
85
+ function redactProviderErrorBody(text, secrets) {
86
+ let redacted = text.replace(/("(?:access|refresh)_token"\s*:\s*)"[^"]*"/gi, '$1"[redacted]"').replace(/((?:access|refresh)_token=)[^&\s]+/gi, "$1[redacted]");
87
+ for (const secret of secrets) {
88
+ if (secret) redacted = redacted.split(secret).join("[redacted]");
89
+ }
90
+ return redacted.slice(0, ERROR_BODY_MAX_CHARS);
91
+ }
92
+ function applyClientAuthentication(input) {
93
+ if (input.method === "client_secret_post") {
94
+ input.body.set("client_id", input.clientId);
95
+ input.body.set("client_secret", input.clientSecret);
96
+ return;
97
+ }
98
+ const basic = Buffer.from(
99
+ `${input.clientId}:${input.clientSecret}`,
100
+ "utf8"
101
+ ).toString("base64");
102
+ input.headers.Authorization = `Basic ${basic}`;
103
+ }
84
104
  async function exchangeAuthorizationCode(input) {
85
105
  const body = new URLSearchParams({
86
106
  grant_type: "authorization_code",
@@ -90,19 +110,22 @@ async function exchangeAuthorizationCode(input) {
90
110
  if (input.codeVerifier) {
91
111
  body.set("code_verifier", input.codeVerifier);
92
112
  }
93
- const basic = Buffer.from(
94
- `${input.clientId}:${input.clientSecret}`,
95
- "utf8"
96
- ).toString("base64");
113
+ const headers = {
114
+ Accept: "application/json",
115
+ "Content-Type": "application/x-www-form-urlencoded"
116
+ };
117
+ applyClientAuthentication({
118
+ method: input.provider.tokenAuthMethod,
119
+ clientId: input.clientId,
120
+ clientSecret: input.clientSecret,
121
+ headers,
122
+ body
123
+ });
97
124
  let response;
98
125
  try {
99
126
  response = await input.ctx.fetch(input.provider.tokenUrl, {
100
127
  method: "POST",
101
- headers: {
102
- Accept: "application/json",
103
- "Content-Type": "application/x-www-form-urlencoded",
104
- Authorization: `Basic ${basic}`
105
- },
128
+ headers,
106
129
  body: body.toString()
107
130
  });
108
131
  } catch (error) {
@@ -113,7 +136,13 @@ async function exchangeAuthorizationCode(input) {
113
136
  };
114
137
  }
115
138
  if (!response.ok) {
116
- return { ok: false, reason: "http_error", status: response.status };
139
+ const text = await response.text().catch(() => "");
140
+ return {
141
+ ok: false,
142
+ reason: "http_error",
143
+ status: response.status,
144
+ body: redactProviderErrorBody(text, [input.clientSecret, input.code])
145
+ };
117
146
  }
118
147
  let payload;
119
148
  try {
@@ -128,6 +157,7 @@ async function exchangeAuthorizationCode(input) {
128
157
  return { ok: true, tokens };
129
158
  }
130
159
  export {
160
+ applyClientAuthentication,
131
161
  buildAuthorizeUrl,
132
162
  callbackUrl,
133
163
  errorRedirectUrl,
@@ -136,6 +166,7 @@ export {
136
166
  generateCodeVerifier,
137
167
  generateNonce,
138
168
  parseTokenResponse,
169
+ redactProviderErrorBody,
139
170
  safeReturnPath,
140
171
  successRedirectUrl
141
172
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekanos/harness",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "The Ekanos integration dev harness — every surface of an integration rendered in real Ekanos chrome, from fixtures, with no Supabase or auth; and, in live mode, a real localhost OAuth loop over your own dev-app credentials.",
5
5
  "bugs": {
6
6
  "email": "npm@govastly.com"
@@ -63,15 +63,15 @@
63
63
  "tw-animate-css": "1.4.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@ekanos/sdk": "0.5.0",
67
- "@ekanos/ui": "0.5.0",
66
+ "@ekanos/sdk": "0.6.0",
67
+ "@ekanos/ui": "0.6.0",
68
68
  "@kit/tsconfig": "0.1.0",
69
69
  "@tailwindcss/postcss": "4.3.3",
70
70
  "@tanstack/react-query": "5.103.2",
71
71
  "@types/node": "25.0.1",
72
72
  "@types/react": "19.2.18",
73
73
  "@types/react-dom": "19.2.5",
74
- "next": "16.3.6",
74
+ "next": "16.4.0",
75
75
  "next-intl": "^4.14.7",
76
76
  "react": "19.2.8",
77
77
  "react-dom": "19.2.8",
@@ -83,8 +83,8 @@
83
83
  "zod": "4.6.5"
84
84
  },
85
85
  "peerDependencies": {
86
- "@ekanos/sdk": "^0.5.0",
87
- "@ekanos/ui": "^0.5.0",
86
+ "@ekanos/sdk": "^0.4.0 || ^0.5.0 || ^0.6.0",
87
+ "@ekanos/ui": "^0.4.0 || ^0.5.0 || ^0.6.0",
88
88
  "@tanstack/react-query": "^5.101.4",
89
89
  "next": "^16.0.0",
90
90
  "next-intl": "^4.14.7",