msal
Version:
Microsoft Authentication Library for js
55 lines • 2.36 kB
JavaScript
;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @hidden
*/
var AadAuthority_1 = require("./AadAuthority");
var B2cAuthority_1 = require("./B2cAuthority");
var Authority_1 = require("./Authority");
var ClientConfigurationError_1 = require("./error/ClientConfigurationError");
var UrlUtils_1 = require("./utils/UrlUtils");
var StringUtils_1 = require("./utils/StringUtils");
var AuthorityFactory = /** @class */ (function () {
function AuthorityFactory() {
}
/**
* Parse the url and determine the type of authority
*/
AuthorityFactory.DetectAuthorityFromUrl = function (authorityUrl) {
authorityUrl = UrlUtils_1.UrlUtils.CanonicalizeUri(authorityUrl);
var components = UrlUtils_1.UrlUtils.GetUrlComponents(authorityUrl);
var pathSegments = components.PathSegments;
switch (pathSegments[0]) {
case "tfp":
return Authority_1.AuthorityType.B2C;
case "adfs":
return Authority_1.AuthorityType.Adfs;
default:
return Authority_1.AuthorityType.Aad;
}
};
/**
* 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) {
if (StringUtils_1.StringUtils.isEmpty(authorityUrl)) {
return null;
}
var type = AuthorityFactory.DetectAuthorityFromUrl(authorityUrl);
// Depending on above detection, create the right type.
switch (type) {
case Authority_1.AuthorityType.B2C:
return new B2cAuthority_1.B2cAuthority(authorityUrl, validateAuthority);
case Authority_1.AuthorityType.Aad:
return new AadAuthority_1.AadAuthority(authorityUrl, validateAuthority);
default:
throw ClientConfigurationError_1.ClientConfigurationErrorMessage.invalidAuthorityType;
}
};
return AuthorityFactory;
}());
exports.AuthorityFactory = AuthorityFactory;
//# sourceMappingURL=AuthorityFactory.js.map