我開始開發Shopify集成。我嘗試集成的應用程序 每個用戶帳戶都有不同的子域,因此 需要針對每個oauth 連接請求重定向到不同的回叫域。到目前爲止,我正在重定向到Shopify授權 URL以允許用戶授予他們的帳戶訪問權限。不過,我得到 的錯誤響應:如何讓Shopify重定向到應用程序URL的子域?
{"error":"invalid_request",
"error_description":"The redirect_uri and application url must have matching hosts"}
的URL的形式爲:
https://SHOP_NAME.myshopify.com/admin/oauth/authorize?client_id=MY_CLIENT_ID&scope=read_order&redirect_uri=SUBDOMAIN.MYAPP.com
我已經嘗試設置應用程序URL(集管理頁面中 Shopify)所有這些和收到同樣的錯誤:
http://MYAPP.com
http://.MYAPP.com
http://*.MYAPP.com
不過,我可以得到它一起工作:
http://SUBDOMAIN.MYAPP.com
我可以創造一個終點,只是需要的信息從查詢 字符串,並重定向到子域名,例如:
callback.MYAPP.com?subdomain=SUBDOMAIN
這將解決這個問題,但我寧願將Shopify API 支持子域名,因爲我也想創建Shopely頁面中的鏈接到我的應用程序中,而不是必須保持構建 這些間接級別。 (雖然,尋找在管理頁面 的應用程序鏈接,它看起來像我會做同樣的還有 了。)
我使用的是非標準的TLD(因爲這是目前在 發展) 。所以,我把MYAPP.com放在這裏真的是oh.dev,然而 我已經嘗試使用.com編輯我的hosts文件,使用相同的 結果。
有誰知道如何讓Shopify接受一個子域爲 callback_url?我錯過了明顯的東西嗎?
下面是一些Clojure的代碼:
(require '[com.twinql.clojure.http :as http] '[clojure.contrib.logging :as log])
(defn consumer []
{:key "1234567890"
:secret "1234567890abcde"})
(defn shopify-config [shop-name]
{:request-token-url (str "https://" shop-name ".myshopify.com/admin/oauth/authorize")
:authorise-url (str "https://" shop-name ".myshopify.com/admin/oauth/authorize")
:access-token-url (str "https://" shop-name ".myshopify.com/admin/oauth/access_token")
:api-endpoint-url (str "https://" shop-name ".myshopify.com")})
(defn get-redirect-url [shop-name callback-url]
(let [{consumer-token :key consumer-token-secret :secret} (consumer)]
(str (-> shop-name shopify-config :request-token-url)
"?client_id=" consumer-token
"&scope=read_orders,read_products,read_customers"
"&redirect_uri=" callback-url)))
(defn get-access-credentials [verifier shop-name]
(let [{:keys [key secret]} (consumer)
response (http/post (-> shop-name shopify-config :access-token-url)
:as :json
:query {"client_id" key
"client_secret" secret
"code" verifier})]
(log/debug (str "response from getting access credentials from shopify : " response))
{:access-token (-> response :content :access_token)
:consumer-key key
:consumer-secret secret}))
(def methods {:get http/get
:post http/post
:delete http/delete
:put http/put})
(defn- make-request [method shop-name url token params]
(let [response (method (str (-> shop-name shopify-config :api-endpoint-url) url)
:as :json
:query params
:headers {"X-Shopify-Access-Token" token})]
(if (-> response :code (= 200))
(:content response)
(do
(log/error (str "Error in shopify request : " response))
(throw (Err. {:handle :shopify-request-error
:response response}))))))
(defn get-products [shop-name token page]
(make-request (:get methods) shop-name "/admin/products.json" token {:page page :limit 200}))
此外,還有一些代碼,獲取類似的店鋪名稱的東西從 用戶,並將其存儲在數據庫等。所以我們基本上調用 get-redirect-url重定向用戶購物,並讓他們獲得 批准權限。我們傳遞給Shopify的回調URL是 一樣的東西:
http://customer1.oh.dev/integrations/shopify/1/callback
然後需要提供和調用get存取憑證的代碼。 周圍的代碼存儲我們返回的訪問令牌等。然後 還有一個其他的用戶操作,將調用獲取產品, 檢索令牌&店名。
我可以發佈一些代碼,但它只是進行HTTP調用,它的工作和不工作的區別只是應用程序url設置中的子域設置。同樣因爲它在開發中,它使用非標準的TLD。我想知道這是否是問題的一部分。 – l0st3d
發佈了一些代碼。詢問是否沒有意義,或缺少太多。 – l0st3d
在合作伙伴區域,您已將應用程序URL註冊爲oh.dev? –