@@ -322,7 +322,8 @@ describe('Token Handler', () => {
322322 client_secret : 'valid-secret' ,
323323 grant_type : 'authorization_code' ,
324324 code : 'valid_code' ,
325- code_verifier : 'any_verifier'
325+ code_verifier : 'any_verifier' ,
326+ redirect_uri : 'https://example.com/callback'
326327 } ) ;
327328
328329 expect ( response . status ) . toBe ( 200 ) ;
@@ -342,6 +343,69 @@ describe('Token Handler', () => {
342343 global . fetch = originalFetch ;
343344 }
344345 } ) ;
346+
347+ it ( 'passes through redirect_uri when using proxy provider' , async ( ) => {
348+ const originalFetch = global . fetch ;
349+
350+ try {
351+ global . fetch = jest . fn ( ) . mockResolvedValue ( {
352+ ok : true ,
353+ json : ( ) => Promise . resolve ( {
354+ access_token : 'mock_access_token' ,
355+ token_type : 'bearer' ,
356+ expires_in : 3600 ,
357+ refresh_token : 'mock_refresh_token'
358+ } )
359+ } ) ;
360+
361+ const proxyProvider = new ProxyOAuthServerProvider ( {
362+ endpoints : {
363+ authorizationUrl : 'https://example.com/authorize' ,
364+ tokenUrl : 'https://example.com/token'
365+ } ,
366+ verifyAccessToken : async ( token ) => ( {
367+ token,
368+ clientId : 'valid-client' ,
369+ scopes : [ 'read' , 'write' ] ,
370+ expiresAt : Date . now ( ) / 1000 + 3600
371+ } ) ,
372+ getClient : async ( clientId ) => clientId === 'valid-client' ? validClient : undefined
373+ } ) ;
374+
375+ const proxyApp = express ( ) ;
376+ const options : TokenHandlerOptions = { provider : proxyProvider } ;
377+ proxyApp . use ( '/token' , tokenHandler ( options ) ) ;
378+
379+ const redirectUri = 'https://example.com/callback' ;
380+ const response = await supertest ( proxyApp )
381+ . post ( '/token' )
382+ . type ( 'form' )
383+ . send ( {
384+ client_id : 'valid-client' ,
385+ client_secret : 'valid-secret' ,
386+ grant_type : 'authorization_code' ,
387+ code : 'valid_code' ,
388+ code_verifier : 'any_verifier' ,
389+ redirect_uri : redirectUri
390+ } ) ;
391+
392+ expect ( response . status ) . toBe ( 200 ) ;
393+ expect ( response . body . access_token ) . toBe ( 'mock_access_token' ) ;
394+
395+ expect ( global . fetch ) . toHaveBeenCalledWith (
396+ 'https://example.com/token' ,
397+ expect . objectContaining ( {
398+ method : 'POST' ,
399+ headers : {
400+ 'Content-Type' : 'application/x-www-form-urlencoded'
401+ } ,
402+ body : expect . stringContaining ( `redirect_uri=${ encodeURIComponent ( redirectUri ) } ` )
403+ } )
404+ ) ;
405+ } finally {
406+ global . fetch = originalFetch ;
407+ }
408+ } ) ;
345409 } ) ;
346410
347411 describe ( 'Refresh token grant' , ( ) => {
0 commit comments