@@ -77,7 +77,7 @@ describe('store auth service', () => {
7777 } )
7878 } )
7979
80- test ( 'authenticateStoreWithApp includes signup JWT in the authorization URL when provided' , async ( ) => {
80+ test ( 'authenticateStoreWithApp opens a loopback handoff URL when a signup JWT is provided' , async ( ) => {
8181 const openURL = vi . fn ( ) . mockResolvedValue ( true )
8282 const presenter = {
8383 openingBrowser : vi . fn ( ) ,
@@ -110,7 +110,12 @@ describe('store auth service', () => {
110110 )
111111
112112 const authorizationUrl = new URL ( openURL . mock . calls [ 0 ] ! [ 0 ] )
113- expect ( authorizationUrl . searchParams . get ( 'signup' ) ) . toBe ( 'signed.signup.jwt' )
113+ expect ( authorizationUrl . hostname ) . toBe ( '127.0.0.1' )
114+ expect ( authorizationUrl . pathname ) . toBe ( '/auth/handoff' )
115+ expect ( authorizationUrl . searchParams . get ( 'signup' ) ) . toBeNull ( )
116+
117+ const waitOptions = waitForStoreAuthCodeMock . mock . calls [ 0 ] ! [ 0 ]
118+ expect ( waitOptions . authorizationRedirect . authorizationUrl ) . toContain ( 'signup=signed.signup.jwt' )
114119 } )
115120
116121 test ( 'authenticateStoreWithApp uses remote scopes by default when available' , async ( ) => {
@@ -309,7 +314,7 @@ describe('store auth service', () => {
309314 expect ( presenter . success ) . toHaveBeenCalledWith ( result )
310315 } )
311316
312- test ( 'authenticateStoreWithApp marks manual auth URL as sensitive when signup JWT is present' , async ( ) => {
317+ test ( 'authenticateStoreWithApp prints the non-sensitive loopback handoff URL when signup JWT is present' , async ( ) => {
313318 const openURL = vi . fn ( ) . mockResolvedValue ( false )
314319 const presenter = {
315320 openingBrowser : vi . fn ( ) ,
@@ -321,63 +326,30 @@ describe('store auth service', () => {
321326 return 'abc123'
322327 } )
323328
324- await expect (
325- authenticateStoreWithApp (
326- {
327- store : 'shop.myshopify.com' ,
328- scopes : 'read_products' ,
329- signup : 'signed.signup.jwt' ,
330- } ,
331- {
332- openURL,
333- waitForStoreAuthCode : waitForStoreAuthCodeMock ,
334- exchangeStoreAuthCodeForToken : vi . fn ( ) . mockResolvedValue ( {
335- access_token : 'token' ,
336- scope : 'read_products' ,
337- expires_in : 86400 ,
338- associated_user : { id : 42 , email : 'test@example.com' } ,
339- } ) ,
340- presenter,
341- } ,
342- ) ,
343- ) . rejects . toThrow ( )
344-
345- expect ( presenter . manualAuthUrl ) . toHaveBeenCalledWith ( expect . stringContaining ( 'signup=signed.signup.jwt' ) , {
346- sensitive : true ,
347- } )
348- } )
349-
350- test ( 'authenticateStoreWithApp fails immediately instead of waiting for a callback that cannot arrive' , async ( ) => {
351- const openURL = vi . fn ( ) . mockResolvedValue ( false )
352- const presenter = {
353- openingBrowser : vi . fn ( ) ,
354- manualAuthUrl : vi . fn ( ) ,
355- success : vi . fn ( ) ,
356- }
357- const exchangeStoreAuthCodeForToken = vi . fn ( )
358- const waitForStoreAuthCodeMock = vi . fn ( ) . mockImplementation ( async ( options ) => {
359- await options . onListening ?.( )
360- return 'abc123'
361- } )
362-
363- await expect (
364- authenticateStoreWithApp (
365- {
366- store : 'shop.myshopify.com' ,
367- scopes : 'read_products' ,
368- signup : 'signed.signup.jwt' ,
369- } ,
370- {
371- openURL,
372- waitForStoreAuthCode : waitForStoreAuthCodeMock ,
373- exchangeStoreAuthCodeForToken,
374- presenter,
375- } ,
376- ) ,
377- ) . rejects . toThrow ( "Authentication can't continue without a browser." )
329+ await authenticateStoreWithApp (
330+ {
331+ store : 'shop.myshopify.com' ,
332+ scopes : 'read_products' ,
333+ signup : 'signed.signup.jwt' ,
334+ } ,
335+ {
336+ openURL,
337+ waitForStoreAuthCode : waitForStoreAuthCodeMock ,
338+ exchangeStoreAuthCodeForToken : vi . fn ( ) . mockResolvedValue ( {
339+ access_token : 'token' ,
340+ scope : 'read_products' ,
341+ expires_in : 86400 ,
342+ associated_user : { id : 42 , email : 'test@example.com' } ,
343+ } ) ,
344+ presenter,
345+ } ,
346+ )
378347
379- expect ( exchangeStoreAuthCodeForToken ) . not . toHaveBeenCalled ( )
380- expect ( presenter . success ) . not . toHaveBeenCalled ( )
348+ expect ( presenter . manualAuthUrl ) . toHaveBeenCalledWith (
349+ expect . stringContaining ( 'http://127.0.0.1:13387/auth/handoff?nonce=' ) ,
350+ { sensitive : false } ,
351+ )
352+ expect ( presenter . manualAuthUrl . mock . calls [ 0 ] ! [ 0 ] ) . not . toContain ( 'signed.signup.jwt' )
381353 } )
382354
383355 test ( 'authenticateStoreWithApp records fqdn metadata before resolving existing scopes' , async ( ) => {
0 commit comments