-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
220 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...ify-app-remix/src/server/authenticate/admin/helpers/ensure-app-is-embedded-if-required.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {BasicParams} from '../../../types'; | ||
|
||
import {redirectToShopifyOrAppRoot} from './redirect-to-shopify-or-app-root'; | ||
|
||
export const ensureAppIsEmbeddedIfRequired = async ( | ||
params: BasicParams, | ||
request: Request, | ||
) => { | ||
const {api, logger, config} = params; | ||
const url = new URL(request.url); | ||
|
||
const shop = url.searchParams.get('shop')!; | ||
|
||
if (api.config.isEmbeddedApp && url.searchParams.get('embedded') !== '1') { | ||
logger.debug('App is not embedded, redirecting to Shopify', {shop}); | ||
await redirectToShopifyOrAppRoot(request, {api, logger, config}); | ||
} | ||
}; |
25 changes: 25 additions & 0 deletions
25
...ix/src/server/authenticate/admin/helpers/ensure-session-token-search-param-if-required.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {BasicParams} from '../../../types'; | ||
|
||
import {redirectToBouncePage} from './redirect-to-bounce-page'; | ||
|
||
const SESSION_TOKEN_PARAM = 'id_token'; | ||
|
||
export const ensureSessionTokenSearchParamIfRequired = async ( | ||
params: BasicParams, | ||
request: Request, | ||
) => { | ||
const {api, logger} = params; | ||
const url = new URL(request.url); | ||
|
||
const shop = url.searchParams.get('shop')!; | ||
const searchParamSessionToken = url.searchParams.get(SESSION_TOKEN_PARAM); | ||
const isEmbedded = url.searchParams.get('embedded') === '1'; | ||
|
||
if (api.config.isEmbeddedApp && isEmbedded && !searchParamSessionToken) { | ||
logger.debug( | ||
'Missing session token in search params, going to bounce page', | ||
{shop}, | ||
); | ||
redirectToBouncePage(params, url); | ||
} | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/shopify-app-remix/src/server/authenticate/admin/helpers/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/shopify-app-remix/src/server/authenticate/admin/helpers/redirect-to-bounce-page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {redirect} from '@remix-run/server-runtime'; | ||
|
||
import {BasicParams} from '../../../types'; | ||
|
||
export const redirectToBouncePage = (params: BasicParams, url: URL): never => { | ||
const {config} = params; | ||
|
||
// Make sure we always point to the configured app URL so it also works behind reverse proxies (that alter the Host | ||
// header). | ||
url.searchParams.set( | ||
'shopify-reload', | ||
`${config.appUrl}${url.pathname}${url.search}`, | ||
); | ||
|
||
// eslint-disable-next-line no-warning-comments | ||
// TODO Make sure this works on chrome without a tunnel (weird HTTPS redirect issue) | ||
// https://github.com/orgs/Shopify/projects/6899/views/1?pane=issue&itemId=28376650 | ||
throw redirect(`${config.auth.patchSessionTokenPath}${url.search}`); | ||
}; |
Oops, something went wrong.