msal-iframe-ok
Version:
Fork to allow silent renewal in iFrame of Microsoft Authentication Library for js
52 lines • 1.99 kB
JavaScript
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
/**
* @hidden
*/
import { Utils } from "./Utils";
import { AadAuthority } from "./AadAuthority";
import { B2cAuthority } from "./B2cAuthority";
import { AuthorityType } from "./Authority";
import { ClientConfigurationErrorMessage } from "./error/ClientConfigurationError";
var AuthorityFactory = /** @class */ (function () {
function AuthorityFactory() {
}
/**
* Parse the url and determine the type of authority
*/
AuthorityFactory.DetectAuthorityFromUrl = function (authorityUrl) {
authorityUrl = Utils.CanonicalizeUri(authorityUrl);
var components = Utils.GetUrlComponents(authorityUrl);
var pathSegments = components.PathSegments;
switch (pathSegments[0]) {
case "tfp":
return AuthorityType.B2C;
case "adfs":
return AuthorityType.Adfs;
default:
return 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 (Utils.isEmpty(authorityUrl)) {
return null;
}
var type = AuthorityFactory.DetectAuthorityFromUrl(authorityUrl);
// Depending on above detection, create the right type.
switch (type) {
case AuthorityType.B2C:
return new B2cAuthority(authorityUrl, validateAuthority);
case AuthorityType.Aad:
return new AadAuthority(authorityUrl, validateAuthority);
default:
throw ClientConfigurationErrorMessage.invalidAuthorityType;
}
};
return AuthorityFactory;
}());
export { AuthorityFactory };
//# sourceMappingURL=AuthorityFactory.js.map