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

    Function tokenToSchemeCredential

    • Creates an AuthScheme and AuthCredential for an API key or a bearer token.

      Parameters

      • tokenType: "apikey" | "oauth2Token"

        'apikey' or 'oauth2Token'.

      • Optionallocation: "query" | "header" | "cookie"

        Where the API key travels. Ignored for 'oauth2Token', because a bearer token always travels in the Authorization header.

      • Optionalname: string

        The name of the header, query parameter, or cookie.

      • OptionalcredentialValue: string

        The API key or token value. Omit it to build the scheme alone.

      Returns [AuthScheme, AuthCredential | undefined]

      A [scheme, credential] pair. The credential is undefined when 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');

      Error For an unsupported token type or API key location.