Package version:
Returns a callback that provides a bearer token. For example, the bearer token can be used to authenticate a request as follows:
import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity";import { createPipelineRequest } from "@azure/core-rest-pipeline";const credential = new DefaultAzureCredential();const scope = "https://cognitiveservices.azure.com/.default";const getAccessToken = getBearerTokenProvider(credential, scope);const token = await getAccessToken();// usageconst request = createPipelineRequest({ url: "https://example.com" });request.headers.set("Authorization", `Bearer ${token}`); Copy
import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity";import { createPipelineRequest } from "@azure/core-rest-pipeline";const credential = new DefaultAzureCredential();const scope = "https://cognitiveservices.azure.com/.default";const getAccessToken = getBearerTokenProvider(credential, scope);const token = await getAccessToken();// usageconst request = createPipelineRequest({ url: "https://example.com" });request.headers.set("Authorization", `Bearer ${token}`);
The credential used to authenticate the request.
The scopes required for the bearer token.
Optional
Options to configure the token provider.
a callback that provides a bearer token.
Returns a callback that provides a bearer token. For example, the bearer token can be used to authenticate a request as follows: