說真的 實在有點複雜 我都眼花撩亂了
我完全不覺得 junior developer 有辦法搞清楚
實驗串接一下看看
這次嘗試非 embed app
app url: https://demo-connect.turn.tw/
allowed redirect url: https://demo-connect.turn.tw/redirect
取得 client id 與 secret -> 這兩個會用到
我有順便設定 distribution 為 custom 並指定給我 store domain -> 這步驟可能是必要
https://admin.shopify.com/?
organization_id=162618756&
no_redirect=true&
redirect=/oauth/redirect_from_developer_dashboard?
client_id%3D6b7001530576df226f1e8d6773eea438
出現我的商店選擇頁面

會跳轉到
https://demo-connect.turn.tw/?
hmac=cb294704a853ae327be712bb86c236098e3fb168732dd6a58a8988256d14a94c&
host=YWRtaW4uc2hvcGlmeS5jb20vc3RvcmUvYWthd2FzZWxlY3Q&
shop=akawaselect.myshopify.com&
timestamp=1765090150
會拿到 hmc, host, shop, timestamp
但我 server 只需要 shop 與 client id
https://admin.shopify.com/store/akawaselect/oauth/authorize?
client_id=6b7001530576df226f1e8d6773eea438&
scope=read_products&
redirect_uri=https%3A%2F%2Fdemo-connect.turn.tw%2Fredirect
https://admin.shopify.com/store/akawaselect/app/grant?
access_change_uuid=89f3b459-88cf-479f-a91f-d6f7abc95f3d&
client_id=6b7001530576df226f1e8d6773eea438

然後又會被我跳轉回到首頁
https://demo-connect.turn.tw/?shop=akawaselect.myshopify.com

會發現旁邊有開新視窗的 icon

點擊之後 會進到我的首頁
https://demo-connect.turn.tw/?
hmac=405d7c89fe4ad7365b28d472b707321a98d18597a56b9c11fc882ca8db64ef6b&
host=YWRtaW4uc2hvcGlmeS5jb20vc3RvcmUvYWthd2FzZWxlY3Q&
session=b1d035e5ae88e096d0f9bb3f908c368964134cbf7340e475ed2e5d087c600ac8&
shop=akawaselect.myshopify.com&
timestamp=1765091558

會多了 hmac, host, session, timestamp
因為是 non-embedded,沒有 app bridge -> 不需要驗證 host,也不需要 session token。
hmac = HMAC_SHA256(商家 request 的其他參數,使用 API Secret)
host=YWRtaW4uc2hvcGlmeS5jb20vc3RvcmUvYWthd2FzZWxlY3Q
這是一段 base64 encoded 字串。
解碼後是:
admin.shopify.com/store/akawaselect
Embedded App 打開後,需要用 host 來回到 Shopify Admin。
session — 用來與 Shopify Admin 的 Session Token Flow 互動
搭配 App Bridge 的 "Authenticated Fetch",用 session token 替代神聖不可外露的 access_token。
| Parameter | Embedded App | Non-Embedded App |
|---|---|---|
| hmac | ✔ 必須驗證 | ❌ 完全可忽略 |
| host | ✔ 必須使用(App Bridge) | ❌ 可忽略 |
| session | ✔ 必須使用(session token flow) | ❌ 可忽略 |
說起來 none embed app 整合方式
會像這樣
https://www.youtube.com/watch?v=dPjeydiD6ro
要求客戶先登入你的系統
然後去 shopify 安裝 app
安裝完 redirect 回自家網站時 因為已有 session 所以直接紀錄綁定即可
啊如果 商家北七 還沒登入系統 就先安裝 shopify app 勒
你的 redirect URI 沒有 session → 你不知道他是誰
→ 這時你不能綁定
→ 因為你不知道是哪一個帳號
→ 最佳解(Best Practice)叫做 Deferred Binding(延後綁定)
反正 我就是提供完整上架審核協助 也就是協助填完一個超大的表單

成果會像這樣
https://apps.shopify.com/jenjan-fulfillment?locale=zh-TW
提供我文案與媒體素材就可以
各個廠商 有的 django 有的 rails 有的 nodejs
以後找我合作
我就通通用 linode + laravel 無資料庫 無 session
拿到 store domain + access token 後面沒我的事
我在面對未來所有廠商
我就說 找我合作 只要知道5件事
1) 接收 store domain + access token 的 http post 網址
我會這樣丟過去
{
"shop": "xxx.myshopify.com",
"access_token": "shpat_xxxx"
}
2) 要求對方 限定 allow my linode ip -> 以免被別人亂丟
3) 告訴我 token bind 完要 redirect 到哪 -> target url 是否已登入不關我的事
http 302 redirect → https://vendor.com/shopify/success?shop=xxx.myshopify.com
4) 因為權限超大 我會提供 linode 完整 ssh 權限 可以上去看程式碼 完全無 session 與 database
5) 注意分成商家先登入/未登入兩種情境 要給我一組測試帳號密碼 我開發過程要用 上架時審核員也會需要
找 AI 寫的最簡單串接
不確定流程是否為 best practice