Đối với tính năng kết hợp quảng cáo phía máy chủ, trình thao tác tệp kê khai của bạn sẽ đưa ra yêu cầu phân đoạn nhóm quảng cáo cho DAI của Google. Để biết thêm thông tin, hãy xem bài viết Tạo URL phân đoạn quảng cáo.
Trang này trình bày cách xác thực các yêu cầu phân đoạn nhóm quảng cáo bằng mã thông báo HMAC.
Trước khi bắt đầu
Trước khi tiếp tục, hãy làm như sau:
- Hoàn thành các điều kiện tiên quyết.
- Đảm bảo bạn đã bật Khoá xác thực tài nguyên Pod trong sự kiện phát trực tiếp trong tài khoản Google Ad Manager.
Tạo mã thông báo HMAC
Để tạo mã thông báo, hãy làm như sau:
- Thu thập các tham số đường dẫn và tham số truy vấn (ngoại trừ mã thông báo uỷ quyền) được điền sẵn cho yêu cầu phân đoạn nhóm của bạn. Để xem danh sách đầy đủ, hãy xem Phương thức: phân đoạn nhóm.
Sắp xếp các tham số của bạn thành một chuỗi duy nhất. Bạn phải sắp xếp các tham số theo thứ tự bảng chữ cái và phân tách chúng bằng dấu ngã
~, ví dụ:custom_asset_key=CUSTOM_ASSET_KEY~exp=EXPIRATION~network_code=NETWORK_CODE~pd=POD_DURATION~pod_id=POD_IDENTIFIERTính toán hàm băm SHA-256 của chuỗi mã thông báo bằng khoá xác thực DAI.
Định dạng đầu ra hàm băm ở dạng thập lục phân.
Để ký chuỗi mã thông báo, hãy thêm chữ ký vào cuối các tham số đã thu thập trước đó:
custom_asset_key=...~hmac=HMAC_SIGNATUREThay thế
HMAC_SIGNATUREbằng chữ ký mà bạn đã tạo bằng cách băm chuỗi mã thông báo bằng khoá xác thực DAI.Để truyền chuỗi mã thông báo đã ký một cách an toàn, hãy áp dụng phương thức mã hoá URL cho chuỗi mã thông báo đã ký.
Ví dụ sau đây tạo ra giá trị được mã hoá URL của một chuỗi mã thông báo đã ký:
HLS (Phát trực tuyến dựa trên HTTP)
# Add 60 seconds to the current time
future_epoch=$((EPOCHSECONDS + 60))
echo "Current: $EPOCHSECONDS"
echo "Future: $future_epoch"
# Current: 1774465950
# Future: 1774466010
# Sample DAI pod resource authentication key
key="EB08..."
# Sort parameters in the token string
token="ad_break_id=ab1~custom_asset_key=hls-pod-serving-redirect-auth-stream-pod~exp=1774466010~network_code=21775744923~pd=30000"
# Generate the token's signature.
echo -n $token | openssl dgst -sha256 -mac HMAC -macopt key:$key
# SHA2-256(stdin)= ff38abab31b436351e20ecd57bcc5b97acd9461abb71c4cf9c9731add965ecf2
# Sign the token: ad_break_id=ab1~custom_asset_key=hls-pod-serving-redirect-auth-stream-pod~exp=1774466010~network_code=21775744923~pd=30000~hmac=ff38abab31b436351e20ecd57bcc5b97acd9461abb71c4cf9c9731add965ecf2
# Encode the token: ad_break_id%3Dab1~custom_asset_key%3Dhls-pod-serving-redirect-auth-stream-pod~exp%3D1774466010~network_code%3D21775744923~pd%3D30000~hmac%3Dff38abab31b436351e20ecd57bcc5b97acd9461abb71c4cf9c9731add965ecf2
DASH (Truyền phát thích ứng động qua HTTP)
# Add 60 seconds to the current time
future_epoch=$((EPOCHSECONDS + 60))
echo "Current: $EPOCHSECONDS"
echo "Future: $future_epoch"
# Current: 1769540517
# Future: 1769540577
# Sample DAI pod resource authentication key
key="EB08..."
# Sort parameters in the token string
token="ad_break_id=ab1~custom_asset_key=dash-pod-serving-redirect-auth-stream-pod~exp=1774466641~network_code=21775744923~pd=30000"
# Generate the token's signature.
echo -n $token | openssl dgst -sha256 -mac HMAC -macopt key:$key
# SHA2-256(stdin)= 7249f9193778f2318314519ff2cea5c47958bc7fdd2eaf24008352867af0a050
# Sign the token: ad_break_id=ab1~custom_asset_key=dash-pod-serving-redirect-auth-stream-pod~exp=1774466641~network_code=21775744923~pd=30000~hmac=7249f9193778f2318314519ff2cea5c47958bc7fdd2eaf24008352867af0a050
# Encode the token: ad_break_id%3Dab1~custom_asset_key%3Ddash-pod-serving-redirect-auth-stream-pod~exp%3D1774466641~network_code%3D21775744923~pd%3D30000~hmac%3D7249f9193778f2318314519ff2cea5c47958bc7fdd2eaf24008352867af0a050
Xác thực yêu cầu phân đoạn nhóm quảng cáo HLS
Để xác thực các yêu cầu về tài nguyên nhóm của bạn, hãy sử dụng tham số chuỗi truy vấn auth-token để truyền mã thông báo HMAC đã ký được mã hoá URL.
HLS (Phát trực tuyến dựa trên HTTP)
Ví dụ sau đây sử dụng mã thông báo HMAC để xác thực yêu cầu phân đoạn nhóm HLS:
curl --include "https://dai.google.com/linear/pods/v1/seg/network/21775744923/custom_asset/hls-pod-serving-redirect-auth-stream-pod/ad_break_id/ab1/profile/media-ts-4628000bps/0.ts?stream_id=51b85d28-7ed5-48da-bfd8-e013b7d7b204:DLS&&sd=10000&pd=30000&auth-token=ad_break_id%3Dab1~custom_asset_key%3Dhls-pod-serving-redirect-auth-stream-pod~exp%3D1774466010~network_code%3D21775744923~pd%3D30000~hmac%3Dff38abab31b436351e20ecd57bcc5b97acd9461abb71c4cf9c9731add965ecf2"
Nếu thành công, bạn sẽ thấy phản hồi sau:
...
< HTTP/2 302
< access-control-allow-headers: Authorization
< access-control-allow-origin: *
< access-control-expose-headers: Location
< cache-control: no-cache, no-store, max-age=0, must-revalidate
< date: Wed, 25 Mar 2026 18:13:40 GMT
< expires: Mon, 01 Jan 1990 00:00:00 GMT
< location: https://redirector.googlevideo.com/....
< pragma: no-cache
< x-content-type-options: nosniff
< x-frame-options: SAMEORIGIN
...
Để hiểu cấu trúc phản hồi và mã trạng thái, hãy tham khảo Phương thức: phân đoạn nhóm.
Nếu xác thực không thành công, bạn sẽ thấy biểu tượng x-ad-manager-dai-warning:
...
< HTTP/2 302
< access-control-allow-headers: Authorization
< access-control-allow-origin: *
< access-control-expose-headers: Location
< cache-control: no-cache, no-store, max-age=0, must-revalidate
< date: Wed, 25 Mar 2026 18:17:21 GMT
< expires: Mon, 01 Jan 1990 00:00:00 GMT
< location: https://redirector.googlevideo.com/....
< pragma: no-cache
< x-ad-manager-dai-warning: Unable to create ad break due to Unauthorized error (skipping ad break creation)
< x-content-type-options: nosniff
...
DASH (Truyền phát thích ứng động qua HTTP)
Ví dụ sau đây sử dụng mã thông báo HMAC để xác thực yêu cầu phân đoạn pod DASH:
curl --include "https://dai.google.com/linear/pods/v1/seg/network/21775744923/custom_asset/dash-pod-serving-redirect-auth-stream-pod/ad_break_id/ab1/profile/media-ts-4628000bps/0.ts?stream_id=8b061ab5-1efc-4e4d-882f-ae3c071df854:ATL&&sd=10000&pd=30000&auth-token=ad_break_id%3Dab1~custom_asset_key%3Ddash-pod-serving-redirect-auth-stream-pod~exp%3D1774466641~network_code%3D21775744923~pd%3D30000~hmac%3D7249f9193778f2318314519ff2cea5c47958bc7fdd2eaf24008352867af0a050"
Nếu thành công, bạn sẽ thấy phản hồi sau:
...
HTTP/2 302
..
location: https://redirector.googlevideo.com/....
...
Để hiểu cấu trúc phản hồi và mã trạng thái, hãy tham khảo Phương thức: phân đoạn nhóm.
Nếu quá trình xác thực không thành công, bạn sẽ thấy x-ad-manager-dai-warning như sau:
...
HTTP/2 302
..
location: https://redirector.googlevideo.com/....
pragma: no-cache
x-ad-manager-dai-warning: Unable to create ad break due to Unauthorized error (skipping ad break creation)
x-content-type-options: nosniff
...