@azure/core-client
Advanced tools
Comparing version 1.0.0-alpha.20201123.1 to 1.0.0-alpha.20201203.2
@@ -12,2 +12,3 @@ // Copyright (c) Microsoft Corporation. | ||
import { deserializationPolicy } from "./deserializationPolicy"; | ||
import { URL } from "./url"; | ||
/** | ||
@@ -28,6 +29,7 @@ * Initializes a new instance of the ServiceClient. | ||
this._stringifyXML = options.stringifyXML; | ||
const credentialScopes = getCredentialScopes(options); | ||
this._pipeline = | ||
options.pipeline || | ||
createDefaultPipeline({ | ||
baseUri: this._baseUri, | ||
credentialScopes, | ||
credential: options.credential, | ||
@@ -215,4 +217,7 @@ parseXML: options.parseXML | ||
function createDefaultPipeline(options = {}) { | ||
const credentialOptions = options.credential && options.credentialScopes | ||
? { credentialScopes: options.credentialScopes, credential: options.credential } | ||
: undefined; | ||
return createClientPipeline({ | ||
credentialOptions: options, | ||
credentialOptions, | ||
deserializationOptions: { | ||
@@ -230,9 +235,7 @@ parseXML: options.parseXML | ||
export function createClientPipeline(options = {}) { | ||
var _a, _b; | ||
const pipeline = createPipelineFromOptions(options !== null && options !== void 0 ? options : {}); | ||
const credential = (_a = options.credentialOptions) === null || _a === void 0 ? void 0 : _a.credential; | ||
if (credential) { | ||
if (options.credentialOptions) { | ||
pipeline.addPolicy(bearerTokenAuthenticationPolicy({ | ||
credential, | ||
scopes: `${((_b = options.credentialOptions) === null || _b === void 0 ? void 0 : _b.baseUri) || ""}/.default` | ||
credential: options.credentialOptions.credential, | ||
scopes: options.credentialOptions.credentialScopes | ||
})); | ||
@@ -298,2 +301,17 @@ } | ||
} | ||
function getCredentialScopes(options) { | ||
if (options.credentialScopes) { | ||
const scopes = options.credentialScopes; | ||
return Array.isArray(scopes) | ||
? scopes.map((scope) => new URL(scope).toString()) | ||
: new URL(scopes).toString(); | ||
} | ||
if (options.baseUri) { | ||
return `${options.baseUri}/.default`; | ||
} | ||
if (options.credential && !options.credentialScopes) { | ||
throw new Error(`When using credentials, the ServiceClientOptions must contain either a baseUri or a credentialScopes. Unable to create a bearerTokenAuthenticationPolicy`); | ||
} | ||
return undefined; | ||
} | ||
//# sourceMappingURL=serviceClient.js.map |
{ | ||
"name": "@azure/core-client", | ||
"version": "1.0.0-alpha.20201123.1", | ||
"version": "1.0.0-alpha.20201203.2", | ||
"description": "Core library for interfacing with AutoRest generated code", | ||
@@ -5,0 +5,0 @@ "sdk-type": "client", |
@@ -81,4 +81,4 @@ import { AbortSignalLike } from '@azure/abort-controller'; | ||
credentialOptions?: { | ||
baseUri?: string; | ||
credential?: TokenCredential; | ||
credentialScopes: string | string[]; | ||
credential: TokenCredential; | ||
}; | ||
@@ -557,2 +557,6 @@ /** | ||
/** | ||
* If specified, will be used to build the BearerTokenAuthenticationPolicy. | ||
*/ | ||
credentialScopes?: string | string[]; | ||
/** | ||
* The default request content type for the service. | ||
@@ -559,0 +563,0 @@ * Used if no requestContentType is present on an OperationSpec. |
@@ -83,4 +83,4 @@ import { AbortSignalLike } from '@azure/abort-controller'; | ||
credentialOptions?: { | ||
baseUri?: string; | ||
credential?: TokenCredential; | ||
credentialScopes: string | string[]; | ||
credential: TokenCredential; | ||
}; | ||
@@ -597,2 +597,6 @@ /** | ||
/** | ||
* If specified, will be used to build the BearerTokenAuthenticationPolicy. | ||
*/ | ||
credentialScopes?: string | string[]; | ||
/** | ||
* The default request content type for the service. | ||
@@ -599,0 +603,0 @@ * Used if no requestContentType is present on an OperationSpec. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
531067
4847