@microsoft/vscode-azext-azureauth 2.0.0 → 2.1.0

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.
@@ -0,0 +1,4 @@
1
+ import type { TenantIdDescription } from '@azure/arm-subscriptions';
2
+ export interface Tenant extends TenantIdDescription {
3
+ isAuthenticated: boolean;
4
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License. See License.txt in the project root for license information.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=Tenant.js.map
@@ -266,28 +266,36 @@ class VSCodeAzureSubscriptionProvider extends vscode.Disposable {
266
266
  *
267
267
  * @returns A client, the credential used by the client, and the authentication function
268
268
  */
269
- getSubscriptionClient(tenantId, scopes) {
269
+ getSubscriptionClient(tenantId) {
270
270
  return __awaiter(this, void 0, void 0, function* () {
271
- const armSubs = yield Promise.resolve().then(() => require('@azure/arm-resources-subscriptions'));
272
- const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true });
273
- if (!session) {
271
+ const initialSession = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(undefined, tenantId, { createIfNone: false, silent: true });
272
+ if (!initialSession) {
274
273
  throw new NotSignedInError_1.NotSignedInError();
275
274
  }
276
275
  const credential = {
277
- getToken: () => __awaiter(this, void 0, void 0, function* () {
278
- return {
279
- token: session.accessToken,
280
- expiresOnTimestamp: 0
281
- };
276
+ getToken: (scopes, _options) => __awaiter(this, void 0, void 0, function* () {
277
+ const session = yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true });
278
+ if (session === null || session === void 0 ? void 0 : session.accessToken) {
279
+ return {
280
+ token: session.accessToken,
281
+ expiresOnTimestamp: 0
282
+ };
283
+ }
284
+ else {
285
+ return null;
286
+ }
282
287
  })
283
288
  };
284
289
  const configuredAzureEnv = (0, configuredAzureEnv_1.getConfiguredAzureEnv)();
285
290
  const endpoint = configuredAzureEnv.resourceManagerEndpointUrl;
291
+ const armSubs = yield Promise.resolve().then(() => require('@azure/arm-resources-subscriptions'));
286
292
  return {
287
293
  client: new armSubs.SubscriptionClient(credential, { endpoint }),
288
294
  credential: credential,
289
295
  authentication: {
290
- getSession: () => session
296
+ getSession: (scopes) => __awaiter(this, void 0, void 0, function* () {
297
+ return yield (0, getSessionFromVSCode_1.getSessionFromVSCode)(scopes, tenantId, { createIfNone: false, silent: true });
298
+ })
291
299
  }
292
300
  };
293
301
  });
@@ -0,0 +1,2 @@
1
+ import type { AzureSubscriptionProvider } from "../AzureSubscriptionProvider";
2
+ export declare function signInToTenant(subscriptionProvider: AzureSubscriptionProvider): Promise<void>;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License. See License.txt in the project root for license information.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
16
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
17
+ var m = o[Symbol.asyncIterator], i;
18
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
19
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
20
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.signInToTenant = void 0;
24
+ const vscode = require("vscode");
25
+ function signInToTenant(subscriptionProvider) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const tenantId = yield pickTenant(subscriptionProvider);
28
+ if (tenantId) {
29
+ yield subscriptionProvider.signIn(tenantId);
30
+ }
31
+ });
32
+ }
33
+ exports.signInToTenant = signInToTenant;
34
+ function pickTenant(subscriptionProvider) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const pick = yield vscode.window.showQuickPick(getPicks(subscriptionProvider), {
37
+ placeHolder: 'Select Directory to Sign In To',
38
+ matchOnDescription: true,
39
+ ignoreFocusOut: true,
40
+ });
41
+ return pick === null || pick === void 0 ? void 0 : pick.tenant.tenantId;
42
+ });
43
+ }
44
+ function getPicks(subscriptionProvider) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const unauthenticatedTenants = yield getUnauthenticatedTenants(subscriptionProvider);
47
+ const picks = unauthenticatedTenants.map(tenant => {
48
+ var _a, _b, _c;
49
+ return ({
50
+ label: (_a = tenant.displayName) !== null && _a !== void 0 ? _a : '',
51
+ description: (_b = tenant.tenantId) !== null && _b !== void 0 ? _b : '',
52
+ detail: (_c = tenant.defaultDomain) !== null && _c !== void 0 ? _c : '',
53
+ tenant,
54
+ });
55
+ });
56
+ return picks;
57
+ });
58
+ }
59
+ function getUnauthenticatedTenants(subscriptionProvider) {
60
+ var _a, e_1, _b, _c;
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const tenants = yield subscriptionProvider.getTenants();
63
+ const unauthenticatedTenants = [];
64
+ try {
65
+ for (var _d = true, tenants_1 = __asyncValues(tenants), tenants_1_1; tenants_1_1 = yield tenants_1.next(), _a = tenants_1_1.done, !_a;) {
66
+ _c = tenants_1_1.value;
67
+ _d = false;
68
+ try {
69
+ const tenant = _c;
70
+ if (!(yield subscriptionProvider.isSignedIn(tenant.tenantId))) {
71
+ unauthenticatedTenants.push(tenant);
72
+ }
73
+ }
74
+ finally {
75
+ _d = true;
76
+ }
77
+ }
78
+ }
79
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
80
+ finally {
81
+ try {
82
+ if (!_d && !_a && (_b = tenants_1.return)) yield _b.call(tenants_1);
83
+ }
84
+ finally { if (e_1) throw e_1.error; }
85
+ }
86
+ return unauthenticatedTenants;
87
+ });
88
+ }
89
+ //# sourceMappingURL=signInToTenant.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@microsoft/vscode-azext-azureauth",
3
3
  "author": "Microsoft Corporation",
4
- "version": "2.0.0",
4
+ "version": "2.1.0",
5
5
  "description": "Azure authentication helpers for Visual Studio Code",
6
6
  "tags": [
7
7
  "azure",