新增 APP

APP 安裝流程

Untitled

  1. 驗證登入店家,此步驟會將下方資訊使用跳轉 (redirect) 方式導到 App 的 Authorization URL。

    hmac = OpenSSL::HMAC.hexdigest(
    	OpenSSL::Digest.new('sha256'),
    	your_oauth_application.secret,
    	Base64.strict_encode64(domain)
    )
    url = "app-authorization-url?shop=#{cyberbiz_domain}&hmac=#{hmac}"
    
    # EX: <https://partner-domain.com/?shop=demo.cyberbiz.co&hmac=47532a9c63a83037603d6b16d4a44e551c28e6e560804e179c6e2b62cf38f248>
    # GET <https://partner-domain.com/?shop=demo.cyberbiz.co&hmac=47532a9c63a83037603d6b16d4a44e551c28e6e560804e179c6e2b62cf38f248>
    
  2. APP 從開發商驗證頁面跳轉回 CYBERBIZ https://{cyberbiz_domain}/admin/oauth/authorize (GET request)

    <aside> 🚨 務必實做 state 參數,避免遭受 CSRF 攻擊,造成資料外洩

    </aside>

    client_id your oauth app client_id
    redirect_uri your oauth app redirect_url
    response_type code
    scope (optional)
    your oauth app scopes split by whitespace. e.g: scope=public read_customers read_products ****
    state random string to prevent CSRF
  3. CYBERBIZ APP 授權安裝

    進到這畫面後,勾選並按下確認

    Untitled

  4. 安裝完成跳轉至 App 的 Redirect URL (redirect_url)跳到 Redirect URL 時會帶的參數有

    code oauth grant code (Valid within 10 minutes
    shop shop.domain
    hmac 同第 1 點,可拿兩者做比對驗證(不用特別解開)
    state state

到這步安裝流程就完成了,App 可以用取得的 code 跟 CYBEBIZ 要 token

通常這一步之後就是跳到 App 自己的設定畫面,或符合條件的話也可以進行 設定頁面自動帶入設定

取得 token

grant_type authorization_code
code your grant code from app installation step 4
redirect_uri your oauth app redirect_url
client_id your oauth app client id
client_secret your oauth app client secret