Class BearerTokenAuthenticationPolicy

  • All Implemented Interfaces:
    HttpPipelinePolicy

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

      • 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 Detail

      • 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
      • 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
      • 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