Skip to content

Commit 9e32fd5

Browse files
committed
Only send client secret and code verifier if defined
1 parent 7f03f13 commit 9e32fd5

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/server/auth/proxyProvider.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ export class ProxyOAuthServerProvider implements OAuthServerProvider {
6666
const params = new URLSearchParams();
6767
params.set("token", request.token);
6868
params.set("client_id", client.client_id);
69-
params.set("client_secret", client.client_secret || "");
69+
if (client.client_secret) {
70+
params.set("client_secret", client.client_secret);
71+
}
7072
if (request.token_type_hint) {
7173
params.set("token_type_hint", request.token_type_hint);
7274
}
@@ -158,20 +160,30 @@ export class ProxyOAuthServerProvider implements OAuthServerProvider {
158160
if (!tokenUrl) {
159161
throw new Error("No token endpoint configured");
160162
}
163+
164+
const params = new URLSearchParams({
165+
grant_type: "authorization_code",
166+
client_id: client.client_id,
167+
code: authorizationCode,
168+
});
169+
170+
if (client.client_secret) {
171+
params.append("client_secret", client.client_secret);
172+
}
173+
174+
if (codeVerifier) {
175+
params.append("code_verifier", codeVerifier);
176+
}
177+
161178
const response = await fetch(tokenUrl, {
162179
method: "POST",
163180
headers: {
164181
"Content-Type": "application/x-www-form-urlencoded",
165182
},
166-
body: new URLSearchParams({
167-
grant_type: "authorization_code",
168-
client_id: client.client_id,
169-
client_secret: client.client_secret || "",
170-
code: authorizationCode,
171-
code_verifier: codeVerifier || "",
172-
}),
183+
body: params.toString(),
173184
});
174185

186+
175187
if (!response.ok) {
176188
throw new ServerError(`Token exchange failed: ${response.status}`);
177189
}
@@ -194,10 +206,13 @@ export class ProxyOAuthServerProvider implements OAuthServerProvider {
194206
const params = new URLSearchParams({
195207
grant_type: "refresh_token",
196208
client_id: client.client_id,
197-
client_secret: client.client_secret || "",
198209
refresh_token: refreshToken,
199210
});
200211

212+
if (client.client_secret) {
213+
params.set("client_secret", client.client_secret);
214+
}
215+
201216
if (scopes?.length) {
202217
params.set("scope", scopes.join(" "));
203218
}

0 commit comments

Comments
 (0)