Class BearerTokenAuthenticationPolicy
A policy that sends an AccessToken provided by a TokenCredential as an Authentication header.
Namespace: System.Dynamic.ExpandoObject
Assembly: Azure.Core.dll
Syntax
public class BearerTokenAuthenticationPolicy : Azure.Core.Pipeline.HttpPipelinePolicy
Constructors
BearerTokenAuthenticationPolicy(TokenCredential, IEnumerable<String>)
Creates a new instance of BearerTokenAuthenticationPolicy using provided token credential and scopes to authenticate for.
Declaration
public BearerTokenAuthenticationPolicy (Azure.Core.TokenCredential credential, System.Collections.Generic.IEnumerable<string> scopes);
Parameters
|
TokenCredential
credential
The token credential to use for authentication. |
|
System.Collections.Generic.IEnumerable<System.String>
scopes
Scopes to be included in acquired tokens. |
Exceptions
|
System.ArgumentNullException
When |
BearerTokenAuthenticationPolicy(TokenCredential, String)
Creates a new instance of BearerTokenAuthenticationPolicy using provided token credential and scope to authenticate for.
Declaration
public BearerTokenAuthenticationPolicy (Azure.Core.TokenCredential credential, string scope);
Parameters
|
TokenCredential
credential
The token credential to use for authentication. |
|
System.String
scope
The scope to be included in acquired tokens. |
Methods
AuthenticateAndAuthorizeRequest(HttpMessage, TokenRequestContext)
Sets the Authorization header on the Request by calling GetToken, or from cache, if possible.
Declaration
protected void AuthenticateAndAuthorizeRequest (Azure.Core.HttpMessage message, Azure.Core.TokenRequestContext context);
Parameters
|
HttpMessage
message
The HttpMessage with the Request to be authorized. |
|
TokenRequestContext
context
The TokenRequestContext used to authorize the Request. |
AuthenticateAndAuthorizeRequestAsync(HttpMessage, TokenRequestContext)
Sets the Authorization header on the Request by calling GetToken, or from cache, if possible.
Declaration
[System.Diagnostics.DebuggerStepThrough]
protected System.Threading.Tasks.ValueTask AuthenticateAndAuthorizeRequestAsync (Azure.Core.HttpMessage message, Azure.Core.TokenRequestContext context);
Parameters
|
HttpMessage
message
The HttpMessage with the Request to be authorized. |
|
TokenRequestContext
context
The TokenRequestContext used to authorize the Request. |
Returns
|
System.Threading.Tasks.ValueTask
|
AuthorizeRequest(HttpMessage)
Executes before ProcessAsync(HttpMessage, ReadOnlyMemory<HttpPipelinePolicy>) or Process(HttpMessage, ReadOnlyMemory<HttpPipelinePolicy>) is called. Implementers of this method are expected to call AuthenticateAndAuthorizeRequest(HttpMessage, TokenRequestContext) or AuthenticateAndAuthorizeRequestAsync(HttpMessage, TokenRequestContext) if authorization is required for requests not related to handling a challenge response.
Declaration
protected virtual void AuthorizeRequest (Azure.Core.HttpMessage message);
Parameters
|
HttpMessage
message
The HttpMessage this policy would be applied to. |
AuthorizeRequestAsync(HttpMessage)
Executes before ProcessAsync(HttpMessage, ReadOnlyMemory<HttpPipelinePolicy>) or Process(HttpMessage, ReadOnlyMemory<HttpPipelinePolicy>) is called. Implementers of this method are expected to call AuthenticateAndAuthorizeRequest(HttpMessage, TokenRequestContext) or AuthenticateAndAuthorizeRequestAsync(HttpMessage, TokenRequestContext) if authorization is required for requests not related to handling a challenge response.
Declaration
protected virtual System.Threading.Tasks.ValueTask AuthorizeRequestAsync (Azure.Core.HttpMessage message);
Parameters
|
HttpMessage
message
The HttpMessage this policy would be applied to. |
Returns
|
System.Threading.Tasks.ValueTask
The System.Threading.Tasks.ValueTask representing the asynchronous operation. |
AuthorizeRequestOnChallenge(HttpMessage)
Executed in the event a 401 response with a WWW-Authenticate authentication challenge header is received after the initial request. The default implementation will attempt to handle Continuous Access Evaluation (CAE) claims challenges.
Declaration
protected virtual bool AuthorizeRequestOnChallenge (Azure.Core.HttpMessage message);
Parameters
|
HttpMessage
message
The HttpMessage to be authenticated. |
Returns
|
System.Boolean
A boolean indicating whether the request was successfully authenticated and should be sent to the transport. |
Remarks
Service client libraries may override this to handle service specific authentication challenges.
AuthorizeRequestOnChallengeAsync(HttpMessage)
Executed in the event a 401 response with a WWW-Authenticate authentication challenge header is received after the initial request. The default implementation will attempt to handle Continuous Access Evaluation (CAE) claims challenges.
Declaration
[System.Diagnostics.DebuggerStepThrough]
protected virtual System.Threading.Tasks.ValueTask<bool> AuthorizeRequestOnChallengeAsync (Azure.Core.HttpMessage message);
Parameters
|
HttpMessage
message
The HttpMessage to be authenticated. |
Returns
|
System.Threading.Tasks.ValueTask<System.Boolean>
A boolean indicating whether the request was successfully authenticated and should be sent to the transport. |
Remarks
Service client libraries may override this to handle service specific authentication challenges.
Process(HttpMessage, ReadOnlyMemory<HttpPipelinePolicy>)
Applies the policy to the message. Implementers are expected to mutate Request before calling ProcessNextAsync(HttpMessage, ReadOnlyMemory<HttpPipelinePolicy>) and observe the Response changes after.
Declaration
public override void Process (Azure.Core.HttpMessage message, ReadOnlyMemory<Azure.Core.Pipeline.HttpPipelinePolicy> pipeline);
Parameters
|
HttpMessage
message
The HttpMessage this policy would be applied to. |
|
System.ReadOnlyMemory<HttpPipelinePolicy>
pipeline
The set of HttpPipelinePolicy to execute after current one. |
ProcessAsync(HttpMessage, ReadOnlyMemory<HttpPipelinePolicy>)
Applies the policy to the message. Implementers are expected to mutate Request before calling ProcessNextAsync(HttpMessage, ReadOnlyMemory<HttpPipelinePolicy>) and observe the Response changes after.
Declaration
public override System.Threading.Tasks.ValueTask ProcessAsync (Azure.Core.HttpMessage message, ReadOnlyMemory<Azure.Core.Pipeline.HttpPipelinePolicy> pipeline);
Parameters
|
HttpMessage
message
The HttpMessage this policy would be applied to. |
|
System.ReadOnlyMemory<HttpPipelinePolicy>
pipeline
The set of HttpPipelinePolicy to execute after current one. |
Returns
|
System.Threading.Tasks.ValueTask
The System.Threading.Tasks.ValueTask representing the asynchronous operation. |