Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
) {
if (!options) {
options = {};
}
this._withCredentials = options.withCredentials || false;
this._httpClient = options.httpClient || new DefaultHttpClient();
this._requestPolicyOptions = new RequestPolicyOptions(options.httpPipelineLogger);
let requestPolicyFactories: RequestPolicyFactory[];
if (Array.isArray(options.requestPolicyFactories)) {
logger.info("ServiceClient: using custom request policies");
requestPolicyFactories = options.requestPolicyFactories;
} else {
let authPolicyFactory: RequestPolicyFactory | undefined = undefined;
if (isTokenCredential(credentials)) {
logger.info(
"ServiceClient: creating bearer token authentication policy from provided credentials"
);
// Create a wrapped RequestPolicyFactory here so that we can provide the
// correct scope to the BearerTokenAuthenticationPolicy at the first time
// one is requested. This is needed because generated ServiceClient
// implementations do not set baseUri until after ServiceClient's constructor
// is finished, leaving baseUri empty at the time when it is needed to
// build the correct scope name.
const wrappedPolicyFactory: () => RequestPolicyFactory = () => {
let bearerTokenPolicyFactory: RequestPolicyFactory | undefined = undefined;
let serviceClient = this;
return {
create(nextPolicy: RequestPolicy, options: RequestPolicyOptions): RequestPolicy {
if (bearerTokenPolicyFactory === undefined) {
bearerTokenPolicyFactory = bearerTokenAuthenticationPolicy(