@@ -66,7 +66,9 @@ export class ProxyOAuthServerProvider implements OAuthServerProvider {
66
66
const params = new URLSearchParams ( ) ;
67
67
params . set ( "token" , request . token ) ;
68
68
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
+ }
70
72
if ( request . token_type_hint ) {
71
73
params . set ( "token_type_hint" , request . token_type_hint ) ;
72
74
}
@@ -158,20 +160,30 @@ export class ProxyOAuthServerProvider implements OAuthServerProvider {
158
160
if ( ! tokenUrl ) {
159
161
throw new Error ( "No token endpoint configured" ) ;
160
162
}
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
+
161
178
const response = await fetch ( tokenUrl , {
162
179
method : "POST" ,
163
180
headers : {
164
181
"Content-Type" : "application/x-www-form-urlencoded" ,
165
182
} ,
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 ( ) ,
173
184
} ) ;
174
185
186
+
175
187
if ( ! response . ok ) {
176
188
throw new ServerError ( `Token exchange failed: ${ response . status } ` ) ;
177
189
}
@@ -194,10 +206,13 @@ export class ProxyOAuthServerProvider implements OAuthServerProvider {
194
206
const params = new URLSearchParams ( {
195
207
grant_type : "refresh_token" ,
196
208
client_id : client . client_id ,
197
- client_secret : client . client_secret || "" ,
198
209
refresh_token : refreshToken ,
199
210
} ) ;
200
211
212
+ if ( client . client_secret ) {
213
+ params . set ( "client_secret" , client . client_secret ) ;
214
+ }
215
+
201
216
if ( scopes ?. length ) {
202
217
params . set ( "scope" , scopes . join ( " " ) ) ;
203
218
}
0 commit comments