1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.TrustedAuthority = void 0;
|
8 | var tslib_1 = require("tslib");
|
9 | var XHRClient_1 = require("../XHRClient");
|
10 | var Constants_1 = require("../utils/Constants");
|
11 | var UrlUtils_1 = require("../utils/UrlUtils");
|
12 | var TrustedAuthority = (function () {
|
13 | function TrustedAuthority() {
|
14 | }
|
15 | |
16 |
|
17 |
|
18 |
|
19 |
|
20 | TrustedAuthority.setTrustedAuthoritiesFromConfig = function (validateAuthority, knownAuthorities) {
|
21 | if (validateAuthority && !this.getTrustedHostList().length) {
|
22 | knownAuthorities.forEach(function (authority) {
|
23 | TrustedAuthority.TrustedHostList.push(authority.toLowerCase());
|
24 | });
|
25 | }
|
26 | };
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 | TrustedAuthority.getAliases = function (authorityToVerify, telemetryManager, correlationId) {
|
33 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
34 | var client, httpMethod, instanceDiscoveryEndpoint, httpEvent;
|
35 | return tslib_1.__generator(this, function (_a) {
|
36 | client = new XHRClient_1.XhrClient();
|
37 | httpMethod = Constants_1.NetworkRequestType.GET;
|
38 | instanceDiscoveryEndpoint = "" + Constants_1.AAD_INSTANCE_DISCOVERY_ENDPOINT + authorityToVerify + "oauth2/v2.0/authorize";
|
39 | httpEvent = telemetryManager.createAndStartHttpEvent(correlationId, httpMethod, instanceDiscoveryEndpoint, "getAliases");
|
40 | return [2 , client.sendRequestAsync(instanceDiscoveryEndpoint, httpMethod, true)
|
41 | .then(function (response) {
|
42 | httpEvent.httpResponseStatus = response.statusCode;
|
43 | telemetryManager.stopEvent(httpEvent);
|
44 | return response.body["metadata"];
|
45 | })
|
46 | .catch(function (err) {
|
47 | httpEvent.serverErrorCode = err;
|
48 | telemetryManager.stopEvent(httpEvent);
|
49 | throw err;
|
50 | })];
|
51 | });
|
52 | });
|
53 | };
|
54 | |
55 |
|
56 |
|
57 |
|
58 |
|
59 | TrustedAuthority.setTrustedAuthoritiesFromNetwork = function (authorityToVerify, telemetryManager, correlationId) {
|
60 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
61 | var metadata, host;
|
62 | return tslib_1.__generator(this, function (_a) {
|
63 | switch (_a.label) {
|
64 | case 0: return [4 , this.getAliases(authorityToVerify, telemetryManager, correlationId)];
|
65 | case 1:
|
66 | metadata = _a.sent();
|
67 | metadata.forEach(function (entry) {
|
68 | var authorities = entry["aliases"];
|
69 | authorities.forEach(function (authority) {
|
70 | TrustedAuthority.TrustedHostList.push(authority.toLowerCase());
|
71 | });
|
72 | });
|
73 | host = UrlUtils_1.UrlUtils.GetUrlComponents(authorityToVerify).HostNameAndPort;
|
74 | if (TrustedAuthority.getTrustedHostList().length && !TrustedAuthority.IsInTrustedHostList(host)) {
|
75 |
|
76 | TrustedAuthority.TrustedHostList.push(host.toLowerCase());
|
77 | }
|
78 | return [2 ];
|
79 | }
|
80 | });
|
81 | });
|
82 | };
|
83 | TrustedAuthority.getTrustedHostList = function () {
|
84 | return this.TrustedHostList;
|
85 | };
|
86 | |
87 |
|
88 |
|
89 |
|
90 | TrustedAuthority.IsInTrustedHostList = function (host) {
|
91 | return this.TrustedHostList.indexOf(host.toLowerCase()) > -1;
|
92 | };
|
93 | TrustedAuthority.TrustedHostList = [];
|
94 | return TrustedAuthority;
|
95 | }());
|
96 | exports.TrustedAuthority = TrustedAuthority;
|
97 |
|
\ | No newline at end of file |