Class KeyCredentialPolicy

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

public class KeyCredentialPolicy extends Object implements HttpPipelinePolicy
The KeyCredentialPolicy class is an implementation of the HttpPipelinePolicy interface. This policy uses a KeyCredential to set the authorization key for a request in the form of a header.

This class is useful when you need to authorize requests with a key. It ensures that the requests are sent over HTTPS to prevent the key from being leaked. The key is set in the header of the HTTP request.

Code sample:

In this example, a KeyCredentialPolicy is created with a key and a header name. The policy can then be added to the pipeline. The request sent by the pipeline will then include the specified header with the key as its value.

 KeyCredential credential = new KeyCredential("my_key");
 KeyCredentialPolicy policy = new KeyCredentialPolicy("my_header", credential);
 
See Also: