GeezerVison is showing adk.dev — tokenToSchemeCredential | ADK for TypeScript: API Reference - v2.5.0
Function tokenToSchemeCredential
-
tokenToSchemeCredential( tokenType: "apikey" | "oauth2Token", location?: "cookie" | "query" | "header", name?: string, credentialValue?: string,): [AuthScheme, AuthCredential | undefined]
Creates an AuthScheme and AuthCredential for an API key or a bearer token.
Parameters
- tokenType: "apikey" | "oauth2Token"
'apikey' or 'oauth2Token'.
Optionallocation: "cookie" | "query" | "header"
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.
A [scheme, credential] pair. The credential is undefined when
credentialValue is omitted.
Example
// API key in a header.
const [scheme, credential] = tokenToSchemeCredential(
'apikey', 'header', 'X-API-Key', 'your_api_key_value');
Example
// OAuth2 bearer token in the Authorization header.
const [scheme, credential] = tokenToSchemeCredential(
'oauth2Token', 'header', 'Authorization', 'your_bearer_token_value');
Throws
Error For an unsupported token type or API key location.