Skip to content

Commit 6a90b94

Browse files
hopefully fixed auth url not having shop param
1 parent 6b92326 commit 6a90b94

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simple-koa-shopify-auth",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"description": "A better, simplified version of the (no longer supported) @Shopify/koa-shopify-auth middleware library. It removes the use of cookies for sessions (which greatly smooths the auth process), replaces a deprecated API call, and supports v2 of the official @shopify/shopify-api package.",
55
"author": "TheSecurityDev",
66
"license": "MIT",

src/create-shopify-auth.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ export default function createShopifyAuth(options: OAuthBeginConfig) {
4141

4242
// This executes for every request
4343
return async function shopifyAuthMiddleware(ctx: Context, next: Next) {
44-
const { cookies, query, path } = ctx;
45-
const queryString = new URLSearchParams(query as any).toString();
44+
const { cookies, query, querystring, path } = ctx;
4645
const shop = query.shop ? query.shop.toString() : "";
4746

4847
cookies.secure = true;
@@ -94,7 +93,7 @@ export default function createShopifyAuth(options: OAuthBeginConfig) {
9493
case err instanceof Shopify.Errors.CookieNotFound:
9594
case err instanceof Shopify.Errors.SessionNotFound:
9695
// This is likely because the OAuth session cookie expired before the merchant approved the request
97-
ctx.redirect(`${oAuthStartPath}?${queryString}`);
96+
ctx.redirect(`${oAuthStartPath}?${querystring}`);
9897
break;
9998
case err instanceof Shopify.Errors.InvalidJwtError:
10099
ctx.throw(401, err.message);

src/top-level-oauth-redirect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function createTopLevelRedirect(apiKey: string, path: string) {
4141
const hostName = Shopify.Context.HOST_NAME; // Use this instead of ctx.host to prevent issues when behind a proxy
4242
const shop = query.shop ? query.shop.toString() : "";
4343
const params = { shop };
44-
const queryString = new URLSearchParams(params).toString(); // Use this instead of ctx.queryString, because it sanitizes the query parameters we are using
44+
const queryString = new URLSearchParams(params).toString(); // Use this instead of ctx.querystring, because it sanitizes the query parameters we are using
4545
ctx.body = await getTopLevelRedirectScript(
4646
shop,
4747
`https://${hostName}${path}?${queryString}`,

src/verify-request.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,13 @@ export default function verifyRequest(options?: VerifyRequestOptions) {
3535
// Create session instance from loaded session data (if available), so we can call isActive() method on it
3636
const session = sessionData ? Session.cloneSession(sessionData, sessionData.id) : null;
3737

38-
const { query } = ctx;
39-
const queryString = new URLSearchParams(query as any).toString();
38+
const { query, querystring } = ctx;
4039
const shop = query.shop ? query.shop.toString() : "";
41-
const authUrl = `${authRoute}?${queryString}`;
4240

4341
// Login again if the shops don't match
4442
if (session && shop && session.shop !== shop) {
4543
await clearSession(ctx, accessMode);
46-
ctx.redirect(authUrl);
44+
ctx.redirect(`${authRoute}?${querystring}`);
4745
return;
4846
}
4947

@@ -86,10 +84,11 @@ export default function verifyRequest(options?: VerifyRequestOptions) {
8684
} else if (Shopify.Context.IS_EMBEDDED_APP) {
8785
shop = getShopFromAuthHeader(ctx); // Get shop from auth header
8886
}
89-
ctx.response.set(REAUTH_URL_HEADER, authUrl); // Set the reauth url header
87+
const reauthUrl = `${authRoute}?shop=${shop}`;
88+
ctx.response.set(REAUTH_URL_HEADER, reauthUrl); // Set the reauth url header
9089
} else {
9190
// Otherwise redirect to the auth page
92-
ctx.redirect(authUrl);
91+
ctx.redirect(`${authRoute}?${querystring}`);
9392
}
9493
};
9594
}

0 commit comments

Comments
 (0)