產生憑證

本指南說明如何產生權杖,以及權杖的必要和選用欄位。

如要建立權杖,請編寫要簽署的字串,在本指南中稱為「已簽署的值」。簽署的值包含描述受保護內容的參數、簽署值的到期時間等。

建立權杖字串時,您會使用已簽署的值。您可透過組合權杖的參數 (例如簽署值的對稱金鑰雜湊式訊息驗證碼 (HMAC)),建立權杖字串。

Media CDN 會使用最終組成的權杖,協助保護您的內容。

建立權杖

  1. 如要建立簽署值,請串連含有必要權杖欄位和所需選用權杖欄位的字串。請以半形波浪號 ~ 分隔各個欄位和所有參數。

  2. 使用 Ed25519 簽章或對稱金鑰 HMAC 簽署已簽署的值。

  3. 將含有必要權杖欄位和選用權杖欄位的字串串連起來,即可組成權杖。請以半形波浪號 ~ 分隔各個欄位和所有參數。

    編寫權杖時,簽署值和權杖字串中每個參數的值都相同,但下列情況除外:

    • FullPath
    • Headers

以下程式碼範例說明如何以程式輔助方式建立權杖:

Python

如要向 Media CDN 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

import base64
import datetime
import hashlib
import hmac

import cryptography.hazmat.primitives.asymmetric.ed25519 as ed25519


def base64_encoder(value: bytes) -> str:
    """
    Returns a base64-encoded string compatible with Media CDN.

    Media CDN uses URL-safe base64 encoding and strips off the padding at the
    end.
    """
    encoded_bytes = base64.urlsafe_b64encode(value)
    encoded_str = encoded_bytes.decode("utf-8")
    return encoded_str.rstrip("=")


