Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
shopify-express-auth
Advanced tools
Middleware to authenticate an Express application with Shopify. Works in sync with @shopify/shopify-api
version 2.0.0
Why do I need this? What does this middleware do?
Make sure you have already installed @shopify/shopify-api
version 2.0.0 . In case you have not installed it yet. Use the following command to install it
npm
npm install @shopify/shopify-api@2.0.0
yarn
yarn add @shopify/shopify-api@2.0.0
Initialize @shopify/shopify-api
import Shopify, {ApiVersion} from '@shopify/shopify-api';
Shopify.Context.initialize({
API_KEY: 'YOUR_APP_API_KEY',
API_SECRET_KEY: 'YOUR_APP_API_SECRET_KEY',
SCOPES: ['APP_SCOPES'],
HOST_NAME: ('YOUR_HOST').replace(/https:\/\//, ""),
API_VERSION: ApiVersion.July21,
IS_EMBEDDED_APP: true,
SESSION_STORAGE: new Shopify.Session.MemorySessionStorage(),
});
Note: Make sure you replace
SESSION_STORAGE: new Shopify.Session.MemorySessionStorage()
by
SESSION_STORAGE: new Shopify.Session.CustomSessionStorage(
'YOUR_CUSTOM_STORAGE'.storeCallback,
'YOUR_CUSTOM_STORAGE'.loadCallback,
'YOUR_CUSTOM_STORAGE'.deleteCallback)
in production environment once you have set up your Custom Session storage. MemorySessionStorage()
should work fine in development environment.
Once you have satisfied all the prerequisite conditions, install this package via:
npm
npm install shopify-express-auth
yarn
yarn add shopify-express-auth
Authenticate your app
Add authentication function of this middleware to your express app as a middleware. This function handles creating/re-creating oauth and session.
Sample
const express = require("express");
const app = express();
...
...
...
app.use(
shopifyAuth({
// Default path prefix is '' i.e the paths become /auth and /auth/callback
// Incase your want to modify the base path due to some reason you can modify it by specifying a prefix value - such as /shopify
// When /shopify prefix is added the paths will become /shopify/auth and /shopify/auth/callback
prefix: '',
// set access mode. Allowed values are 'online' and 'offline'. Note: online tokens expire every 24 hours and you will need to re-validate
// if want the developed hassle free - keep the accessMode as 'offline'
accessMode: 'offline',
// Callback for when the auth procedure is complete.
afterAuth(req, res) {
const { shop, accessToken } = req.shopify;
console.log('The access token is: ', accessToken);
res.redirect('/');
},
}),
);
Access the session information on res.shopify
inside the afterAuth
callback. Store the access token for future use - such as: for creating webhooks, retrieving order, customer information etc.
shopifyAuth
paramsParam | Options | Description |
---|---|---|
prefix | empty string/some custom route prefix string | If you want to add a customp prefix in the auth routes. |
accessMode | offline/online | Corresponds to which access mode you want to use |
afterAuth() | - | A required callback function passed to shopifyAuth. After auth is successful, this callback function will be invoked and will contain the session information |
Note: Online tokens expire every 24 hours and you will need to re-validate.
Validate your API calls
Use this middleware to authenticate all API calls you make from your app's frontend to your app's express backend. This middleware will check if a valid and active session token has been generated by your express app and your frontend has sent a valid & active session token
along with the request or not.
Make sure you are using @shopify/app-bridge
v2.0.5 on the client side.
Sample
const express = require("express");
const router = express.Router();
const UserController = require("../controllers/user.controller");
const shopifyExpressAuth = require("shopify-express-auth");
router.post(
"/create",
shopifyExpressAuth.verifyRequest({ accessMode: "offline", returnHeader: false }),
UserController.create
);
If the session/session token
is not valid then the user will be redirected to the shopify oauth route (/auth
) in order to generate a valid session.
verifyRequest
paramsParam | Options | Description |
---|---|---|
accessMode | offline/online | Checks for offline or online session |
returnHeader | false/true | Returns re-auth headers on auth failure |
FAQs
Middleware to authenticate express app with Shopify
We found that shopify-express-auth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.