app

package
v0.0.0-...-113de0a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2019 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAPIHandler

func NewAPIHandler(handler http.Handler, oauthTokenStorage OAuthTokenStorage) http.Handler

NewAPIHandler instantiates a new API handler.

A typical usage is to wrap custom API rest endpoints with an APIHandler to ensure that the calls originates from a Shopify admin page that went through a OAuthHandler.

func NewAPIMiddleware

func NewAPIMiddleware(storage OAuthTokenStorage) func(http.Handler) http.Handler

NewAPIMiddleware instantiates a new API middleware.

func NewOAuthHandler

func NewOAuthHandler(handler http.Handler, storage OAuthTokenStorage, config *Config, errorHandler ErrorHandler) http.Handler

NewOAuthHandler instantiates a new Shopify embedded app handler, from the specified configuration.

A typical usage of the handler is to serve the `index.html` page of a Shopify embedded app.

Upon a successful request, the handler stores or refreshes authentication information on the client side, in the form of a cookie.

The handler also stores the Shopify API key in a cookie named `shopify-api-key`.

Javascript admin apps can use that cookie to actually configure their embedding in the Shopify admin portal.

func NewOAuthMiddleware

func NewOAuthMiddleware(storage OAuthTokenStorage, config *Config, errorHandler ErrorHandler) func(http.Handler) http.Handler

NewOAuthMiddleware instantiates a new Shopify embedded app middleware, from the specified configuration.

A typical usage of the handler is to serve the `index.html` page of a Shopify embedded app.

Upon a successful request, the handler stores or refreshes authentication information on the client side, in the form of a cookie.

func NewProxyHandler

func NewProxyHandler(handler http.Handler, storage OAuthTokenStorage, config *Config, errorHandler ErrorHandler) http.Handler

NewProxyHandler instantiates a new Shopify proxy handler, from the specified configuration.

A typical usage of the handler is to serve pages, scripts or APIs through a Shopify App proxy, usually from the storefront.

func NewProxyMiddleware

func NewProxyMiddleware(storage OAuthTokenStorage, config *Config, errorHandler ErrorHandler) func(http.Handler) http.Handler

NewProxyMiddleware instantiates a new proxy middleware.

func NewScriptTagsHandler

func NewScriptTagsHandler(handler http.Handler, scriptTags ...shopify.ScriptTag) http.Handler

NewScriptTagsHandler instantiates a handler that ensures that a list of script tags are registered.

It must be chained with an APIHandler or OAuthHandler as it requires the request context to contains the Shopify credentials (shop and access tokens).

func NewScriptTagsMiddleware

func NewScriptTagsMiddleware(scriptTags ...shopify.ScriptTag) func(http.Handler) http.Handler

NewScriptTagsMiddleware instantiates a middleware that ensures that a list of script tags are registered.

It must be chained with an APIHandler or OAuthHandler as it requires the request context to contains the Shopify credentials (shop and access tokens).

Types

type Application

type Application struct {
	// Config contains the application configuration.
	Config *Config

	// OAuthTokenStorage contains the OAuth token storage provider.
	OAuthTokenStorage OAuthTokenStorage

	// ErrorHandler, if specified, is a handler to call when fatal errors occurs.
	ErrorHandler ErrorHandler
}

Application represents a Shopify embedded application.

func (*Application) NewAPIHandler

func (a *Application) NewAPIHandler(handler http.Handler) http.Handler

NewAPIHandler instantiates a new API handler.

A typical usage is to wrap custom API rest endpoints with an APIHandler to ensure that the calls originates from a Shopify admin page that went through a OAuthHandler.

func (*Application) NewAPIMiddleware

func (a *Application) NewAPIMiddleware() func(http.Handler) http.Handler

NewAPIMiddleware instantiates a new API middleware.

A typical usage is to wrap custom API rest endpoints with an APIHandler to ensure that the calls originates from a Shopify admin page that went through a OAuthHandler.

func (*Application) NewOAuthHandler

func (a *Application) NewOAuthHandler(handler http.Handler) http.Handler

NewOAuthHandler instantiates a new Shopify embedded app handler.

A typical usage of the handler is to serve the `index.html` page of a Shopify embedded app.

Upon a successful request, the handler stores or refreshes authentication information on the client side, in the form of a cookie.

func (*Application) NewOAuthMiddleware

func (a *Application) NewOAuthMiddleware() func(http.Handler) http.Handler

NewOAuthMiddleware instantiates a new Shopify embedded app middleware.

A typical usage of the handler is to serve the `index.html` page of a Shopify embedded app.

