msal
Version:
Microsoft Authentication Library for js
68 lines • 2.99 kB
JavaScript
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { __awaiter, __generator } from "tslib";
/**
* @hidden
*/
import { Authority } from "./Authority";
import { StringUtils } from "../utils/StringUtils";
import { ClientConfigurationError } from "../error/ClientConfigurationError";
var AuthorityFactory = /** @class */ (function () {
function AuthorityFactory() {
}
AuthorityFactory.saveMetadataFromNetwork = function (authorityInstance, telemetryManager, correlationId) {
return __awaiter(this, void 0, void 0, function () {
var metadata;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, authorityInstance.resolveEndpointsAsync(telemetryManager, correlationId)];
case 1:
metadata = _a.sent();
this.metadataMap.set(authorityInstance.CanonicalAuthority, metadata);
return [2 /*return*/, metadata];
}
});
});
};
AuthorityFactory.getMetadata = function (authorityUrl) {
return this.metadataMap.get(authorityUrl);
};
AuthorityFactory.saveMetadataFromConfig = function (authorityUrl, authorityMetadataJson) {
try {
if (authorityMetadataJson) {
var parsedMetadata = JSON.parse(authorityMetadataJson);
if (!parsedMetadata.authorization_endpoint || !parsedMetadata.end_session_endpoint || !parsedMetadata.issuer) {
throw ClientConfigurationError.createInvalidAuthorityMetadataError();
}
this.metadataMap.set(authorityUrl, {
AuthorizationEndpoint: parsedMetadata.authorization_endpoint,
EndSessionEndpoint: parsedMetadata.end_session_endpoint,
Issuer: parsedMetadata.issuer
});
}
}
catch (e) {
throw ClientConfigurationError.createInvalidAuthorityMetadataError();
}
};
/**
* Create an authority object of the correct type based on the url
* Performs basic authority validation - checks to see if the authority is of a valid type (eg aad, b2c)
*/
AuthorityFactory.CreateInstance = function (authorityUrl, validateAuthority, authorityMetadata) {
if (StringUtils.isEmpty(authorityUrl)) {
return null;
}
if (authorityMetadata) {
// todo: log statements
this.saveMetadataFromConfig(authorityUrl, authorityMetadata);
}
return new Authority(authorityUrl, validateAuthority, this.metadataMap.get(authorityUrl));
};
AuthorityFactory.metadataMap = new Map();
return AuthorityFactory;
}());
export { AuthorityFactory };
//# sourceMappingURL=AuthorityFactory.js.map