驗證串流工作階段要求

串流要求會為直播活動註冊新工作階段。 詳情請參閱「提出串流要求」。

本頁說明如何使用 HMAC 權杖驗證串流要求。

事前準備

產生 HMAC 權杖

如要產生權杖,請按照下列步驟操作:

  1. 收集串流工作階段要求所需的路徑和查詢參數。如需完整清單,請參閱「方法:串流」。
  2. 合併參數鍵和值字串。參數必須依字母順序排序,並以波浪號 ~ 字元分隔,例如:

    custom_asset_key=CUSTOM_ASSET_KEY~exp=EXPIRATION~network_code=NETWORK_CODE
    

    更改下列內容:

    • CUSTOM_ASSET_KEY必要。直播活動的自訂資產金鑰。
    • EXPIRATION必要。權杖的到期時間戳記,以 Unix 紀元時間表示。
    • NETWORK_CODE必要。Google Ad Manager 帳戶的聯播網代碼。
  3. 使用 DAI 驗證金鑰計算權杖字串的 SHA-256 雜湊。

  4. 以十六進位格式輸出雜湊。

  5. 如要簽署權杖字串,請在先前收集的參數結尾附加簽章:

    custom_asset_key=...~hmac=HMAC_SIGNATURE
    

    使用 DAI 驗證金鑰雜湊處理權杖字串,然後以產生的簽章取代 HMAC_SIGNATURE

  6. 如要安全地傳遞已簽署的權杖字串,請對已簽署的權杖字串套用網址編碼。

以下範例會簽署及編碼在 60 秒內過期的權杖字串:

# Add 60 seconds to the current time
future_epoch=$((EPOCHSECONDS + 60))
echo "Current: $EPOCHSECONDS"
echo "Future: $future_epoch"
# Current: 1774478306
# Future: 1774478366

# Sample DAI stream authentication key
key="DE0E9..."

# Sort parameters in the token string
token="custom_asset_key=hls-pod-serving-redirect-auth-stream-pod~exp=1774478366~network_code=21775744923"

# Generate the token's signature.
echo -n $token | openssl dgst -sha256 -mac HMAC -macopt key:$key
# SHA2-256(stdin)= 17cdf7079b735320dbc66e4c9d677ae0380fb0ef3cf9ce90fdd55d0667574365

# Sign the token: custom_asset_key=hls-pod-serving-redirect-auth-stream-pod~exp=1774478366~network_code=21775744923~hmac=17cdf7079b735320dbc66e4c9d677ae0380fb0ef3cf9ce90fdd55d0667574365

# Encode the token: custom_asset_key%3Dhls-pod-serving-redirect-auth-stream-podexp%3D1774478366network_code%3D21775744923~hmac%3D17cdf7079b735320dbc66e4c9d677ae0380fb0ef3cf9ce90fdd55d0667574365

使用 HMAC 權杖要求直播工作階段

如要使用 HMAC 權杖驗證串流建立要求,請執行下列其中一項操作:

HTTP 即時串流

Authorization 要求標頭

curl "https://dai.google.com/ssai/pods/api/v1/network/21775744923/custom_asset/hls-pod-serving-redirect-auth-stream-pod/stream" \
-X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: DCLKDAI token=custom_asset_key%3Dhls-pod-serving-redirect-auth-stream-podexp%3D1774478366network_code%3D21775744923~hmac%3D17cdf7079b735320dbc66e4c9d677ae0380fb0ef3cf9ce90fdd55d0667574365"

查詢字串參數

curl "https://dai.google.com/ssai/pods/api/v1/network/21775744923/custom_asset/hls-pod-serving-redirect-auth-stream-pod/stream?auth-token=custom_asset_key%3Dhls-pod-serving-redirect-auth-stream-podexp%3D1774478366network_code%3D21775744923~hmac%3D17cdf7079b735320dbc66e4c9d677ae0380fb0ef3cf9ce90fdd55d0667574365" \
-X POST \
-H "Content-Type: application/x-www-form-urlencoded"

表單資料欄位

curl "https://dai.google.com/ssai/pods/api/v1/network/21775744923/custom_asset/hls-pod-serving-redirect-auth-stream-pod/stream" \
-X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "auth-token=custom_asset_key%3Dhls-pod-serving-redirect-auth-stream-podexp%3D1774478366network_code%3D21775744923~hmac%3D17cdf7079b735320dbc66e4c9d677ae0380fb0ef3cf9ce90fdd55d0667574365"

