koa-shopify-auth icon indicating copy to clipboard operation
koa-shopify-auth copied to clipboard

Old version of shopify-api

Open ChaseWNorton opened this issue 3 years ago • 10 comments

Issue summary

Is this repo even maintained anymore? We need to set a depreciated notice if not. Write a short description of the issue here ↓

Expected behavior

What do you think should happen?

Actual behavior

What actually happens?

Tip: include an error message (in a <details></details> tag) if your issue is related to an error

Steps to reproduce the problem

Reduced test case

The best way to get your bug fixed is to provide a reduced test case.


Checklist

  • [ ] Please delete the labels section before submitting your issue
  • [ ] I have described this issue in a way that is actionable (if possible)

ChaseWNorton avatar Nov 07 '21 02:11 ChaseWNorton

Hi @ChaseWNorton, thanks for raising this. We're actually in the process of deprecating this repo, since most of the support it adds isn't needed any more - mostly code to work around ITP checks and 3rd party cookies which are no longer allowed for apps.

Going forward, our sample app is going to be borrowing the verifyRequest middleware from this package, and replacing it with direct calls to the shopify-api library (v2).

We'll mark it as deprecated as soon as we release those changes!

paulomarg avatar Nov 08 '21 13:11 paulomarg

Hi @ChaseWNorton, thanks for raising this. We're actually in the process of deprecating this repo, since most of the support it adds isn't needed any more - mostly code to work around ITP checks and 3rd party cookies which are no longer allowed for apps.

Going forward, our sample app is going to be borrowing the verifyRequest middleware from this package, and replacing it with direct calls to the shopify-api library (v2).

We'll mark it as deprecated as soon as we release those changes!

I appreciate the update! I've actually been debugging this for about an hour before I found this reply and realized there were breaking changes.

Maybe put a small disclaimer in this package's Readme mentioning that this package is planned to be deprecated? If I had known it was soon to be deprecated I wouldn't have bothered using this package and would have instead used the official shopify-api package.

limeforadime avatar Dec 06 '21 11:12 limeforadime

I have created an improved version of this library which fixes this and other issues. You can find it at https://github.com/TheSecurityDev/simple-koa-shopify-auth.

Or via NPM: https://www.npmjs.com/package/simple-koa-shopify-auth.

TheSecurityDev avatar Jan 09 '22 00:01 TheSecurityDev

I have created an improved version of this library which fixes this and other issues. You can find it at https://www.npmjs.com/package/simple-koa-shopify-auth.

Very cool! Thanks for making this! Will check it out.

limeforadime avatar Jan 09 '22 11:01 limeforadime

@TheSecurityDev When using simple-koa-shopify-auth the session is not created, as if my CustomSessionStorage is never called. It was working fine before switching to simple-koa-shopify-auth

Shopify.Context.initialize({
    API_KEY        : process.env.SHOPIFY_API_KEY,
    API_SECRET_KEY : process.env.SHOPIFY_API_SECRET,
    SCOPES         : process.env.SCOPES.split(","),
    HOST_NAME      : process.env.HOST.replace(/https:\/\//, ""),
    API_VERSION    : ApiVersion.October20,
    IS_EMBEDDED_APP: true,
    // This should be replaced with your preferred storage strategy
    // SESSION_STORAGE: new Shopify.Session.MemorySessionStorage(),
    SESSION_STORAGE: new Shopify.Session.CustomSessionStorage(
      sessionStorage.storeCallback,
      sessionStorage.loadCallback,
      sessionStorage.deleteCallback
    )
  });

Any clue?

redochka avatar Jan 17 '22 21:01 redochka

@redochka It's a change in Shopify Node API rather than simple-koa-shopify-auth.

In your loadCallback method of the session storage when you successfully retrieve the session object, initiate the session with Shopify.Session.Session instance and return the instance to loadCallback method.

import Shopify from "@shopify/shopify-api";
...
...
loadCallback = async (id) => {
  try {
    ...
    ...
      const sessionData = JSON.parse(data);
      const session = new Shopify.Session.Session(
        id,
        sessionData.shop,
        sessionData.state,
        sessionData.isOnline
      );
      session.scope = sessionData.scope;
      session.accessToken = sessionData.accessToken;
      session.expires = sessionData.expires;
      return session;
    }

    return undefined;
  } catch (err) {
    throw new Error(err);
  }
};

Edit: The latest version should have fixed it. @TheSecurityDev can confirm.

rahilwazir avatar Jan 17 '22 21:01 rahilwazir

@rahilwazir my loadCallback is not called. So the code that you suggested will not get a chance to run

redochka avatar Jan 17 '22 21:01 redochka

@TheSecurityDev When using simple-koa-shopify-auth the session is not created, as if my CustomSessionStorage is never called. It was working fine before switching to simple-koa-shopify-auth

Shopify.Context.initialize({
    API_KEY        : process.env.SHOPIFY_API_KEY,
    API_SECRET_KEY : process.env.SHOPIFY_API_SECRET,
    SCOPES         : process.env.SCOPES.split(","),
    HOST_NAME      : process.env.HOST.replace(/https:\/\//, ""),
    API_VERSION    : ApiVersion.October20,
    IS_EMBEDDED_APP: true,
    // This should be replaced with your preferred storage strategy
    // SESSION_STORAGE: new Shopify.Session.MemorySessionStorage(),
    SESSION_STORAGE: new Shopify.Session.CustomSessionStorage(
      sessionStorage.storeCallback,
      sessionStorage.loadCallback,
      sessionStorage.deleteCallback
    )
  });

Any clue?

Make sure you are using the latest version of the library (v1.0.4), and make sure you are using Shopify Node API library V2.

If it still doesn't work, open an issue in the repository and I'll try to help you further.

TheSecurityDev avatar Jan 17 '22 21:01 TheSecurityDev

@TheSecurityDev yes latest version of the library is used

"simple-koa-shopify-auth": "^1.0.4",
"@shopify/shopify-api": "^2.0.0",

I opened an issue Thanks

redochka avatar Jan 18 '22 09:01 redochka

in your yarn.lock or package-lock.json upgrade the dependencies version yourself

Screenshot 2022-06-18 131629

Delete your node_modules folder and reinstall your packages after.

nzmitch avatar Jun 18 '22 01:06 nzmitch

Note that this repo is no longer maintained and this issue will not be reviewed. Prefer the official JavaScript API library. If you still want to use Koa, see simple-koa-shopify-auth for a potential community solution.

github-actions[bot] avatar Jan 30 '23 20:01 github-actions[bot]