def sign_token(
    base64_key: bytes,
    signature_algorithm: str,
    start_time: datetime.datetime = None,
    expiration_time: datetime.datetime = None,
    url_prefix: str = None,
    full_path: str = None,
    path_globs: str = None,
    session_id: str = None,
    data: str = None,
    headers: str = None,
    ip_ranges: str = None,
) -> str:
    """Gets the Signed URL Suffix string for the Media CDN' Short token URL requests.
    One of (`url_prefix`, `full_path`, `path_globs`) must be included in each input.
    Args:
        base64_key: Secret key as a base64 encoded string.
        signature_algorithm: Algorithm can be either `SHA1` or `SHA256` or `Ed25519`.
        start_time: Start time as a UTC datetime object.
        expiration_time: Expiration time as a UTC datetime object. If None, an expiration time 1 hour from now will be used.
        url_prefix: the URL prefix to sign, including protocol.
                    For example: http://example.com/path/ for URLs under /path or http://example.com/path?param=1
        full_path:  A full path to sign, starting with the first '/'.
                    For example: /path/to/content.mp4
        path_globs: a set of ','- or '!'-delimited path glob strings.
                    For example: /tv/*!/film/* to sign paths starting with /tv/ or /film/ in any URL.
        session_id: a unique identifier for the session
        data: data payload to include in the token
        headers: header name and value to include in the signed token in name=value format.  May be specified more than once.
                    For example: [{'name': 'foo', 'value': 'bar'}, {'name': 'baz', 'value': 'qux'}]
        ip_ranges: A list of comma separated ip ranges. Both IPv4 and IPv6 ranges are acceptable.
                    For example: "203.0.113.0/24,2001:db8:4a7f:a732/64"

    Returns:
        The Signed URL appended with the query parameters based on the
        specified URL prefix and configuration.
    """

    decoded_key = base64.urlsafe_b64decode(base64_key)
    algo = signature_algorithm.lower()

    # For most fields, the value we put in the token and the value we must sign
    # are the same.  The FullPath and Headers use a different string for the
    # value to be signed compared to the token.  To illustrate this difference,
    # we'll keep the token and the value to be signed separate.
    tokens = []
    to_sign = []

    # check for `full_path` or `path_globs` or `url_prefix`
    if full_path:
        tokens.append("FullPath")
        to_sign.append(f"FullPath={full_path}")
    elif path_globs:
        path_globs = path_globs.strip()
        field = f"PathGlobs={path_globs}"
        tokens.append(field)
        to_sign.append(field)
    elif url_prefix:
        field = "URLPrefix=" + base64_encoder(url_prefix.encode("utf-8"))
        tokens.append(field)
        to_sign.append(field)
    else:
        raise ValueError(
            "User Input Missing: One of `url_prefix`, `full_path` or `path_globs` must be specified"
        )

    # check & parse optional params
    if start_time:
        epoch_duration = start_time.astimezone(
            tz=datetime.timezone.utc
        ) - datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)
        field = f"Starts={int(epoch_duration.total_seconds())}"
        tokens.append(field)
        to_sign.append(field)

    if not expiration_time:
        expiration_time = datetime.datetime.now() + datetime.timedelta(hours=1)
        epoch_duration = expiration_time.astimezone(
            tz=datetime.timezone.utc
        ) - datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)
    else:
        epoch_duration = expiration_time.astimezone(
            tz=datetime.timezone.utc
        ) - datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)
    field = f"Expires={int(epoch_duration.total_seconds())}"
    tokens.append(field)
    to_sign.append(field)

    if session_id:
        field = f"SessionID={session_id}"
        tokens.append(field)
        to_sign.append(field)

    if data:
        field = f"Data={data}"
        tokens.append(field)
        to_sign.append(field)

    if headers:
        header_names = []
        header_pairs = []
        for each in headers:
            header_names.append(each["name"])
            header_pairs.append("%s=%s" % (each["name"], each["value"]))
        tokens.append(f"Headers={','.join(header_names)}")
        to_sign.append(f"Headers={','.join(header_pairs)}")

    if ip_ranges:
        field = f"IPRanges={base64_encoder(ip_ranges.encode('ascii'))}"
        tokens.append(field)
        to_sign.append(field)

    # generating token
    to_sign = "~".join(to_sign)
    to_sign_bytes = to_sign.encode("utf-8")
    if algo == "ed25519":
        digest = ed25519.Ed25519PrivateKey.from_private_bytes(decoded_key).sign(
            to_sign_bytes
        )
        tokens.append("Signature=" + base64_encoder(digest))
    elif algo == "sha256":
        signature = hmac.new(
            decoded_key, to_sign_bytes, digestmod=hashlib.sha256
        ).hexdigest()
        tokens.append("hmac=" + signature)
    elif algo == "sha1":
        signature = hmac.new(
            decoded_key, to_sign_bytes, digestmod=hashlib.sha1
        ).hexdigest()
        tokens.append("hmac=" + signature)
    else:
        raise ValueError(
            "Input Missing Error: `signature_algorithm` can only be one of `sha1`, `sha256` or `ed25519`"
        )
    return "~".join(tokens)

Java

如要向 Media CDN 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Optional;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters;
import org.bouncycastle.crypto.signers.Ed25519Signer;
import org.bouncycastle.util.encoders.Hex;

public class DualToken {

  public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeyException {
    // TODO(developer): Replace these variables before running the sample.
    // Secret key as a base64 encoded string.
    byte[] base64Key = new byte[]{};
    // Algorithm can be one of these: SHA1, SHA256, or Ed25519.
    String signatureAlgorithm = "ed25519";
    // (Optional) Start time as a UTC datetime object.
    DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT;
    Optional<Instant> startTime = Optional.empty();
    // Expiration time as a UTC datetime object.
    // If None, an expiration time that's an hour after the current time is used.
    Instant expiresTime = Instant.from(formatter.parse("2022-09-13T12:00:00Z"));

    // ONE OF (`urlPrefix`, `fullPath`, `pathGlobs`) must be included in each input.
    // The URL prefix and protocol to sign.
    // For example: http://example.com/path/ for URLs under /path or http://example.com/path?param=1
    Optional<String> urlPrefix = Optional.empty();
    // A full path to sign, starting with the first '/'.
    // For example: /path/to/content.mp4
    Optional<String> fullPath = Optional.of("http://10.20.30.40/");
    // A set of path glob strings delimited by ',' or '!'.
    // For example: /tv/*!/film/* to sign paths starting with /tv/ or /film/ in any URL.
    Optional<String> pathGlobs = Optional.empty();

    // (Optional) A unique identifier for the session.
    Optional<String> sessionId = Optional.empty();
    // (Optional) Data payload to include in the token.
    Optional<String> data = Optional.empty();
    // (Optional) Header name and value to include in the signed token in name=value format.
    // May be specified more than once.
    // For example: [{'name': 'foo', 'value': 'bar'}, {'name': 'baz', 'value': 'qux'}]
    Optional<List<Header>> headers = Optional.empty();
    // (Optional) A list of comma-separated IP ranges. Both IPv4 and IPv6 ranges are acceptable.
    // For example: "203.0.113.0/24,2001:db8:4a7f:a732/64"
    Optional<String> ipRanges = Optional.empty();

    DualToken.signToken(
        base64Key,
        signatureAlgorithm,
        startTime,
        expiresTime,
        urlPrefix,
        fullPath,
        pathGlobs,
        sessionId,
        data,
        headers,
        ipRanges);
  }

  // Gets the signed URL suffix string for the Media CDN short token URL requests.
  // Result:
  //     The signed URL appended with the query parameters based on the
  // specified URL prefix and configuration.
  public static void signToken(
      byte[] base64Key, String signatureAlgorithm, Optional<Instant> startTime,
      Instant expirationTime, Optional<String> urlPrefix, Optional<String> fullPath,
      Optional<String> pathGlobs, Optional<String> sessionId, Optional<String> data,
      Optional<List<Header>> headers, Optional<String> ipRanges)
      throws NoSuchAlgorithmException, InvalidKeyException {

    String field = "";
    byte[] decodedKey = Base64.getUrlDecoder().decode(base64Key);

    // For most fields, the value in the token and the value to sign
    // are the same. Compared to the token, the FullPath and Headers
    // use a different string for the value to sign. To illustrate this difference,
    // we'll keep the token and the value to be signed separate.
    List<String> tokens = new ArrayList<>();
    List<String> toSign = new ArrayList<>();

    // Check for `fullPath` or `pathGlobs` or `urlPrefix`.
    if (fullPath.isPresent()) {
      tokens.add("FullPath");
      toSign.add(String.format("FullPath=%s", fullPath.get()));
    } else if (pathGlobs.isPresent()) {
      field = String.format("PathGlobs=%s", pathGlobs.get().trim());
      tokens.add(field);
      toSign.add(field);
    } else if (urlPrefix.isPresent()) {
      field = String.format("URLPrefix=%s",
          base64Encoder(urlPrefix.get().getBytes(StandardCharsets.UTF_8)));
      tokens.add(field);
      toSign.add(field);
    } else {
      throw new IllegalArgumentException(
          "User Input Missing: One of `urlPrefix`, `fullPath` or `pathGlobs` must be specified");
    }

    // Check & parse optional params.
    long epochDuration;
    if (startTime.isPresent()) {
      epochDuration = ChronoUnit.SECONDS.between(Instant.EPOCH, startTime.get());
      field = String.format("Starts=%s", epochDuration);
      tokens.add(field);
      toSign.add(field);
    }

    if (expirationTime == null) {
      expirationTime = Instant.now().plus(1, ChronoUnit.HOURS);
    }
    epochDuration = ChronoUnit.SECONDS.between(Instant.EPOCH, expirationTime);
    field = String.format("Expires=%s", epochDuration);
    tokens.add(field);
    toSign.add(field);

    if (sessionId.isPresent()) {
      field = String.format("SessionID=%s", sessionId.get());
      tokens.add(field);
      toSign.add(field);
    }

    if (data.isPresent()) {
      field = String.format("Data=%s", data.get());
      tokens.add(field);
      toSign.add(field);
    }

    if (headers.isPresent()) {
      List<String> headerNames = new ArrayList<>();
      List<String> headerPairs = new ArrayList<>();

      for (Header entry : headers.get()) {
        headerNames.add(entry.getName());
        headerPairs.add(String.format("%s=%s", entry.getName(), entry.getValue()));
      }
      tokens.add(String.format("Headers=%s", String.join(",", headerNames)));
      toSign.add(String.format("Headers=%s", String.join(",", headerPairs)));
    }

    if (ipRanges.isPresent()) {
      field = String.format("IPRanges=%s",
          base64Encoder(ipRanges.get().getBytes(StandardCharsets.US_ASCII)));
      tokens.add(field);
      toSign.add(field);
    }

    // Generate token.
    String toSignJoined = String.join("~", toSign);
    byte[] toSignBytes = toSignJoined.getBytes(StandardCharsets.UTF_8);
    String algorithm = signatureAlgorithm.toLowerCase();

    if (algorithm.equalsIgnoreCase("ed25519")) {
      Ed25519PrivateKeyParameters privateKey = new Ed25519PrivateKeyParameters(decodedKey, 0);
      Ed25519Signer signer = new Ed25519Signer();
      signer.init(true, privateKey);
      signer.update(toSignBytes, 0, toSignBytes.length);
      byte[] signature = signer.generateSignature();
      tokens.add(String.format("Signature=%s", base64Encoder(signature)));
    } else if (algorithm.equalsIgnoreCase("sha256")) {
      String sha256 = "HmacSHA256";
      Mac mac = Mac.getInstance(sha256);
      SecretKeySpec secretKeySpec = new SecretKeySpec(decodedKey, sha256);
      mac.init(secretKeySpec);
      byte[] signature = mac.doFinal(toSignBytes);
      tokens.add(String.format("hmac=%s", Hex.toHexString(signature)));
    } else if (algorithm.equalsIgnoreCase("sha1")) {
      String sha1 = "HmacSHA1";
      Mac mac = Mac.getInstance(sha1);
      SecretKeySpec secretKeySpec = new SecretKeySpec(decodedKey, sha1);
      mac.init(secretKeySpec);
      byte[] signature = mac.doFinal(toSignBytes);
      tokens.add(String.format("hmac=%s", Hex.toHexString(signature)));
    } else {
      throw new Error(
          "Input Missing Error: `signatureAlgorithm` can only be one of `sha1`, `sha256` or "
              + "`ed25519`");
    }
    // The signed URL appended with the query parameters based on the
    // specified URL prefix and configuration.
    System.out.println(String.join("~", tokens));
  }

  // Returns a base64-encoded string compatible with Media CDN.
  // Media CDN uses URL-safe base64 encoding and strips off the padding at the
  // end.
  public static String base64Encoder(byte[] value) {
    byte[] encodedBytes = Base64.getUrlEncoder().withoutPadding().encode(value);
    return new String(encodedBytes, StandardCharsets.UTF_8);
  }

  public static class Header {

    private String name;
    private String value;

    public Header(String name, String value) {
      this.name = name;
      this.value = value;
    }

    public String getName() {
      return name;
    }

    public void setName(String name) {
      this.name = name;
    }

    public String getValue() {
      return value;
    }

    public void setValue(String value) {
      this.value = value;
    }

    @Override
    public String toString() {
      return "Header{"
          + "name='" + name + '\''
          + ", value='" + value + '\''
          + '}';
    }
  }

}

以下各節說明權杖使用的欄位。

必要權杖欄位

每個權杖都必須填寫下列欄位:

  • Expires
  • 下列任一項:
    • PathGlobs
    • URLPrefix
    • FullPath
  • 下列任一項:
    • Signature
    • hmac

除非另有規定,否則參數名稱和值會區分大小寫。

下表說明每個參數:

欄位名稱 / 別名 權杖參數 簽署的值

Expires

exp

自 Unix 紀元 (1970-01-01T00:00:00Z) 經過的整數秒數 Expires=EXPIRATION_TIME,之後權杖就會失效。

PathGlobs

pathsacl

最多五個路徑區隔的清單,可授予存取權。區隔可使用半形逗號 (,) 或半形驚嘆號 (!) 做為分隔符號,但不能同時使用兩者。

PathGlobs 支援在路徑中使用星號 (*) 和問號 (?) 做為萬用字元。單一星號 (*) 字元可跨越任意數量的路徑片段,這與 pathMatchTemplate 的模式比對語法不同。

路徑參數 (以半形分號 ; 表示) 不得使用,因為比對時會造成模糊不清。

因此,請確保網址不包含下列特殊字元:,!*?;

PathGlobs=PATHS
URLPrefix

採用 Base64 編碼的網路安全網址,包括通訊協定 http://https://,最多可選擇一個點。

舉例來說,`https://example.com/foo/bar.ts` 的有效 URLPrefix 值包括 `https://example.com`、`https://example.com/foo` 和 `https://example.com/foo/bar`。