如果成功,您會看到下列 JSON 回應:

{
"stream_id":"6299a01b-450d-4879-a5c8-fe3cf2188aee:CBF2",
"media_verification_url":"https://dai.google.com/view/p/service/linear/stream/6299a01b-450d-4879-a5c8-fe3cf2188aee:CBF2/loc/CBF2/network/21775744923/event/C5BT3czhT2Sc7OIbM8ibqA/media/","metadata_url":"https://dai.google.com/linear/pods/hls/pa/event/C5BT3czhT2Sc7OIbM8ibqA/stream/6299a01b-450d-4879-a5c8-fe3cf2188aee:CBF2/metadata",
"session_update_url":"https://dai.google.com/linear/v1/pa/event/C5BT3czhT2Sc7OIbM8ibqA/stream/6299a01b-450d-4879-a5c8-fe3cf2188aee:CBF2/session",
"polling_frequency":10
}

如要瞭解回應結構和狀態碼,請參閱「方法:串流」。

如果驗證失敗,系統會顯示下列錯誤訊息:

<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 401 (Unauthorized)!!1</title>
...
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>401.</b> <ins>That’s an error.</ins>
<p><ins>That’s all we know.</ins>s

DASH

Authorization 要求標頭

curl "https://dai.google.com/ssai/pods/api/v1/network/21775744923/custom_asset/dash-pod-serving-redirect-auth-stream-pod/stream"\
-X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: DCLKDAI token=custom_asset_key%3Ddash-pod-serving-redirect-auth-stream-podexp%3D1772817105network_code%3D21775744923~hmac%3Dc7e10f51f544610cdda28fdee903472839bf1154701ae371c0196d8f63c8bdda"

查詢字串參數

curl "https://dai.google.com/ssai/pods/api/v1/network/21775744923/custom_asset/dash-pod-serving-redirect-auth-stream-pod/stream?auth-token=custom_asset_key%3Ddash-pod-serving-redirect-auth-stream-podexp%3D1772817105network_code%3D21775744923~hmac%3Dc7e10f51f544610cdda28fdee903472839bf1154701ae371c0196d8f63c8bdda" \
-X POST \
-H "Content-Type: application/x-www-form-urlencoded"

表單資料欄位

curl "https://dai.google.com/ssai/pods/api/v1/network/21775744923/custom_asset/dash-pod-serving-redirect-auth-stream-pod/stream" \
-X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "auth-token=custom_asset_key%3Ddash-pod-serving-redirect-auth-stream-podexp%3D1772817105network_code%3D21775744923~hmac%3Dc7e10f51f544610cdda28fdee903472839bf1154701ae371c0196d8f63c8bdda"

如果成功,您會看到下列 JSON 回應:

{
"stream_id": "e66568dc-cb5c-4859-b645-e12d9b5b821b:ATL",
"media_verification_url": "https://dai.google.com/view/p/service/linear/stream/e66568dc-cb5c-4859-b645-e12d9b5b821b:ATL/loc/ATL/network/21775744923/event/YMTFNxBxTR66kFv-krZHcQ/media/",
"metadata_url": "https://dai.google.com/linear/pods/dash/pa/event/YMTFNxBxTR66kFv-krZHcQ/stream/e66568dc-cb5c-4859-b645-e12d9b5b821b:ATL/metadata",
"session_update_url": "https://dai.google.com/linear/v1/pa/event/YMTFNxBxTR66kFv-krZHcQ/stream/e66568dc-cb5c-4859-b645-e12d9b5b821b:ATL/session",
"polling_frequency": 10,
"pod_manifest_url": "https://dai.google.com/linear/pods/v1/dash/event/YMTFNxBxTR66kFv-krZHcQ/stream/e66568dc-cb5c-4859-b645-e12d9b5b821b:ATL/pod/$pod-id$/manifest.mpd",
"manifest_format": "dash"
}

如要瞭解回應結構和狀態碼,請參閱「方法:串流」。

如果驗證失敗,系統會顯示下列錯誤訊息:

<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 401 (Unauthorized)!!1</title>
...
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>401.</b> <ins>That’s an error.</ins>
<p><ins>That’s all we know.</ins>