Skip to content
Shopify oauth (oauth2) middleware for Golang
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Adding license. Mar 22, 2015
README.md Adding readme. Mar 22, 2015
config.go Removing session check from handler. Apr 18, 2015
errors.go Fixing documentation. Mar 22, 2015
failure_handler.go Fixing documentation. Mar 22, 2015
handler.go
handler_test.go Removing session check from handler. Apr 18, 2015
installation.go
persistence.go Removing session check from handler. Apr 18, 2015
script_tags.go Adding script tag insertion upon app installation. Apr 4, 2015
verification.go Initial commit. Feb 14, 2015
verification_test.go Initial commit. Feb 14, 2015
webhook.go Adding webhook creation to installation script. Mar 16, 2015

README.md

shoauth

shoauth is an HTTP package for Go that implements the Shopify oauth2 API.

Features

  • Performs Shopify app installation (displaying auth page and retrieving access tokens)
  • Optionally performs webhook installation upon app installation
  • Performs Shopify request verification (both user & webhook)
  • Acts as typical Go middleware - meaning it can be placed in any middleware stack as long as it is made up of http.Handler
  • Allows custom failure handlers.
  • Has no dependencies external to the Go standard library.

Example

package main

import (
	"fmt"
	"github.com/darrenpeters/shoauth"
	"net/http"
	"os"
)

type dummyPersistence struct {}

func (p *dummyPersistence) InstallationExists(shopID string) bool {
	return false // Use any ORM or SQL package directly
}

func (p *dummyPersistence) CreateInstallation(shopID string, accessToken string) error {
	return nil // Use any ORM or SQL package directly
}

func (p *dummyPersistence) HasValidSession(r *http.Request) bool {
	return false // Use gorilla sessions or whatever here
}

func oauthConfig(s *shoauth.ShopifyConfig) {
	s.ClientID = os.Getenv("SHOPIFY_CLIENT_ID")
	s.SharedSecret = os.Getenv("SHOPIFY_SHARED_SECRET")
	s.IsEmbedded = true
	s.Scopes = []string{"read_products", "write_products", "read_customers", "write_customers", "read_orders", "write_orders", "read_shipping", "write_shipping"}
	s.Webhooks = make(map[string]string)
	s.Webhooks["orders/fulfilled"] = "https://yourapp.com/orders/fulfilled"
	s.Webhooks["app/uninstalled"] = "https://yourapp.com/app/uninstalled"
}

func main() {
	shoauthHandler := shoauth.NewShopifyOauthHandler(http.DefaultServeMux, shoauth.DefaultFailureHandler(), &dummyPersistence{}, oauthConfig)
	fmt.Println("Listening on http://127.0.0.1:8000/")
	http.ListenAndServe(":8000", shoauthHandler)
}

Documentation

Documentation is available at GoDoc

You can’t perform that action at this time.