0.0.35 • Published 3 years ago

ah-shopify-auth-plugin v0.0.35

Weekly downloads
4
License
ISC
Repository
github
Last release
3 years ago

Plugin to add Shopify authentication to Actionhero

Still early stages, would love any input!

Configuration

To configure your Actionhero server to authenicate with shopify oAuth:

  1. Add this plugin to your actionhero project npm install ah-shopify-auth-plugin. Also, if you want to store your creditnails in a file rather than your server's ENVIRONMENT, you can npm install dotenv.
  2. Include this plugin in your config/plugins.ts.
import { join } from "path";

export const DEFAULT = {
  plugins: () => {
    return {
      "ah-shopify-auth-plugin": {
        path: join(__dirname, "..", "node_modules", "ah-shopify-auth-plugin")
      }
    };
  }
};
  1. Set the required enviornment variables, either in your ENV or .env. This plugin requites SHOPIFY_API_KEY and SHOPIFY_API_SECRET.
SHOPIFY_API_KEY=[YOUR_SHOPIFY_API_KEY]
SHOPIFY_API_SECRET=[YOUR_SHOPIFY_API_SECRET]
  1. Add a shopifyAuth.ts to your config directory with the following:
const path = require("path");

export const DEFAULT = {
  shopifyAuth: config => {

    return {
        apiKey: process.env.SHOPIFY_API_KEY,
        apiSecret: process.env.SHOPIFY_API_SECRET,
        scopes: 'read_products',
        ignoredDirectories: ["static"] //array of ignored directories (top level only)
    };
  }
};
  1. In most cases change your default route in config/servers/web.ts to be "api" rather than "file" (this plugin only authenticates api calls)

SameSite cookies

Shopify and chrome now require cookies to be SameSite=none. To do this you need to add these attributes to your sessionID cookie in config/servers/web.ts:

...
// Settings for determining the id of an http(s) request (browser-fingerprint)
fingerprintOptions: {
  cookieKey: "sessionID",
  toSetCookie: true,
  onlyStaticElements: false,
  settings: {
    path: "/",
    expires: 3600000,
    sameSite: "None",
    secure: true
  }
},
...

Processing Auth Token

Auth Token and scopes are saved on the session object. Like this:

{
  shopifySession: {
    access_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    scope: 'read_products',
    shop: 'some-store.myshopify.com'
  }
}

If you need to do something with the Shopify authToken once a user authenticates you can overwrite the function:

api.shopifyAuth.afterAuth = async (data, shopifySession) => {
    // Overwrite this function process the shopify access token after its been recieved
    log("Shopify Authorization Complete!");
    return;
}

the data object is the same data object passed to Actionhero actions, and the shopifySession is structured as above.

0.0.35

3 years ago

0.0.31

4 years ago

0.0.32

4 years ago

0.0.33

4 years ago

0.0.34

4 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.24

4 years ago

0.0.25

4 years ago

0.0.26

4 years ago

0.0.27

4 years ago

0.0.28

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.20

4 years ago

0.0.21

4 years ago

0.0.17

4 years ago

0.0.18

4 years ago

0.0.19

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago