Home

Awesome

shoauth

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

Features

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