Merge pull request #105 from daviwil/cherry-pick-104

Cherry-pick changes from PR #104
This commit is contained in:
David Wilson 2020-09-25 14:41:21 -07:00 коммит произвёл GitHub
Родитель 4bbceb1dc3 ed10075941
Коммит 2ece38f40e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 48 добавлений и 10 удалений

Просмотреть файл

@ -1,7 +1,10 @@
# Changelog
## 3.0.5 - 2020/06/16
## 3.0.6 - 2020/09/25
- Fixed a bug where `buildTenantsList` will throw an error when it can't list tenants
- Added instructions for authenticating with an existing token
## 3.0.5 - 2020/06/16
- The helper method `buildTenantList` is made public. This is helpful if one needs to get the Ids of all the tenants in the account programmatically.
- A new method `setDomain()` which takes the Id of a tenant is now available on all credentials. Use this to change the domain i.e. the tenant against which tokens are created.
- Fixed typos in error messages.
@ -9,11 +12,9 @@
- Added support for the `IDENTITY_ENDPOINT` and `IDENTITY_SECRET` when using the `MSIAppServiceTokenCredentials` credentials.
## 3.0.4 - 2020/05/19 (deprecated)
- Through a mistake of release automation, a CI job from PR #91 got shipped by accident.
## 3.0.3 - 2019/08/22
- Fixed a bug where the callback to `loginWithServicePrincipalSecretWithAuthResponse` is sometimes not called.
For more details, see [PR 77](https://github.com/Azure/ms-rest-nodeauth/pull/77)
@ -27,6 +28,15 @@ For more details, see [PR 77](https://github.com/Azure/ms-rest-nodeauth/pull/77)
- **Breaking change:**
- Updated min version of dependency `@azure/ms-rest-js` from `^1.8.13` to `^2.0.4` there by fixing [#67](https://github.com/Azure/ms-rest-nodeauth/issues/67).
## 2.0.6 - 2020/09/24
- Fixed a bug where `buildTenantsList` will throw an error when it can't list tenants
- Added instructions for authenticating with an existing token
## 2.0.5 - 2019/08/22
- Fixed a bug where the callback to `loginWithServicePrincipalSecretWithAuthResponse` is sometimes not called.
- Fix bug prevent tenant IDs from being discovered on auth
- Reduce number of `Promise` object allocations inside `async` functions.
## 2.0.4 - 2019/08/02
- Rolled back the min version of dependency `@azure/ms-rest-js` from `^2.0.3` to `^1.8.13` thereby fixing [#69](https://github.com/Azure/ms-rest-nodeauth/issues/69).

Просмотреть файл

@ -238,6 +238,26 @@ function getUrl(subscriptionId: string): string {
main();
```
### Authenticating with an existing token
If you have acquired a valid Azure Active Directory token from another source, you can use it to authenticate with Azure SDK libraries using the following code snippet:
```js
const { HttpHeaders } = require("@azure/ms-rest-js");
function getCredentialForToken(accessToken) {
return {
signRequest: (request) => {
if (!request.headers) request.headers = new HttpHeaders();
request.headers.set("Authorization", `Bearer ${accessToken}`);
return Promise.resolve(request);
}
};
}
const creds = getCredentialForToken("your existing token");
```
### Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a

Просмотреть файл

@ -175,10 +175,14 @@ export async function withUsernamePasswordWithAuthResponse(username: string, pas
}
const creds = new UserTokenCredentials(options.clientId, options.domain, username, password, options.tokenAudience, options.environment);
await creds.getToken();
const tokenResponse = await creds.getToken();
// The token cache gets propulated for all the tenants as a part of building the tenantList.
let tenantList = await buildTenantList(creds);
if (tenantList.length === 0 && tokenResponse.tenantId) {
tenantList = [tokenResponse.tenantId];
}
// The token cache gets populated for all the tenants as a part of building the tenantList.
const tenantList = await buildTenantList(creds);
const subscriptionList: LinkedSubscription[] = await _getSubscriptions(creds, tenantList, options.tokenAudience);
return { credentials: creds, subscriptions: subscriptionList };

Просмотреть файл

@ -90,10 +90,14 @@ export async function buildTenantList(credentials: TokenCredentialsBase, apiVers
};
const res = await client.sendRequest(req);
const result: string[] = [];
if (res.status < 300) {
const tenants: any = res.parsedBody;
for (const tenant of tenants.value) {
result.push(tenant.tenantId);
}
}
return result;
}

Просмотреть файл

@ -5,7 +5,7 @@
"email": "azsdkteam@microsoft.com",
"url": "https://github.com/Azure/ms-rest-nodeauth"
},
"version": "3.0.5",
"version": "3.0.6",
"description": "Azure Authentication library in node.js with type definitions.",
"keywords": [
"node",