Upon a successful request, the handler stores or refreshes authentication information on the client side, in the form of a cookie.

func (*Application) NewProxyHandler

func (a *Application) NewProxyHandler(handler http.Handler) http.Handler

NewProxyHandler instantiates a new Shopify proxy handler.

A typical usage of the handler is to serve pages, scripts or APIs through a Shopify App proxy, usually from the storefront.

func (*Application) NewProxyMiddleware

func (a *Application) NewProxyMiddleware() func(http.Handler) http.Handler

NewProxyMiddleware instantiates a new Shopify proxy handler.

A typical usage of the handler is to serve pages, scripts or APIs through a Shopify App proxy, usually from the storefront.

func (*Application) NewScriptTagsHandler

func (a *Application) NewScriptTagsHandler(handler http.Handler, scriptTags ...shopify.ScriptTag) http.Handler

NewScriptTagsHandler instantiates a new script tags handler.

A typical usage of the handler is to serve the `index.html` page of a Shopify embedded app.

Upon a successful request, the handler stores or refreshes authentication information on the client side, in the form of a cookie.

func (*Application) NewScriptTagsMiddleware

func (a *Application) NewScriptTagsMiddleware(scriptTags ...shopify.ScriptTag) func(http.Handler) http.Handler

NewScriptTagsMiddleware instantiates a new script tags middleware.

A typical usage of the handler is to serve the `index.html` page of a Shopify embedded app.

Upon a successful request, the handler stores or refreshes authentication information on the client side, in the form of a cookie.

type Config

type Config struct {
	// APIKey is the Shopify API key for the app, as indicated on the Shopify
	// App page.
	APIKey shopify.APIKey

	// APISecret is the Shopify API secret for the app, as indicated on the
	// Shopify App page.
	APISecret shopify.APISecret

	// PublicURL is the public URL at which the app will be instantiated.
	PublicURL *url.URL

	// The Scope of the app, as documented at
	// https://help.shopify.com/en/api/getting-started/authentication/oauth/scopes.
	Scope shopify.Scope
}

Config contains the configuration for a Handler.

func ReadConfigFromEnvironment

func ReadConfigFromEnvironment() (*Config, error)

ReadConfigFromEnvironment reads a configuration from environment variables.

type ErrorHandler

type ErrorHandler interface {
	ServeHTTPError(w http.ResponseWriter, req *http.Request, err error)
}

ErrorHandler represents an error handler.

type MemoryOAuthTokenStorage

type MemoryOAuthTokenStorage struct {
	// contains filtered or unexported fields
}

MemoryOAuthTokenStorage implements in-memory storage of OAuth tokens.

func (*MemoryOAuthTokenStorage) DeleteOAuthToken

func (s *MemoryOAuthTokenStorage) DeleteOAuthToken(ctx context.Context, shop shopify.Shop) error

DeleteOAuthToken deletes an OAuth token for a shop.

If the shop has no OAuth token, the call is a no-op.

The method never fails.

func (*MemoryOAuthTokenStorage) GetOAuthToken

func (s *MemoryOAuthTokenStorage) GetOAuthToken(ctx context.Context, shop shopify.Shop) (*shopify.OAuthToken, error)

GetOAuthToken gets an OAuth token for the specified shop.

The method never fails.

If no OAuth token exists for the shop, a nil OAuth token is returned.

func (*MemoryOAuthTokenStorage) UpdateOAuthToken

func (s *MemoryOAuthTokenStorage) UpdateOAuthToken(ctx context.Context, shop shopify.Shop, oauthToken shopify.OAuthToken) error

UpdateOAuthToken updates an OAuth token.

If the shop has no previous OAuth token, it is then created.

The method never fails.

type OAuthTokenStorage

type OAuthTokenStorage interface {
	// GetOAuthToken gets an OAuth token for the specified shop.
	//
	// If the request fails, an error is returned.
	//
	// If no OAuth token exists for the shop, a nil OAuth token is returned.
	GetOAuthToken(ctx context.Context, shop shopify.Shop) (*shopify.OAuthToken, error)

	// UpdateOAuthToken updates an OAuth token.
	//
	// If the shop has no previous OAuth token, it is then created.
	UpdateOAuthToken(ctx context.Context, shop shopify.Shop, oauthToken shopify.OAuthToken) error

	// DeleteOAuthToken deletes an OAuth token for a shop.
	//
	// If the shop has no OAuth token, the call is a no-op.
	DeleteOAuthToken(ctx context.Context, shop shopify.Shop) error
}

OAuthTokenStorage represents an OAuth token storage.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL