ADK for TypeScript: API Reference
    Preparing search index...

    函数名称:tokenToSchemeCredential API 标识符:(该函数为内部函数,因此没有公开的 API 标识符) 占位符:(该函数为内部函数,因此没有占位符)

    • 为 API 密钥或承载令牌(bearer token)创建相应的 `AuthScheme` 和 `AuthCredential` 对象。

      参数

      • tokenType: “apikey” | “oauth2Token”

        'apikey' 或者 'oauth2Token'.

      • Optional位置: “cookie” | “query” | “header”

        API密钥的传输路径。此信息可被忽略。 'oauth2Token'因为承载令牌(bearer token)总是通过 `Authorization` 头部进行传输。

      • Optional名称: string

        头部信息(header)、查询参数(query parameter)或 Cookie 的名称。

      • OptionalcredentialValue: string

        API密钥或令牌值。如果仅需要构建该方案(scheme),可以忽略此字段。

      返回值 [AuthScheme, AuthCredential | `undefined`]

      A [scheme, credential] `pair`。该凭证是…… undefined 当……的时候 credentialValue (注:原句中“is omitted”已被保留;如果需要进一步解释或补充内容,请提供更多背景信息。)

      // API key in a header.
      const [scheme, credential] = tokenToSchemeCredential(
      'apikey', 'header', 'X-API-Key', 'your_api_key_value');
      // OAuth2 bearer token in the Authorization header.
      const [scheme, credential] = tokenToSchemeCredential(
      'oauth2Token', 'header', 'Authorization', 'your_bearer_token_value');

      错误:使用的令牌类型或 API 密钥的位置不受支持。