@@ -13,6 +13,7 @@ test.describe('OAuth testing tokens @nextjs', () => {
1313 let appOrigin : string ;
1414 let consentPosts : string [ ] ;
1515 let consentTokens : ( string | null ) [ ] ;
16+ let authorizeTokens : ( string | null ) [ ] ;
1617
1718 test . beforeAll ( async ( ) => {
1819 app = createServer ( ( request , response ) => {
@@ -37,6 +38,10 @@ test.describe('OAuth testing tokens @nextjs', () => {
3738 } ) ;
3839 response . end ( 'Consent accepted' ) ;
3940 } ) ;
41+ } else if ( url . pathname === '/oauth/authorize/continue' ) {
42+ authorizeTokens . push ( url . searchParams . get ( '__clerk_testing_token' ) ) ;
43+ response . writeHead ( 303 , { location : url . searchParams . get ( 'callback' ) || '/' } ) ;
44+ response . end ( 'Authorized' ) ;
4045 } else {
4146 response . end ( JSON . stringify ( { url : request . url , method : request . method } ) ) ;
4247 }
@@ -49,6 +54,7 @@ test.describe('OAuth testing tokens @nextjs', () => {
4954 test . beforeEach ( async ( { context } ) => {
5055 consentPosts = [ ] ;
5156 consentTokens = [ ] ;
57+ authorizeTokens = [ ] ;
5258 await setupTestingTokens ( { context, frontendApiOrigin : appOrigin , token : 'app-testing-token' } ) ;
5359 } ) ;
5460
@@ -95,6 +101,22 @@ test.describe('OAuth testing tokens @nextjs', () => {
95101 expect ( ( await context . cookies ( providerOrigin ) ) . map ( cookie => cookie . name ) . sort ( ) ) . toEqual ( [ 'consent' , 'provider' ] ) ;
96102 } ) ;
97103
104+ test ( 'delivers the token on the callback when the provider skips the consent screen' , async ( { page, context } ) => {
105+ await setupTestingTokens ( { context, frontendApiOrigin : providerOrigin , token : 'provider-testing-token' } ) ;
106+ const callback = new URL ( '/v1/oauth_callback?code=auth-code&state=a%2Bb%2F%3D' , appOrigin ) ;
107+ const authorize = new URL ( '/oauth/authorize/continue' , providerOrigin ) ;
108+ authorize . searchParams . set ( 'callback' , callback . toString ( ) ) ;
109+ await page . goto ( authorize . toString ( ) ) ;
110+
111+ expect ( authorizeTokens ) . toEqual ( [ null ] ) ;
112+ const received = JSON . parse ( ( await page . locator ( 'body' ) . textContent ( ) ) || '{}' ) ;
113+ expect ( Object . fromEntries ( new URL ( received . url , appOrigin ) . searchParams ) ) . toEqual ( {
114+ code : 'auth-code' ,
115+ state : 'a+b/=' ,
116+ __clerk_testing_token : 'app-testing-token' ,
117+ } ) ;
118+ } ) ;
119+
98120 for ( const [ name , getCallback ] of [
99121 [ 'another origin' , ( ) => new URL ( '/v1/oauth_callback?code=auth-code' , providerOrigin ) ] ,
100122 [ 'another path' , ( ) => new URL ( '/sso-callback?code=auth-code' , appOrigin ) ] ,
0 commit comments