URLPrefix=BASE_64_URL_PREFIX
FullPath 無,在權杖中指定 FullPath 時,請勿重複您在簽署值中指定的路徑。在權杖中,加入不含 = 的欄位名稱。 FullPath=FULL_PATH_TO_OBJECT
Signature 簽章的 Base64 編碼版本,可在網路上安全使用。 不適用
hmac 採用 Base64 編碼的網路安全 HMAC 值。 不適用

PathGlobs 萬用字元語法

下表說明 PathGlobs 萬用字元語法。

運算子 相符 範例
* (星號) 比對網址路徑中零個或多個字元,包括斜線 (/) 字元。
  • /videos/* 會比對所有以 /videos/ 開頭的路徑。
  • /videos/s*/4k/* 符合 /videos/s/4k//videos/s01/4k/main.m3u8
  • /manifests/*/4k/* 符合 /manifests/s01/4k/main.m3u8/manifests/s01/e01/4k/main.m3u8。不符合模式 /manifests/4k/main.m3u8
? (問號) 比對網址路徑中的單一字元,不包括斜線 (/) 字元。 /videos/s?main.m3u8相符項目 /videos/s1main.m3u8。不符合 /videos/s01main.m3u8/videos/s/main.m3u8

網址路徑的 glob 必須以星號 (*) 或正斜線 (/) 開頭。

由於 */* 會比對所有網址路徑,因此我們不建議在已簽署的權杖中使用這兩者。為確保獲得最周全的保護,請確認 glob 符合您要授予存取權的內容。

選填的權杖欄位

除非另有規定,否則參數名稱和值會區分大小寫。

下表說明選用參數的參數名稱、別名和詳細資料:

欄位名稱 / 別名 參數 簽署的值

Starts

st

自 Unix 紀元 (1970-01-01T00:00:00Z) 起算的整數秒數 Starts=START_TIME
IPRanges

最多五個 IPv4 和 IPv6 位址的清單 (採用 CIDR 格式),這些位址的網址採用網頁安全 Base64 格式。舉例來說,如要指定 IP 範圍「192.6.13.13/32,193.5.64.135/32」,請指定 IPRanges=MTkyLjYuMTMuMTMvMzIsMTkzLjUuNjQuMTM1LzMy

如果用戶端有 WAN 遷移風險,或是應用程式前端的網路路徑與傳送路徑不同,則在權杖中加入 IPRanges 可能沒有幫助。如果用戶端連線時使用的 IP 位址不在已簽署的要求中,Media CDN 會以 HTTP 403 程式碼拒絕用戶端。

在下列情況下,Media CDN 可能會以 HTTP 403 代碼拒絕用戶端:

  • 雙重堆疊 (IPv4、IPv6) 環境
  • 連線遷移 (從 Wi-Fi 遷移至行動網路,以及從行動網路遷移至 Wi-Fi)
  • 使用電信業者閘道 NAT (CGNAT 或 CGN) 的行動網路
  • 多路徑 TCP (MPTCP)

這些因素都可能導致特定用戶端在影片播放期間擁有非決定性 IP 位址。如果發出存取權後用戶端 IP 位址變更,且用戶端嘗試將影片片段下載至播放緩衝區,則會收到 Media CDN 傳送的 HTTP 403

IPRanges=BASE_64_IP_RANGES

SessionID

id

任意字串,可用於記錄分析或播放追蹤。

為避免建立無效權杖,請使用 % 編碼或網路安全 base64 編碼字串。SessionID 不得使用下列字元,否則權杖會失效:「~」、「&」或「 」(空格)。

SessionID=SESSION_ID_VALUE

Data

datapayload

任意字串,可用於記錄分析。

為避免建立無效權杖,請使用 % 編碼或網路安全 base64 編碼字串。Data 不得使用下列字元,否則權杖會失效:「~」、「&」或「 」(空格)。

data=DATA_VALUE
Headers 以半形逗號分隔的標頭欄位名稱清單。標頭名稱不區分大小寫,簽署值中的標頭名稱會區分大小寫。如果缺少標頭,值會是空字串。如果標頭有多個副本,則會以半形逗號串連。 Headers=HEADER_1_NAME=HEADER_1_EXPECTED_VALUE, HEADER_2_NAME=HEADER_2_EXPECTED_VALUE

範例

