-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move session fetching and request validation to authenticate
Co-authored-by: Paulo Margarido <[email protected]> Co-authored-by: Rezaan Syed <[email protected]>
- Loading branch information
1 parent
02511ee
commit cd4e13d
Showing
5 changed files
with
127 additions
and
122 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
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
28 changes: 28 additions & 0 deletions
28
.../shopify-app-remix/src/server/authenticate/admin/helpers/validate-shop-and-host-params.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,28 @@ | ||
import {redirect} from '@remix-run/server-runtime'; | ||
import {BasicParams} from 'src/server/types'; | ||
|
||
export function validateShopAndHostParams( | ||
params: BasicParams, | ||
request: Request, | ||
) { | ||
const {api, config, logger} = params; | ||
|
||
if (config.isEmbeddedApp) { | ||
const url = new URL(request.url); | ||
const shop = api.utils.sanitizeShop(url.searchParams.get('shop')!); | ||
if (!shop) { | ||
logger.debug('Missing or invalid shop, redirecting to login path', { | ||
shop, | ||
}); | ||
throw redirect(config.auth.loginPath); | ||
} | ||
|
||
const host = api.utils.sanitizeHost(url.searchParams.get('host')!); | ||
if (!host) { | ||
logger.debug('Invalid host, redirecting to login path', { | ||
host: url.searchParams.get('host'), | ||
}); | ||
throw redirect(config.auth.loginPath); | ||
} | ||
} | ||
} |
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
11 changes: 5 additions & 6 deletions
11
packages/shopify-app-remix/src/server/authenticate/admin/strategies/types.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 |
---|---|---|
@@ -1,17 +1,16 @@ | ||
import {JwtPayload} from '@shopify/shopify-api'; | ||
|
||
import {SessionContext} from '../types'; | ||
import {JwtPayload, Session} from '@shopify/shopify-api'; | ||
|
||
export interface SessionTokenContext { | ||
shop: string; | ||
sessionId: string; | ||
sessionId?: string; | ||
payload?: JwtPayload; | ||
} | ||
|
||
export interface AuthorizationStrategy { | ||
respondToOAuthRequests: (request: Request) => Promise<void | never>; | ||
authenticate: ( | ||
request: Request, | ||
sessionToken: string, | ||
) => Promise<SessionContext | never>; | ||
session: Session | undefined, | ||
shop: string, | ||
) => Promise<Session | never>; | ||
} |