ตรวจสอบสิทธิ์คำขอเซสชันสตรีม

คำขอสตรีมจะลงทะเบียนเซสชันใหม่สำหรับเหตุการณ์ไลฟ์สด ดูข้อมูลเพิ่มเติมได้ที่สร้างคำขอสตรีม

หน้านี้ครอบคลุมการใช้โทเค็น HMAC เพื่อตรวจสอบสิทธิ์คำขอสตรีม

ก่อนเริ่มต้น

สร้างโทเค็น HMAC

หากต้องการสร้างโทเค็น ให้ทำดังนี้

  1. รวบรวมพารามิเตอร์เส้นทางและพารามิเตอร์การค้นหาที่จำเป็นสำหรับคำขอเซสชันสตรีม ดูรายการทั้งหมดได้ที่ เมธอด: สตรีม
  2. รวมสตริงคีย์และค่าพารามิเตอร์ คุณต้องจัดเรียงพารามิเตอร์ตามตัวอักษรและคั่นพารามิเตอร์ด้วยอักขระ ~ เช่น

    custom_asset_key=CUSTOM_ASSET_KEY~exp=EXPIRATION~network_code=NETWORK_CODE
    

    แทนที่ค่าต่อไปนี้

    • CUSTOM_ASSET_KEY: จำเป็น คีย์เนื้อหาที่กำหนดเองของเหตุการณ์ไลฟ์สด
    • EXPIRATION: จำเป็น การประทับเวลาหมดอายุของโทเค็นในเวลา Unix Epoch
    • NETWORK_CODE: จำเป็น รหัสเครือข่ายของบัญชี Google Ad Manager
  3. คำนวณแฮช SHA-256 ของสตริงโทเค็นโดยใช้คีย์การตรวจสอบสิทธิ์ DAI

  4. จัดรูปแบบเอาต์พุตแฮชเป็นเลขฐานสิบหก

  5. หากต้องการลงชื่อในสตริงโทเค็น ให้ต่อท้ายลายเซ็นที่ท้ายพารามิเตอร์ที่รวบรวมไว้ก่อนหน้านี้

    custom_asset_key=...~hmac=HMAC_SIGNATURE
    

    แทนที่ HMAC_SIGNATURE ด้วยลายเซ็นที่คุณสร้างขึ้นโดยการแฮชสตริงโทเค็นโดยใช้คีย์การตรวจสอบสิทธิ์ DAI

  6. หากต้องการส่งสตริงโทเค็นที่ลงชื่อแล้วอย่างปลอดภัย ให้ใช้การเข้ารหัส URL กับสตริงโทเค็นที่ลงชื่อแล้ว

ตัวอย่างต่อไปนี้จะลงชื่อและเข้ารหัสสตริงโทเค็นที่จะหมดอายุภายใน 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 ให้ทำอย่างใดอย่างหนึ่งต่อไปนี้

HLS

ส่วนหัวของคำขอ 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>