以下各節提供產生權杖的範例。

使用 FullPath 的範例

請參考以下使用 FullPath 欄位的範例:

  • 要求項目:http://example.com/tv/my-show/s01/e01/playlist.m3u8
  • 到期時間:160000000

簽署的值為:

Expires=160000000~FullPath=/tv/my-show/s01/e01/playlist.m3u8

如要建立權杖,請使用 Ed25519 簽章或對稱金鑰 HMAC 簽署已簽署的值。

以下是從已簽署值建立的權杖範例:

Ed25519 簽章

Expires=160000000~FullPath~Signature=SIGNATURE_OF_SIGNED_VALUE

其中 SIGNATURE_OF_SIGNED_VALUE 是先前建立的簽署值 ED25519 簽章。

對稱金鑰 HMAC

Expires=160000000~FullPath~hmac=HMAC_OF_SIGNED_VALUE

其中 HMAC_OF_SIGNED_VALUE 是先前建立的簽署值對稱金鑰 HMAC。

在上述範例中,權杖中提供 FullPath,但值不會從簽署值中指定的路徑重複。這樣一來,您就能簽署要求的完整路徑,不必在權杖中複製要求。

使用 URLPrefix 的範例

請參考以下使用 URLPrefix 欄位的範例:

  • 要求項目:http://example.com/tv/my-show/s01/e01/playlist.m3u8
  • 到期時間:160000000

簽署的值為:

Expires=160000000~URLPrefix=aHR0cDovL2V4YW1wbGUuY29tL3R2L215LXNob3cvczAxL2UwMS9wbGF5bGlzdC5tM3U4

在前述範例中,我們將所要求項目的路徑 http://example.com/tv/my-show/s01/e01/playlist.m3u8 替換為網頁安全 Base64 格式的項目路徑 aHR0cDovL2V4YW1wbGUuY29tL3R2L215LXNob3cvczAxL2UwMS9wbGF5bGlzdC5tM3U4

如要建立權杖,請使用 Ed25519 簽章或對稱金鑰 HMAC 簽署已簽署的值。

以下是從已簽署值建立的權杖範例:

Ed25519 簽章

Expires=160000000~URLPrefix=aHR0cDovL2V4YW1wbGUuY29tL3R2L215LXNob3cvczAxL2UwMS9wbGF5bGlzdC5tM3U4~Signature=SIGNATURE_OF_SIGNED_VALUE

其中 SIGNATURE_OF_SIGNED_VALUE 是先前建立的簽署值 ED25519 簽章。

對稱金鑰 HMAC

Expires=160000000~URLPrefix=aHR0cDovL2V4YW1wbGUuY29tL3R2L215LXNob3cvczAxL2UwMS9wbGF5bGlzdC5tM3U4~hmac=HMAC_OF_SIGNED_VALUE

其中 HMAC_OF_SIGNED_VALUE 是先前建立的簽署值對稱金鑰 HMAC。

使用 Headers 的範例

請參考以下使用 Headers 欄位的範例:

  • 要求項目:http://example.com/tv/my-show/s01/e01/playlist.m3u8
  • 到期時間:160000000
  • PathGlobs 值:*
  • 預期要求標頭:
    • user-agent: browser
    • accept: text/html

簽署的值為:

Expires=160000000~PathGlobs=*~Headers=user-agent=browser,accept=text/html

如要建立權杖,請使用 Ed25519 簽章或對稱金鑰 HMAC 簽署已簽署的值。

以下是從已簽署值建立的權杖範例:

Ed25519 簽章

Expires=160000000~PathGlobs=*~Headers=user-agent,accept~Signature=SIGNATURE_OF_SIGNED_VALUE

其中 SIGNATURE_OF_SIGNED_VALUE 是先前建立的簽署值 ED25519 簽章。

對稱金鑰 HMAC

Expires=160000000~PathGlobs=*~Headers=user-agent,accept~hmac=HMAC_OF_SIGNED_VALUE

其中 HMAC_OF_SIGNED_VALUE 是先前建立的簽署值對稱金鑰 HMAC。

在上述範例中,權杖中提供 Headers=user-agent,accept,但預期的標頭值不會從簽署值重複。這樣一來,您就能簽署特定要求標頭鍵/值組合,而不必在權杖中重複這些值。