[![Build Status](https://travis-ci.org/Shopify/quilt.svg?branch=master)](https://travis-ci.org/Shopify/quilt) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE.md) [![npm version](https://badge.fury.io/js/%40shopify%2Fkoa-shopi
Last updated 2 years ago by dimensionsoftware .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @dimensionsoftware/koa-shopify-auth 
SYNC missed versions from official npm registry.


Build Status License: MIT npm version

This is a soft fork of @shopify/koa-shopify-auth that fixes one small Oauth bug.

Middleware to authenticate a Koa application with Shopify.

Sister module to @shopify/shopify-express, but simplified.

Features you might know from the express module like the webhook middleware and proxy will be presented as their own packages instead.


$ yarn add @dimensionsoftware/koa-shopify-auth


This package exposes shopifyAuth by default, and verifyRequest as a named export.

import shopifyAuth, {verifyRequest} from '@shopify/koa-shopify-auth';


Returns an authentication middleware taking up (by default) the routes /auth and /auth/callback.

    // if specified, mounts the routes off of the given path
    // eg. /shopify/auth, /shopify/auth/callback
    // defaults to ''
    prefix: '/shopify',
    // your shopify app api key
    apiKey: SHOPIFY_API_KEY,
    // your shopify app secret
    secret: SHOPIFY_SECRET,
    // scopes to request on the merchants store
    scopes: ['write_orders, write_products'],
    // set access mode, default is 'online'
    accessMode: 'offline',
    // callback for when auth is completed
    afterAuth(ctx) {
      const {shop, accessToken} = ctx.session;

      console.log('We did it!', accessToken);



This 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.


You should never have to manually go here. This route is purely for shopify to send data back during the oauth process.


Returns a middleware to verify requests before letting them further in the chain.

    // path to redirect to if verification fails
    // defaults to '/auth'
    authRoute: '/foo/auth',
    // path to redirect to if verification fails and there is no shop on the query
    // defaults to '/auth'
    fallbackRoute: '/install',

Example app

import 'isomorphic-fetch';

import Koa from 'koa';
import session from 'koa-session';
import shopifyAuth, {verifyRequest} from '@shopify/koa-shopify-auth';

const {SHOPIFY_API_KEY, SHOPIFY_SECRET} = process.env;

const app = new Koa();
app.keys = [SHOPIFY_SECRET];

  // sets up secure session data on each request

  // sets up shopify auth
      apiKey: SHOPIFY_API_KEY,
      secret: SHOPIFY_SECRET,
      scopes: ['write_orders, write_products'],
      afterAuth(ctx) {
        const {shop, accessToken} = ctx.session;

        console.log('We did it!', accessToken);


  // everything after this point will require authentication

  // application code
  .use(ctx => {
    ctx.body = '????';



This 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.


Though 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.

Testing locally

By 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).

Current Tags

  • 3.1.12                                ...           latest (2 years ago)

3 Versions

  • 3.1.12                                ...           2 years ago
  • 3.1.11                                ...           2 years ago
  • 3.1.10                                ...           2 years ago
Maintainers (1)
Today 0
This Week 1
This Month 1
Last Day 1
Last Week 1
Last Month 1
Dependencies (4)
Dev Dependencies (5)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |