{"_id":"@cala/koa-shopify-auth","_rev":"19-e4ccdff324d492c4be289244e6e95167","name":"@cala/koa-shopify-auth","dist-tags":{"latest":"4.0.1"},"versions":{"4.0.0":{"name":"@cala/koa-shopify-auth","version":"4.0.0","author":{"name":"Shopify Inc."},"license":"MIT","_id":"@cala/koa-shopify-auth@4.0.0","maintainers":[{"name":"cala-machine-user","email":"devops@ca.la"},{"name":"nexpure","email":"nexpure@gmail.com"},{"name":"sebastiancala","email":"sebastian@ca.la"},{"name":"alekhinen","email":"nick.alekhine@gmail.com"},{"name":"sam_ca-la","email":"sam@ca.la"},{"name":"scotttrinh","email":"scott@scotttrinh.com"},{"name":"dylanpyle","email":"me@dylanpyle.com"}],"homepage":"https://github.com/ca-la/koa-shopify-auth#readme","bugs":{"url":"https://github.com/ca-la/koa-shopify-auth/issues"},"dist":{"shasum":"3a22d6c051c1d4f2ce4e91fbff75b6d4fa9e2262","tarball":"https://registry.npmjs.org/@cala/koa-shopify-auth/-/koa-shopify-auth-4.0.0.tgz","fileCount":99,"integrity":"sha512-fSGKcEPjU975AbmAJzqdfogPgdTIeIZVYo2uSedvtQNqt6ST5cffb40h3FiJHk7Nf+8W06Jfj64IIgEBV83sYA==","signatures":[{"sig":"MEQCIA/A8MGAKorMgRQeC3e1ynRIf11h/BoHGRP4I2yvCep/AiBmd7moYH53x+npVSHSfWd6noeBEG4rSW4e86ULM8uBHg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":223690,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd1FsCCRA9TVsSAnZWagAAqB8QAIM3gTsVTIJ7wrXR7Dnx\nGjG9OSwpawnvEJjiHUO946kvrl2wx/5R7/xLR1B2NaRxksuZX2CvyxjStiY1\nNtZOJ2LHxP9hwg+HvaJ1d9O2pwTDoku5dU8wgw1zHC8osdV8hWJ8xlTYC9Jn\nZiXa/pPCPwU0JWJ6+frMx1dQEDuhk6qE7/mz6Vlh1kqt2GJLqAK3EgRz9ft3\n9WXfozXS0uRYE/zar78MJ/1u5si3dDoYs1yvlZkIx1dcughVkzz1TbQt9Xcu\nUvMoa4YeL/5GcvANlPbd3plmNWvQQVfBkHxAak9lMj7P7X1GjlOptp3aZY4d\nG29Dkzy3t8jP7LPRRpCU7GmoBpa6CYtvj3ZwJytqEeIw1WU6ZHeQXI3rTGq/\n/NjU3cS4XFK7ecTbzlJzzfE6agZr3df6GlKE7SbyIyOtKjskt3ZncDsskpnr\nQIYNB0cX+/4GJ0Tcb0BGirQ639jqmWpBWVE35SK69Vnzjoty4V4J6wCBsZpH\nvc2GS5JNnCeSChhhgV+qugiVhJGa2TWqUsuJvpksdizDTreazSjf2t3dBuaj\nkSIr5cFF1KZ4P3ds6ftP98L7pMC/EnfzbAx43F9+v/gTOBG8m5UldXB1IxWz\nRXa2CA8uUtKCAm/Xh7IgOtW84Ko8ww7h8QZpvJpCjCo0mLHzewN+CRBaP8X4\n2vY4\r\n=JUjO\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/src/index.js","types":"dist/src/index.d.ts","gitHead":"83c3c29aaa7897bdcbd36c32c900684f71a649ea","_npmUser":{"name":"scotttrinh","email":"scott@scotttrinh.com"},"repository":{"url":"git+https://github.com/ca-la/koa-shopify-auth.git","type":"git"},"_npmVersion":"6.4.1","description":"Fork from [Shopify/quilt](https://github.com/Shopify/quilt).","directories":{},"sideEffects":false,"_nodeVersion":"10.15.0","dependencies":{"nonce":"^1.0.4","tslib":"^1.9.3","koa-compose":">=3.0.0 <4.0.0","safe-compare":"^1.1.2","@shopify/network":"^1.4.3"},"_hasShrinkwrap":false,"devDependencies":{"koa":"^2.5.0","jest":"^24.9.0","ts-jest":"^24.1.0","prettier":"^1.19.1","@types/koa":"^2.0.0","node-fetch":"^2.6.0","typescript":"^3.7.2","@types/jest":"^24.0.23","@types/node-fetch":"^2.5.3","@types/koa-compose":"*","@types/safe-compare":"^1.1.0","@shopify/jest-dom-mocks":"^2.8.6","@shopify/jest-koa-mocks":"^2.1.9"},"_npmOperationalInternal":{"tmp":"tmp/koa-shopify-auth_4.0.0_1574198017895_0.556940858343457","host":"s3://npm-registry-packages"}},"4.0.1":{"name":"@cala/koa-shopify-auth","version":"4.0.1","author":{"name":"Shopify Inc."},"license":"MIT","_id":"@cala/koa-shopify-auth@4.0.1","maintainers":[{"name":"alekhinen","email":"nick.alekhine@gmail.com"},{"name":"cala-machine-user","email":"devops@ca.la"},{"name":"dylanpyle","email":"me@dylanpyle.com"},{"name":"nexpure","email":"nexpure@gmail.com"},{"name":"sam_ca-la","email":"sam@ca.la"},{"name":"scotttrinh","email":"scott@scotttrinh.com"},{"name":"sebastiancala","email":"sebastian@ca.la"}],"homepage":"https://github.com/ca-la/koa-shopify-auth#readme","bugs":{"url":"https://github.com/ca-la/koa-shopify-auth/issues"},"dist":{"shasum":"8fdea9172f3bf1be878f20a24c85ec373fbc6d30","tarball":"https://registry.npmjs.org/@cala/koa-shopify-auth/-/koa-shopify-auth-4.0.1.tgz","fileCount":61,"integrity":"sha512-4ncdIMDH+tUk+MZ554ukWoOX5OTBimTkxZ6u+w+hHOF6Ni8DL0JeYgLbBh5I6EdrnWvgBq+GKbKweqrwexP1eA==","signatures":[{"sig":"MEUCIQCV3RnSV5Jcpg1rXMU0YRqdjdc7UpFNkOfdvRLBWF6swwIgLD0+gOcM1miS6EHxRTty8unfe1++0L180jG/XXV6IdI=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":169204,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2CJRCRA9TVsSAnZWagAAJlUQAIKEtT/q1UTjw2/01FmZ\n7vgAnyPEYxNj4EoHNpVIE+LJ0nq31FIN7fpB3/MJW91hSvvulT/ZV4hBW39Z\nSZ4km7X3pxb2kJSQtWjsQAtttZLE3dr6dCXc6heI0LqHYkxfvmvw6VE1UY/O\nCDaEcHS5w9dKMACi93Q12RSKCQRmSR4cWdzt9BdWKfxqU0PONZHKn1GOwK5l\nzuoEAWjWB31Eg0DTZzpkwwbRhSFfta+/SreTnWf1kIbpObijT7c03bQR035x\nzBdjmh4LiQFk5NuWrr6aMAjosYQmq34MMcLI9aXDFXs6OqAVo19kmWrJFd+e\nygeKQcZHivd06pAHqGjML9YsSK86omms9R7fBlwyn6ZlMCDzrFe0oarfWHBB\np3vJ2yTk0e1osRCeq/RL0V0JWqXyKVMN4dUzbdz30W/Io+et+OqP+0cgPTW5\nDyHM+rLmDRWeGbq68NPiH9PhFOXHr55NRzrbkq9Td6wqYeChG91ZEH/8QaZ+\nktkdhnSShRXdfGaMm1xjzw+RJsoyeuSDmCwDRXC9NlDCnYixGAZW2HmAE1tJ\ng2HJfYn6/IfTkanMKpV1vAvR6FMvGscY6EwPy/teHJRqRScE3JTVVMhdgWY4\nfL5LAMCNgKqeIzzQFzrgYm7YfrN/3G49fHKwyQENFXHn1Ab3N3uZ9aKbdCCN\naxCD\r\n=GS+K\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/src/index.js","types":"dist/src/index.d.ts","gitHead":"c866962ddceb8552a102534ec7c3037f24cd0d8b","_npmUser":{"name":"scotttrinh","email":"scott@scotttrinh.com"},"repository":{"url":"git+https://github.com/ca-la/koa-shopify-auth.git","type":"git"},"_npmVersion":"6.4.1","description":"Fork from [Shopify/quilt](https://github.com/Shopify/quilt).","directories":{},"sideEffects":false,"_nodeVersion":"10.15.0","dependencies":{"nonce":"^1.0.4","tslib":"^1.9.3","koa-compose":">=3.0.0 <4.0.0","safe-compare":"^1.1.2","@shopify/network":"^1.4.3"},"_hasShrinkwrap":false,"devDependencies":{"koa":"^2.5.0","jest":"^24.9.0","ts-jest":"^24.1.0","prettier":"^1.19.1","@types/koa":"^2.0.0","node-fetch":"^2.6.0","typescript":"^3.7.2","@types/jest":"^24.0.23","@types/node-fetch":"^2.5.3","@types/koa-compose":"*","@types/safe-compare":"^1.1.0","@shopify/jest-dom-mocks":"^2.8.6","@shopify/jest-koa-mocks":"^2.1.9"},"_npmOperationalInternal":{"tmp":"tmp/koa-shopify-auth_4.0.1_1574258895152_0.33887378904763255","host":"s3://npm-registry-packages"}}},"time":{"created":"2019-11-19T21:13:37.894Z","modified":"2025-01-15T18:31:57.604Z","4.0.0":"2019-11-19T21:13:38.053Z","4.0.1":"2019-11-20T14:08:15.301Z"},"bugs":{"url":"https://github.com/ca-la/koa-shopify-auth/issues"},"author":{"name":"Shopify Inc."},"license":"MIT","homepage":"https://github.com/ca-la/koa-shopify-auth#readme","repository":{"url":"git+https://github.com/ca-la/koa-shopify-auth.git","type":"git"},"description":"Fork from [Shopify/quilt](https://github.com/Shopify/quilt).","maintainers":[{"email":"me@dylanpyle.com","name":"dylanpyle"},{"email":"devops@ca.la","name":"cala-machine-user"},{"email":"alexandradamant@gmail.com","name":"alexandradamant"}],"readme":"# `@cala/koa-shopify-auth`\n\nFork from [Shopify/quilt](https://github.com/Shopify/quilt).\n\nMiddleware to authenticate a [Koa](http://koajs.com/) application with [Shopify](https://www.shopify.ca/).\n\nSister module to [`@shopify/shopify-express`](https://www.npmjs.com/package/@shopify/shopify-express), but simplified.\n\nFeatures you might know from the express module like the webhook middleware and proxy will be presented as their [own packages instead](https://github.com/Shopify/quilt/blob/master/packages/koa-shopify-graphql-proxy/README.md).\n\n## Installation\n\n```bash\n$ npm i @cala/koa-shopify-auth\n```\n\n## Usage\n\nThis package exposes `shopifyAuth` by default, and `verifyRequest` as a named export.\n\n```js\nimport shopifyAuth, {verifyRequest} from '@cala/koa-shopify-auth';\n```\n\n### shopifyAuth\n\nReturns an authentication middleware taking up (by default) the routes `/auth` and `/auth/callback`.\n\n```js\napp.use(\n  shopifyAuth({\n    // if specified, mounts the routes off of the given path\n    // eg. /shopify/auth, /shopify/auth/callback\n    // defaults to ''\n    prefix: '/shopify',\n    // your shopify app api key\n    apiKey: SHOPIFY_API_KEY,\n    // your shopify app secret\n    secret: SHOPIFY_SECRET,\n    // scopes to request on the merchants store\n    scopes: ['write_orders, write_products'],\n    // set access mode, default is 'online'\n    accessMode: 'offline',\n    // callback for when auth is completed\n    afterAuth(ctx) {\n      const {shop, accessToken} = ctx.session;\n\n      console.log('We did it!', accessToken);\n\n      ctx.redirect('/');\n    },\n  }),\n);\n```\n\n#### `/auth`\n\nThis route starts the oauth process. It expects a `?shop` parameter and will error out if one is not present. To install it in a store just go to `/auth?shop=myStoreSubdomain`.\n\n### `/auth/callback`\n\nYou should never have to manually go here. This route is purely for shopify to send data back during the oauth process.\n\n### verifyRequest\n\nReturns a middleware to verify requests before letting them further in the chain.\n\n```javascript\napp.use(\n  verifyRequest({\n    // path to redirect to if verification fails\n    // defaults to '/auth'\n    authRoute: '/foo/auth',\n    // path to redirect to if verification fails and there is no shop on the query\n    // defaults to '/auth'\n    fallbackRoute: '/install',\n  }),\n);\n```\n\n### Example app\n\n```javascript\nimport 'isomorphic-fetch';\n\nimport Koa from 'koa';\nimport session from 'koa-session';\nimport shopifyAuth, {verifyRequest} from '@cala/koa-shopify-auth';\n\nconst {SHOPIFY_API_KEY, SHOPIFY_SECRET} = process.env;\n\nconst app = new Koa();\napp.keys = [SHOPIFY_SECRET];\n\napp\n  // sets up secure session data on each request\n  .use(session(app))\n\n  // sets up shopify auth\n  .use(\n    shopifyAuth({\n      apiKey: SHOPIFY_API_KEY,\n      secret: SHOPIFY_SECRET,\n      scopes: ['write_orders, write_products'],\n      afterAuth(ctx) {\n        const {shop, accessToken} = ctx.session;\n\n        console.log('We did it!', accessToken);\n\n        ctx.redirect('/');\n      },\n    }),\n  )\n\n  // everything after this point will require authentication\n  .use(verifyRequest())\n\n  // application code\n  .use(ctx => {\n    ctx.body = '🎉';\n  });\n```\n\n## Gotchas\n\n### Fetch\n\nThis app uses `fetch` to make requests against shopify, and expects you to have it polyfilled. The example app code above includes a call to import it.\n\n### Session\n\nThough you can use `shopifyAuth` without a session middleware configured, `verifyRequest` expects you to have one. If you don't want to use one and have some other solution to persist your credentials, you'll need to build your own verifiction function.\n\n### Testing locally\n\nBy default this app requires that you use a `myshopify.com` host in the `shop` parameter. You can modify this to test against a local/staging environment via the `myShopifyDomain` option to `shopifyAuth` (e.g. `myshopify.io`).\n","readmeFilename":"README.md"}