Class BearerTokenAuthenticationPolicy

java.lang.Object
com.azure.core.http.policy.BearerTokenAuthenticationPolicy
All Implemented Interfaces:
HttpPipelinePolicy
Direct Known Subclasses:
ArmChallengeAuthenticationPolicy

public class BearerTokenAuthenticationPolicy extends Object implements HttpPipelinePolicy
The pipeline policy that applies a token credential to an HTTP request with "Bearer" scheme.
  • Constructor Details

    • BearerTokenAuthenticationPolicy

      public BearerTokenAuthenticationPolicy(TokenCredential credential, String... scopes)
      Creates BearerTokenAuthenticationPolicy.
      Parameters:
      credential - the token credential to authenticate the request
      scopes - the scopes of authentication the credential should get token for
  • Method Details

    • authorizeRequest

      public Mono<Void> authorizeRequest(HttpPipelineCallContext context)
      Executed before sending the initial request and authenticates the request.
      Parameters:
      context - The request context.
      Returns:
      A Mono containing Void
    • authorizeRequestSync

      public void authorizeRequestSync(HttpPipelineCallContext context)
      Synchronously executed before sending the initial request and authenticates the request.
      Parameters:
      context - The request context.
    • authorizeRequestOnChallenge

      public Mono<Boolean> authorizeRequestOnChallenge(HttpPipelineCallContext context, HttpResponse response)
      Handles the authentication challenge in the event a 401 response with a WWW-Authenticate authentication challenge header is received after the initial request and returns appropriate TokenRequestContext to be used for re-authentication.
      Parameters:
      context - The request context.
      response - The Http Response containing the authentication challenge header.
      Returns:
      A Mono containing TokenRequestContext
    • authorizeRequestOnChallengeSync

      public boolean authorizeRequestOnChallengeSync(HttpPipelineCallContext context, HttpResponse response)
      Handles the authentication challenge in the event a 401 response with a WWW-Authenticate authentication challenge header is received after the initial request and returns appropriate TokenRequestContext to be used for re-authentication.
      Parameters:
      context - The request context.
      response - The Http Response containing the authentication challenge header.
      Returns:
      A boolean indicating if containing the TokenRequestContext for re-authentication
    • process

      Description copied from interface: HttpPipelinePolicy
      Processes provided request context and invokes the next policy.
      Specified by:
      process in interface HttpPipelinePolicy
      Parameters:
      context - The request context.
      next - The next policy to invoke.
      Returns:
      A publisher that initiates the request upon subscription and emits a response on completion.
    • processSync

      Description copied from interface: HttpPipelinePolicy
      Processes provided request context and invokes the next policy synchronously.
      Specified by:
      processSync in interface HttpPipelinePolicy
      Parameters:
      context - The request context.
      next - The next policy to invoke.
      Returns:
      A publisher that initiates the request upon subscription and emits a response on completion.
    • setAuthorizationHeader

      public Mono<Void> setAuthorizationHeader(HttpPipelineCallContext context, TokenRequestContext tokenRequestContext)
      Authorizes the request with the bearer token acquired using the specified tokenRequestContext
      Parameters:
      context - the HTTP pipeline context.
      tokenRequestContext - the token request context to be used for token acquisition.
      Returns:
      a Mono containing Void
    • setAuthorizationHeaderSync

      public void setAuthorizationHeaderSync(HttpPipelineCallContext context, TokenRequestContext tokenRequestContext)
      Authorizes the request with the bearer token acquired using the specified tokenRequestContext
      Parameters:
      context - the HTTP pipeline context.
      tokenRequestContext - the token request context to be used for token acquisition.