Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
fix request used to check oauth (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaKXz committed Feb 15, 2022
1 parent bd85cdd commit 3ef7f0a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed
- Replace deprecated metafields API request used for oauth token check with longer lived call to the shop endpoint [144](https://github.com/Shopify/koa-shopify-auth/pull/144)

## [4.1.4] - 2021-07-19
### Fixed
- Retry OAuth if cookie / session has expired on callback [112](https://github.com/Shopify/koa-shopify-auth/pull/112)
Expand Down
9 changes: 3 additions & 6 deletions src/verify-request/tests/verify-request.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import '../../test/test_helper';

import {createMockContext} from '@shopify/jest-koa-mocks';
import {StatusCode} from '@shopify/network';
import Shopify, { RequestReturn } from '@shopify/shopify-api';
import jwt from 'jsonwebtoken';

import verifyRequest from '../verify-request';
import {clearSession} from '../utilities';
import {TEST_COOKIE_NAME, TOP_LEVEL_OAUTH_COOKIE_NAME} from '../../index';
import {REAUTH_HEADER, REAUTH_URL_HEADER} from '../verify-token';
import { clear } from 'console';
const TEST_SHOP = 'testshop.myshopify.io';
const TEST_USER = '1';

Expand Down Expand Up @@ -41,10 +39,9 @@ describe('verifyRequest', () => {
session.scope = 'test_scope';
await Shopify.Utils.storeSession(session);

// mocking metafields call from client.get()
Shopify.Clients.Rest.prototype.get = jest.fn(({path, query}) => {
expect(path).toEqual('metafields');
expect(query).toEqual({'limit': 1})
// mocking shop call from client.get()
Shopify.Clients.Rest.prototype.get = jest.fn(({path}) => {
expect(path).toEqual('shop');
return Promise.resolve({ "body": "" } as RequestReturn);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/verify-request/verify-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function verifyToken(routes: Routes, accessMode: AccessMode = DEFAULT_ACC
try {
// make a request to make sure oauth has succeeded, retry otherwise
const client = new Shopify.Clients.Rest(session.shop, session.accessToken)
await client.get({ path: "metafields", query: {'limit': 1} })
await client.get({path: 'shop'});

ctx.cookies.set(TOP_LEVEL_OAUTH_COOKIE_NAME);
await next();
Expand Down

0 comments on commit 3ef7f0a

Please sign in to comment.