1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.AuthorityFactory = void 0;
|
8 | var tslib_1 = require("tslib");
|
9 |
|
10 |
|
11 |
|
12 | var Authority_1 = require("./Authority");
|
13 | var StringUtils_1 = require("../utils/StringUtils");
|
14 | var ClientConfigurationError_1 = require("../error/ClientConfigurationError");
|
15 | var AuthorityFactory = (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 , authorityInstance.resolveEndpointsAsync(telemetryManager, correlationId)];
|
24 | case 1:
|
25 | metadata = _a.sent();
|
26 | this.metadataMap.set(authorityInstance.CanonicalAuthority, metadata);
|
27 | return [2 , 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 |
|
55 |
|
56 |
|
57 | AuthorityFactory.CreateInstance = function (authorityUrl, validateAuthority, authorityMetadata) {
|
58 | if (StringUtils_1.StringUtils.isEmpty(authorityUrl)) {
|
59 | return null;
|
60 | }
|
61 | if (authorityMetadata) {
|
62 |
|
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 | }());
|
70 | exports.AuthorityFactory = AuthorityFactory;
|
71 |
|
\ | No newline at end of file |