Skip to content

Commit

Permalink
only applying baseUri as the scope if it matches an Azure management …
Browse files Browse the repository at this point in the history
…cloud
  • Loading branch information
sadasant authored Aug 14, 2021
1 parent dd32d33 commit 5ed7aca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## 2.6.0 - (2021-08-02)

- Added a new property `baseUri` on the `ServiceClientOptions` that is then used to initialize the corresponding `baseUri` protected property on the `ServiceClient`. This allows the instantiating of the `AzureIdentityCredentialAdapter` class with the right scope when a user constructs a `ServiceClient` with a `TokenCredential`. Resolves https://github.com/Azure/azure-sdk-for-js/issues/15945
- Added a new property `baseUri` on the `ServiceClientOptions` that is then used to initialize the corresponding `baseUri` protected property on the `ServiceClient`.
- For `baseUri` that happen to be known Azure management clouds, this allows the instantiating of the `AzureIdentityCredentialAdapter` class with the right scope when a user constructs a `ServiceClient` with a `TokenCredential`. Resolves https://github.com/Azure/azure-sdk-for-js/issues/15945

## 2.5.3 - (2021-07-12)
- Updated the dependency on the uuid package to v8 (PR [456](https://github.com/Azure/ms-rest-js/pull/456))
Expand Down
18 changes: 14 additions & 4 deletions lib/serviceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,20 @@ export class ServiceClient {

let serviceClientCredentials: ServiceClientCredentials | undefined;
if (isTokenCredential(credentials)) {
serviceClientCredentials = new AzureIdentityCredentialAdapter(
credentials,
options?.baseUri ? `${options.baseUri}/.default` : undefined
);
let scope: string | undefined = undefined;
const azureManagementClouds = [
"https://management.core.windows.net",
"https://management.core.chinacloudapi.cn",
"https://management.core.usgovcloudapi.net",
"https://management.core.cloudapi.de",
];
if (
options?.baseUri &&
azureManagementClouds.find((cloud) => options!.baseUri!.indexOf(cloud) > -1)
) {
scope = `${options.baseUri}/.default`;
}
serviceClientCredentials = new AzureIdentityCredentialAdapter(credentials, scope);
} else {
serviceClientCredentials = credentials;
}
Expand Down

0 comments on commit 5ed7aca

Please sign in to comment.