@microsoft/vscode-azext-azureauth 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://dev.azure.com/ms-azuretools/AzCode/_build/latest?definitionId=17)
|
|
4
4
|
|
|
5
|
-
This package provides a simple way to authenticate to Azure and receive Azure subscription information.
|
|
5
|
+
This package provides a simple way to authenticate to Azure and receive Azure subscription information. It uses the [built-in Microsoft Authentication extension](https://github.com/microsoft/vscode/tree/main/extensions/microsoft-authentication) and does not rely on the [Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account) in any way.
|
|
6
6
|
|
|
7
7
|
## Azure Subscription Provider
|
|
8
8
|
|
|
@@ -28,9 +28,11 @@ export declare class VSCodeAzureSubscriptionProvider extends vscode.Disposable i
|
|
|
28
28
|
/**
|
|
29
29
|
* Checks to see if a user is signed in.
|
|
30
30
|
*
|
|
31
|
+
* @param tenantId (Optional) Provide to check if a user is signed in to a specific tenant.
|
|
32
|
+
*
|
|
31
33
|
* @returns True if the user is signed in, false otherwise.
|
|
32
34
|
*/
|
|
33
|
-
isSignedIn(): Promise<boolean>;
|
|
35
|
+
isSignedIn(tenantId?: string): Promise<boolean>;
|
|
34
36
|
/**
|
|
35
37
|
* Asks the user to sign in or pick an account to use.
|
|
36
38
|
*
|
|
@@ -81,9 +81,9 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
81
81
|
getSubscriptions(filter = true) {
|
|
82
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
83
|
const tenantIds = yield this.getTenantFilters();
|
|
84
|
-
const
|
|
84
|
+
const shouldFilterTenants = filter && !!tenantIds.length; // If the list is empty it is treated as "no filter"
|
|
85
85
|
const subscriptionIds = yield this.getSubscriptionFilters();
|
|
86
|
-
const
|
|
86
|
+
const shouldFilterSubscriptions = filter && !!subscriptionIds.length; // If the list is empty it is treated as "no filter"
|
|
87
87
|
const results = [];
|
|
88
88
|
try {
|
|
89
89
|
this.suppressSignInEvents = true;
|
|
@@ -92,13 +92,17 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
92
92
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
93
93
|
const tenantId = tenant.tenantId;
|
|
94
94
|
// If filtering is enabled, and the current tenant is not in that list, then skip it
|
|
95
|
-
if (
|
|
95
|
+
if (shouldFilterTenants && !tenantIds.includes(tenantId)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
// If the user is not signed in to this tenant, then skip it
|
|
99
|
+
if (!(yield this.isSignedIn(tenantId))) {
|
|
96
100
|
continue;
|
|
97
101
|
}
|
|
98
102
|
// For each tenant, get the list of subscriptions
|
|
99
103
|
for (const subscription of yield this.getSubscriptionsForTenant(tenantId)) {
|
|
100
104
|
// If filtering is enabled, and the current subscription is not in that list, then skip it
|
|
101
|
-
if (
|
|
105
|
+
if (shouldFilterSubscriptions && !subscriptionIds.includes(subscription.subscriptionId)) {
|
|
102
106
|
continue;
|
|
103
107
|
}
|
|
104
108
|
results.push(subscription);
|
|
@@ -108,17 +112,19 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
|
|
|
108
112
|
finally {
|
|
109
113
|
this.suppressSignInEvents = false;
|
|
110
114
|
}
|
|
111
|
-
return results;
|
|
115
|
+
return results.sort((a, b) => a.name.localeCompare(b.name));
|
|
112
116
|
});
|
|
113
117
|
}
|
|
114
118
|
/**
|
|
115
119
|
* Checks to see if a user is signed in.
|
|
116
120
|
*
|
|
121
|
+
* @param tenantId (Optional) Provide to check if a user is signed in to a specific tenant.
|
|
122
|
+
*
|
|
117
123
|
* @returns True if the user is signed in, false otherwise.
|
|
118
124
|
*/
|
|
119
|
-
isSignedIn() {
|
|
125
|
+
isSignedIn(tenantId) {
|
|
120
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
const session = yield vscode.authentication.getSession((0, configuredAzureEnv_1.getConfiguredAuthProviderId)(), this.
|
|
127
|
+
const session = yield vscode.authentication.getSession((0, configuredAzureEnv_1.getConfiguredAuthProviderId)(), this.getScopes([], tenantId), { createIfNone: false, silent: true });
|
|
122
128
|
return !!session;
|
|
123
129
|
});
|
|
124
130
|
}
|