UNPKG

3.2 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright (c) Microsoft Corporation. All rights reserved.
4 * Licensed under the MIT License.
5 */
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.AuthorityFactory = void 0;
8var tslib_1 = require("tslib");
9/**
10 * @hidden
11 */
12var Authority_1 = require("./Authority");
13var StringUtils_1 = require("../utils/StringUtils");
14var ClientConfigurationError_1 = require("../error/ClientConfigurationError");
15var AuthorityFactory = /** @class */ (function () {
16 function AuthorityFactory() {
17 }
18 AuthorityFactory.saveMetadataFromNetwork = function (authorityInstance, telemetryManager, correlationId) {
19 return tslib_1.__awaiter(this, void 0, void 0, function () {
20 var metadata;
21 return tslib_1.__generator(this, function (_a) {
22 switch (_a.label) {
23 case 0: return [4 /*yield*/, authorityInstance.resolveEndpointsAsync(telemetryManager, correlationId)];
24 case 1:
25 metadata = _a.sent();
26 this.metadataMap.set(authorityInstance.CanonicalAuthority, metadata);
27 return [2 /*return*/, metadata];
28 }
29 });
30 });
31 };
32 AuthorityFactory.getMetadata = function (authorityUrl) {
33 return this.metadataMap.get(authorityUrl);
34 };
35 AuthorityFactory.saveMetadataFromConfig = function (authorityUrl, authorityMetadataJson) {
36 try {
37 if (authorityMetadataJson) {
38 var parsedMetadata = JSON.parse(authorityMetadataJson);
39 if (!parsedMetadata.authorization_endpoint || !parsedMetadata.end_session_endpoint || !parsedMetadata.issuer) {
40 throw ClientConfigurationError_1.ClientConfigurationError.createInvalidAuthorityMetadataError();
41 }
42 this.metadataMap.set(authorityUrl, {
43 AuthorizationEndpoint: parsedMetadata.authorization_endpoint,
44 EndSessionEndpoint: parsedMetadata.end_session_endpoint,
45 Issuer: parsedMetadata.issuer
46 });
47 }
48 }
49 catch (e) {
50 throw ClientConfigurationError_1.ClientConfigurationError.createInvalidAuthorityMetadataError();
51 }
52 };
53 /**
54 * Create an authority object of the correct type based on the url
55 * Performs basic authority validation - checks to see if the authority is of a valid type (eg aad, b2c)
56 */
57 AuthorityFactory.CreateInstance = function (authorityUrl, validateAuthority, authorityMetadata) {
58 if (StringUtils_1.StringUtils.isEmpty(authorityUrl)) {
59 return null;
60 }
61 if (authorityMetadata) {
62 // todo: log statements
63 this.saveMetadataFromConfig(authorityUrl, authorityMetadata);
64 }
65 return new Authority_1.Authority(authorityUrl, validateAuthority, this.metadataMap.get(authorityUrl));
66 };
67 AuthorityFactory.metadataMap = new Map();
68 return AuthorityFactory;
69}());
70exports.AuthorityFactory = AuthorityFactory;
71//# sourceMappingURL=AuthorityFactory.js.map
\No newline at end of file