Code Monkey home page Code Monkey logo

elixir-shopify-admin-proxy's Introduction

ShopifyAdminProxy

A simple proxy for forwarding requests to the Shopify Admin API.

The proxy uses the ShopifyAPI authentication plug to validate the Shop's JWT, it then uses the Admin API token for the Shopify App to query the Shopify GraphQL Admin API. This is useful if you are building out your Admin React app and want to query for things held in Shopify but don't want to have to create an entire translation layer/API.

Installation

def deps do
  [
    {:shopify_admin_proxy, github: "hez/elixir-shopify-admin-proxy", branch: "v0.3.3"}
  ]
end

The proxy requires all your GraphQL queries are stored in their own directory, this is then used to allow only requests you have explicitly added to the app. This is done by setting the config for :shopify_admin_proxy.

Add the following to your config/config.exs substituting in your own directory.

# Allowed queries for shopify admin proxy
config :shopify_admin_proxy,
  base_gpl_directory: Path.expand("../admin_ui/src/graphql/shopify", __DIR__)

The proxy defaults to caching all graphql query files in the module, to disable this for development add the following to config/dev.exs

# Disable query compile time caching for dev
config :shopify_admin_proxy, use_cached_queries: false
# If you would like to use User Tokens then set this to true
config :shopify_admin_proxy, use_online_tokens: false

Since the proxy forwards the entire body of the request you will have to mount the proxy in your endpoint before the Plug.Parsers gets called. You can ignore upstream: ... here, it is required by the proxy library used but gets replaced at time of calling.

Example:

  plug ShopifyAdminProxy,
    upstream: "https://example.myshopify.com/admin/api/2022-04/graphql.json",
    mount_path: "/api/admin/shopify_graphql_proxy"

  plug Plug.Parsers,
    parsers: [:urlencoded, :multipart, :json],
    ....

elixir-shopify-admin-proxy's People

Contributors

dependabot[bot] avatar hez avatar

Watchers

 avatar

elixir-shopify-admin-proxy's Issues

401 or 403 should return header "X-Shopify-API-Request-Failure-Reauthorize-Url"

Shopify App Bridge authenticated fetch supports auto redirecting to an install/reauth url when a token expires or is missing scopes by setting the response header string to something like X-Shopify-API-Request-Failure-Reauthorize-Url.

The documentation is hard to find but here is the spec:

export interface AuthenticatedFetchOptions {
    /**
     * The fetch function to perform the network call.
     */
    fetchOperation?: FetchOperation;
    /**
     * The URL to redirect to when the session token is invalid.
     * If not provided, `requestFailureReauthorizeUrlHeader` will be used.
     */
    reauthorizeUrl?: string;
    /**
     * The Header parameter.
     */
    requestFailureReauthorizeUrlHeader: string;
}

We could add |> put_resp_header("X-Shopify-API-Request-Failure-Reauthorize-Url", install_url) to

|> resp(403, "Forbidden.")
or even specify the difference between unauthorized and forbidden.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.