File tree Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -165,7 +165,13 @@ const App = () => {
165
165
}
166
166
167
167
// Default to empty array
168
- return [ ] ;
168
+ return [
169
+ {
170
+ name : "Authorization" ,
171
+ value : "Bearer " ,
172
+ enabled : false ,
173
+ } ,
174
+ ] ;
169
175
} ) ;
170
176
171
177
const [ pendingSampleRequests , setPendingSampleRequests ] = useState <
Original file line number Diff line number Diff line change @@ -914,14 +914,14 @@ describe("useConnection", () => {
914
914
expect ( headers ) . toHaveProperty ( "Authorization" , "Bearer mock-token" ) ;
915
915
} ) ;
916
916
917
- test ( "replaces empty Bearer token placeholder with OAuth token" , async ( ) => {
917
+ test ( "warns of enabled empty Bearer token" , async ( ) => {
918
918
// This test prevents regression of the bug where default "Bearer " header
919
919
// prevented OAuth token injection, causing infinite auth loops
920
920
const customHeaders : CustomHeaders = [
921
921
{
922
922
name : "Authorization" ,
923
923
value : "Bearer " , // Empty Bearer token placeholder
924
- enabled : true ,
924
+ enabled : true , // enabled
925
925
} ,
926
926
] ;
927
927
@@ -937,8 +937,8 @@ describe("useConnection", () => {
937
937
} ) ;
938
938
939
939
const headers = mockSSETransport . options ?. requestInit ?. headers ;
940
- // Should replace the empty "Bearer " with actual OAuth token
941
- expect ( headers ) . toHaveProperty ( "Authorization" , "Bearer mock-token " ) ;
940
+
941
+ expect ( headers ) . toHaveProperty ( "Authorization" , "Bearer" ) ;
942
942
// Should not have the x-custom-auth-headers since Authorization is standard
943
943
expect ( headers ) . not . toHaveProperty ( "x-custom-auth-headers" ) ;
944
944
Original file line number Diff line number Diff line change @@ -402,7 +402,7 @@ export function useConnection({
402
402
403
403
const isEmptyAuthHeader = ( header : CustomHeaders [ number ] ) =>
404
404
header . name . trim ( ) . toLowerCase ( ) === "authorization" &&
405
- header . value . trim ( ) === "Bearer " ;
405
+ header . value . trim ( ) . toLowerCase ( ) === "bearer " ;
406
406
407
407
// Check for empty Authorization headers and show validation error
408
408
const hasEmptyAuthHeader = finalHeaders . some (
@@ -418,7 +418,11 @@ export function useConnection({
418
418
} ) ;
419
419
}
420
420
421
- const needsOAuthToken = finalHeaders . length === 0 || hasEmptyAuthHeader ;
421
+ const needsOAuthToken = ! finalHeaders . some (
422
+ ( header ) =>
423
+ header . enabled &&
424
+ header . name . trim ( ) . toLowerCase ( ) === "authorization" ,
425
+ ) ;
422
426
423
427
if ( needsOAuthToken ) {
424
428
const oauthToken = ( await serverAuthProvider . tokens ( ) ) ?. access_token ;
You can’t perform that action at this time.
0 commit comments