BearerTokenCredentialPolicy Class

Adds a bearer token Authorization header to requests.

Inheritance
azure.core.pipeline.policies._authentication._BearerTokenCredentialPolicyBase
BearerTokenCredentialPolicy
azure.core.pipeline.policies._base.HTTPPolicy
BearerTokenCredentialPolicy

Constructor

BearerTokenCredentialPolicy(credential: TokenCredential, *scopes: str, **kwargs: Any)

Parameters

credential
<xref:azure.core.TokenCredential>
Required

The credential.

scopes
str
Required

Lets you specify the type of access needed.

Methods

authorize_request

Acquire a token from the credential and authorize the request with it.

Keyword arguments are passed to the credential's get_token method. The token will be cached and used to authorize future requests.

on_challenge

Authorize request according to an authentication challenge

This method is called when the resource provider responds 401 with a WWW-Authenticate header.

on_exception

Executed when an exception is raised while executing the next policy.

This method is executed inside the exception handler.

on_request

Called before the policy sends a request.

The base implementation authorizes the request with a bearer token.

on_response

Executed after the request comes back from the next policy.

send

Authorize request with a bearer token and send it to the next policy

authorize_request

Acquire a token from the credential and authorize the request with it.

Keyword arguments are passed to the credential's get_token method. The token will be cached and used to authorize future requests.

authorize_request(request: PipelineRequest, *scopes: str, **kwargs: Any) -> None

Parameters

request
PipelineRequest
Required

the request

scopes
str
Required

required scopes of authentication

on_challenge

Authorize request according to an authentication challenge

This method is called when the resource provider responds 401 with a WWW-Authenticate header.

on_challenge(request: PipelineRequest, response: PipelineResponse) -> bool

Parameters

request
PipelineRequest
Required

the request which elicited an authentication challenge

response
PipelineResponse
Required

the resource provider's response

Returns

a bool indicating whether the policy should send the request

on_exception

Executed when an exception is raised while executing the next policy.

This method is executed inside the exception handler.

on_exception(request: PipelineRequest) -> None

Parameters

request
PipelineRequest
Required

The Pipeline request object

on_request

Called before the policy sends a request.

The base implementation authorizes the request with a bearer token.

on_request(request: PipelineRequest) -> None

Parameters

request
PipelineRequest
Required

the request

on_response

Executed after the request comes back from the next policy.

on_response(request: PipelineRequest, response: PipelineResponse) -> None

Parameters

request
PipelineRequest
Required

Request to be modified after returning from the policy.

response
PipelineResponse
Required

Pipeline response object

send

Authorize request with a bearer token and send it to the next policy

send(request: PipelineRequest) -> PipelineResponse

Parameters

request
PipelineRequest
Required

The pipeline request object