msal-iframe-ok
Version:
Fork to allow silent renewal in iFrame of Microsoft Authentication Library for js
1,351 lines (1,339 loc) • 715 kB
JavaScript
/*! msal-iframe-ok v1.0.2 2019-07-09 */
'use strict';
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define("Msal", [], factory);
else if(typeof exports === 'object')
exports["Msal"] = factory();
else
root["Msal"] = factory();
})(window, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 17);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = __webpack_require__(1);
var Constants_1 = __webpack_require__(2);
var ClientAuthError_1 = __webpack_require__(4);
var Constants_2 = __webpack_require__(2);
var js_base64_1 = __webpack_require__(20);
/**
* @hidden
*/
var Utils = /** @class */ (function () {
function Utils() {
}
//#region General Util
/**
* Utils function to compare two Account objects - used to check if the same user account is logged in
*
* @param a1: Account object
* @param a2: Account object
*/
Utils.compareAccounts = function (a1, a2) {
if (!a1 || !a2) {
return false;
}
if (a1.homeAccountIdentifier && a2.homeAccountIdentifier) {
if (a1.homeAccountIdentifier === a2.homeAccountIdentifier) {
return true;
}
}
return false;
};
/**
* Decimal to Hex
*
* @param num
*/
Utils.decimalToHex = function (num) {
var hex = num.toString(16);
while (hex.length < 2) {
hex = "0" + hex;
}
return hex;
};
/**
* MSAL JS Library Version
*/
Utils.getLibraryVersion = function () {
return Constants_2.Library.version;
};
/**
* Creates a new random GUID - used to populate state?
* @returns string (GUID)
*/
Utils.createNewGuid = function () {
// RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or
// pseudo-random numbers.
// The algorithm is as follows:
// Set the two most significant bits (bits 6 and 7) of the
// clock_seq_hi_and_reserved to zero and one, respectively.
// Set the four most significant bits (bits 12 through 15) of the
// time_hi_and_version field to the 4-bit version number from
// Section 4.1.3. Version4
// Set all the other bits to randomly (or pseudo-randomly) chosen
// values.
// UUID = time-low "-" time-mid "-"time-high-and-version "-"clock-seq-reserved and low(2hexOctet)"-" node
// time-low = 4hexOctet
// time-mid = 2hexOctet
// time-high-and-version = 2hexOctet
// clock-seq-and-reserved = hexOctet:
// clock-seq-low = hexOctet
// node = 6hexOctet
// Format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
// y could be 1000, 1001, 1010, 1011 since most significant two bits needs to be 10
// y values are 8, 9, A, B
var cryptoObj = window.crypto; // for IE 11
if (cryptoObj && cryptoObj.getRandomValues) {
var buffer = new Uint8Array(16);
cryptoObj.getRandomValues(buffer);
//buffer[6] and buffer[7] represents the time_hi_and_version field. We will set the four most significant bits (4 through 7) of buffer[6] to represent decimal number 4 (UUID version number).
buffer[6] |= 0x40; //buffer[6] | 01000000 will set the 6 bit to 1.
buffer[6] &= 0x4f; //buffer[6] & 01001111 will set the 4, 5, and 7 bit to 0 such that bits 4-7 == 0100 = "4".
//buffer[8] represents the clock_seq_hi_and_reserved field. We will set the two most significant bits (6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively.
buffer[8] |= 0x80; //buffer[8] | 10000000 will set the 7 bit to 1.
buffer[8] &= 0xbf; //buffer[8] & 10111111 will set the 6 bit to 0.
return Utils.decimalToHex(buffer[0]) + Utils.decimalToHex(buffer[1])
+ Utils.decimalToHex(buffer[2]) + Utils.decimalToHex(buffer[3])
+ "-" + Utils.decimalToHex(buffer[4]) + Utils.decimalToHex(buffer[5])
+ "-" + Utils.decimalToHex(buffer[6]) + Utils.decimalToHex(buffer[7])
+ "-" + Utils.decimalToHex(buffer[8]) + Utils.decimalToHex(buffer[9])
+ "-" + Utils.decimalToHex(buffer[10]) + Utils.decimalToHex(buffer[11])
+ Utils.decimalToHex(buffer[12]) + Utils.decimalToHex(buffer[13])
+ Utils.decimalToHex(buffer[14]) + Utils.decimalToHex(buffer[15]);
}
else {
var guidHolder = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
var hex = "0123456789abcdef";
var r = 0;
var guidResponse = "";
for (var i = 0; i < 36; i++) {
if (guidHolder[i] !== "-" && guidHolder[i] !== "4") {
// each x and y needs to be random
r = Math.random() * 16 | 0;
}
if (guidHolder[i] === "x") {
guidResponse += hex[r];
}
else if (guidHolder[i] === "y") {
// clock-seq-and-reserved first hex is filtered and remaining hex values are random
r &= 0x3; // bit and with 0011 to set pos 2 to zero ?0??
r |= 0x8; // set pos 3 to 1 as 1???
guidResponse += hex[r];
}
else {
guidResponse += guidHolder[i];
}
}
return guidResponse;
}
};
//#endregion
//#region Time
/**
* Returns time in seconds for expiration based on string value passed in.
*
* @param expires
*/
Utils.expiresIn = function (expires) {
// if AAD did not send "expires_in" property, use default expiration of 3599 seconds, for some reason AAD sends 3599 as "expires_in" value instead of 3600
if (!expires) {
expires = "3599";
}
return this.now() + parseInt(expires, 10);
};
/**
* return the current time in Unix time. Date.getTime() returns in milliseconds.
*/
Utils.now = function () {
return Math.round(new Date().getTime() / 1000.0);
};
//#endregion
//#region String Ops
/**
* Check if a string is empty
*
* @param str
*/
Utils.isEmpty = function (str) {
return (typeof str === "undefined" || !str || 0 === str.length);
};
//#endregion
//#region Token Processing (Extract to TokenProcessing.ts)
/**
* decode a JWT
*
* @param jwtToken
*/
Utils.decodeJwt = function (jwtToken) {
if (this.isEmpty(jwtToken)) {
return null;
}
var idTokenPartsRegex = /^([^\.\s]*)\.([^\.\s]+)\.([^\.\s]*)$/;
var matches = idTokenPartsRegex.exec(jwtToken);
if (!matches || matches.length < 4) {
//this._requestContext.logger.warn("The returned id_token is not parseable.");
return null;
}
var crackedToken = {
header: matches[1],
JWSPayload: matches[2],
JWSSig: matches[3]
};
return crackedToken;
};
/**
* Extract IdToken by decoding the RAWIdToken
*
* @param encodedIdToken
*/
Utils.extractIdToken = function (encodedIdToken) {
// id token will be decoded to get the username
var decodedToken = this.decodeJwt(encodedIdToken);
if (!decodedToken) {
return null;
}
try {
var base64IdToken = decodedToken.JWSPayload;
var base64Decoded = this.base64DecodeStringUrlSafe(base64IdToken);
if (!base64Decoded) {
//this._requestContext.logger.info("The returned id_token could not be base64 url safe decoded.");
return null;
}
// ECMA script has JSON built-in support
return JSON.parse(base64Decoded);
}
catch (err) {
//this._requestContext.logger.error("The returned id_token could not be decoded" + err);
}
return null;
};
//#endregion
//#region Encode and Decode
/**
* encoding string to base64 - platform specific check
*
* @param input
*/
Utils.base64EncodeStringUrlSafe = function (input) {
// html5 should support atob function for decoding
return js_base64_1.Base64.encode(input);
};
/**
* decoding base64 token - platform specific check
*
* @param base64IdToken
*/
Utils.base64DecodeStringUrlSafe = function (base64IdToken) {
// html5 should support atob function for decoding
base64IdToken = base64IdToken.replace(/-/g, "+").replace(/_/g, "/");
return decodeURIComponent(encodeURIComponent(js_base64_1.Base64.decode(base64IdToken))); // jshint ignore:line
};
/**
* base64 encode a string
*
* @param input
*/
// TODO: Rename to specify type of encoding
Utils.encode = function (input) {
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = this.utf8Encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
}
else if (isNaN(chr3)) {
enc4 = 64;
}
output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);
}
return output.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
};
/**
* utf8 encode a string
*
* @param input
*/
Utils.utf8Encode = function (input) {
input = input.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = 0; n < input.length; n++) {
var c = input.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
};
/**
* decode a base64 token string
*
* @param base64IdToken
*/
// TODO: Rename to specify type of encoding
Utils.decode = function (base64IdToken) {
var codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
base64IdToken = String(base64IdToken).replace(/=+$/, "");
var length = base64IdToken.length;
if (length % 4 === 1) {
throw ClientAuthError_1.ClientAuthError.createTokenEncodingError(base64IdToken);
}
var h1, h2, h3, h4, bits, c1, c2, c3, decoded = "";
for (var i = 0; i < length; i += 4) {
//Every 4 base64 encoded character will be converted to 3 byte string, which is 24 bits
// then 6 bits per base64 encoded character
h1 = codes.indexOf(base64IdToken.charAt(i));
h2 = codes.indexOf(base64IdToken.charAt(i + 1));
h3 = codes.indexOf(base64IdToken.charAt(i + 2));
h4 = codes.indexOf(base64IdToken.charAt(i + 3));
// For padding, if last two are "="
if (i + 2 === length - 1) {
bits = h1 << 18 | h2 << 12 | h3 << 6;
c1 = bits >> 16 & 255;
c2 = bits >> 8 & 255;
decoded += String.fromCharCode(c1, c2);
break;
}
// if last one is "="
else if (i + 1 === length - 1) {
bits = h1 << 18 | h2 << 12;
c1 = bits >> 16 & 255;
decoded += String.fromCharCode(c1);
break;
}
bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
// then convert to 3 byte chars
c1 = bits >> 16 & 255;
c2 = bits >> 8 & 255;
c3 = bits & 255;
decoded += String.fromCharCode(c1, c2, c3);
}
return decoded;
};
/**
* deserialize a string
*
* @param query
*/
Utils.deserialize = function (query) {
var match; // Regex for replacing addition symbol with a space
var pl = /\+/g;
var search = /([^&=]+)=([^&]*)/g;
var decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); };
var obj = {};
match = search.exec(query);
while (match) {
obj[decode(match[1])] = decode(match[2]);
match = search.exec(query);
}
return obj;
};
//#endregion
//#region Scopes (extract to Scopes.ts)
/**
* Check if there are dup scopes in a given request
*
* @param cachedScopes
* @param scopes
*/
// TODO: Rename this, intersecting scopes isn't a great name for duplicate checker
Utils.isIntersectingScopes = function (cachedScopes, scopes) {
cachedScopes = this.convertToLowerCase(cachedScopes);
for (var i = 0; i < scopes.length; i++) {
if (cachedScopes.indexOf(scopes[i].toLowerCase()) > -1) {
return true;
}
}
return false;
};
/**
* Check if a given scope is present in the request
*
* @param cachedScopes
* @param scopes
*/
Utils.containsScope = function (cachedScopes, scopes) {
cachedScopes = this.convertToLowerCase(cachedScopes);
return scopes.every(function (value) { return cachedScopes.indexOf(value.toString().toLowerCase()) >= 0; });
};
/**
* toLower
*
* @param scopes
*/
// TODO: Rename this, too generic name for a function that only deals with scopes
Utils.convertToLowerCase = function (scopes) {
return scopes.map(function (scope) { return scope.toLowerCase(); });
};
/**
* remove one element from a scope array
*
* @param scopes
* @param scope
*/
// TODO: Rename this, too generic name for a function that only deals with scopes
Utils.removeElement = function (scopes, scope) {
return scopes.filter(function (value) { return value !== scope; });
};
//#endregion
//#region URL Processing (Extract to UrlProcessing.ts?)
Utils.getDefaultRedirectUri = function () {
return window.location.href.split("?")[0].split("#")[0];
};
/**
* Given a url like https://a:b/common/d?e=f#g, and a tenantId, returns https://a:b/tenantId/d
* @param href The url
* @param tenantId The tenant id to replace
*/
Utils.replaceTenantPath = function (url, tenantId) {
url = url.toLowerCase();
var urlObject = this.GetUrlComponents(url);
var pathArray = urlObject.PathSegments;
if (tenantId && (pathArray.length !== 0 && (pathArray[0] === Constants_1.Constants.common || pathArray[0] === Constants_1.SSOTypes.ORGANIZATIONS))) {
pathArray[0] = tenantId;
}
return this.constructAuthorityUriFromObject(urlObject, pathArray);
};
Utils.constructAuthorityUriFromObject = function (urlObject, pathArray) {
return this.CanonicalizeUri(urlObject.Protocol + "//" + urlObject.HostNameAndPort + "/" + pathArray.join("/"));
};
/**
* Parses out the components from a url string.
* @returns An object with the various components. Please cache this value insted of calling this multiple times on the same url.
*/
Utils.GetUrlComponents = function (url) {
if (!url) {
throw "Url required";
}
// https://gist.github.com/curtisz/11139b2cfcaef4a261e0
var regEx = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?");
var match = url.match(regEx);
if (!match || match.length < 6) {
throw "Valid url required";
}
var urlComponents = {
Protocol: match[1],
HostNameAndPort: match[4],
AbsolutePath: match[5]
};
var pathSegments = urlComponents.AbsolutePath.split("/");
pathSegments = pathSegments.filter(function (val) { return val && val.length > 0; }); // remove empty elements
urlComponents.PathSegments = pathSegments;
return urlComponents;
};
/**
* Given a url or path, append a trailing slash if one doesnt exist
*
* @param url
*/
Utils.CanonicalizeUri = function (url) {
if (url) {
url = url.toLowerCase();
}
if (url && !Utils.endsWith(url, "/")) {
url += "/";
}
return url;
};
/**
* Checks to see if the url ends with the suffix
* Required because we are compiling for es5 instead of es6
* @param url
* @param str
*/
// TODO: Rename this, not clear what it is supposed to do
Utils.endsWith = function (url, suffix) {
if (!url || !suffix) {
return false;
}
return url.indexOf(suffix, url.length - suffix.length) !== -1;
};
/**
* Utils function to remove the login_hint and domain_hint from the i/p extraQueryParameters
* @param url
* @param name
*/
Utils.urlRemoveQueryStringParameter = function (url, name) {
if (this.isEmpty(url)) {
return url;
}
var regex = new RegExp("(\\&" + name + "=)[^\&]+");
url = url.replace(regex, "");
// name=value&
regex = new RegExp("(" + name + "=)[^\&]+&");
url = url.replace(regex, "");
// name=value
regex = new RegExp("(" + name + "=)[^\&]+");
url = url.replace(regex, "");
return url;
};
//#endregion
//#region ExtraQueryParameters Processing (Extract?)
/**
* Constructs extraQueryParameters to be sent to the server for the AuthenticationParameters set by the developer
* in any login() or acquireToken() calls
* @param idTokenObject
* @param extraQueryParameters
* @param sid
* @param loginHint
*/
//TODO: check how this behaves when domain_hint only is sent in extraparameters and idToken has no upn.
Utils.constructUnifiedCacheQueryParameter = function (request, idTokenObject) {
// preference order: account > sid > login_hint
var ssoType;
var ssoData;
var serverReqParam = {};
// if account info is passed, account.sid > account.login_hint
if (request) {
if (request.account) {
var account = request.account;
if (account.sid) {
ssoType = Constants_1.SSOTypes.SID;
ssoData = account.sid;
}
else if (account.userName) {
ssoType = Constants_1.SSOTypes.LOGIN_HINT;
ssoData = account.userName;
}
}
// sid from request
else if (request.sid) {
ssoType = Constants_1.SSOTypes.SID;
ssoData = request.sid;
}
// loginHint from request
else if (request.loginHint) {
ssoType = Constants_1.SSOTypes.LOGIN_HINT;
ssoData = request.loginHint;
}
}
// adalIdToken retrieved from cache
else if (idTokenObject) {
if (idTokenObject.hasOwnProperty(Constants_1.Constants.upn)) {
ssoType = Constants_1.SSOTypes.ID_TOKEN;
ssoData = idTokenObject.upn;
}
else {
ssoType = Constants_1.SSOTypes.ORGANIZATIONS;
ssoData = null;
}
}
serverReqParam = this.addSSOParameter(ssoType, ssoData);
// add the HomeAccountIdentifier info/ domain_hint
if (request && request.account && request.account.homeAccountIdentifier) {
serverReqParam = this.addSSOParameter(Constants_1.SSOTypes.HOMEACCOUNT_ID, request.account.homeAccountIdentifier, serverReqParam);
}
return serverReqParam;
};
/**
* Add SID to extraQueryParameters
* @param sid
*/
Utils.addSSOParameter = function (ssoType, ssoData, ssoParam) {
if (!ssoParam) {
ssoParam = {};
}
if (!ssoData) {
return ssoParam;
}
switch (ssoType) {
case Constants_1.SSOTypes.SID: {
ssoParam[Constants_1.SSOTypes.SID] = ssoData;
break;
}
case Constants_1.SSOTypes.ID_TOKEN: {
ssoParam[Constants_1.SSOTypes.LOGIN_HINT] = ssoData;
ssoParam[Constants_1.SSOTypes.DOMAIN_HINT] = Constants_1.SSOTypes.ORGANIZATIONS;
break;
}
case Constants_1.SSOTypes.LOGIN_HINT: {
ssoParam[Constants_1.SSOTypes.LOGIN_HINT] = ssoData;
break;
}
case Constants_1.SSOTypes.ORGANIZATIONS: {
ssoParam[Constants_1.SSOTypes.DOMAIN_HINT] = Constants_1.SSOTypes.ORGANIZATIONS;
break;
}
case Constants_1.SSOTypes.CONSUMERS: {
ssoParam[Constants_1.SSOTypes.DOMAIN_HINT] = Constants_1.SSOTypes.CONSUMERS;
break;
}
case Constants_1.SSOTypes.HOMEACCOUNT_ID: {
var homeAccountId = ssoData.split(".");
var uid = Utils.base64DecodeStringUrlSafe(homeAccountId[0]);
var utid = Utils.base64DecodeStringUrlSafe(homeAccountId[1]);
// TODO: domain_req and login_req are not needed according to eSTS team
ssoParam[Constants_1.SSOTypes.LOGIN_REQ] = uid;
ssoParam[Constants_1.SSOTypes.DOMAIN_REQ] = utid;
if (utid === Constants_1.Constants.consumersUtid) {
ssoParam[Constants_1.SSOTypes.DOMAIN_HINT] = Constants_1.SSOTypes.CONSUMERS;
}
else {
ssoParam[Constants_1.SSOTypes.DOMAIN_HINT] = Constants_1.SSOTypes.ORGANIZATIONS;
}
break;
}
case Constants_1.SSOTypes.LOGIN_REQ: {
ssoParam[Constants_1.SSOTypes.LOGIN_REQ] = ssoData;
break;
}
case Constants_1.SSOTypes.DOMAIN_REQ: {
ssoParam[Constants_1.SSOTypes.DOMAIN_REQ] = ssoData;
break;
}
}
return ssoParam;
};
/**
* Utility to generate a QueryParameterString from a Key-Value mapping of extraQueryParameters passed
* @param extraQueryParameters
*/
Utils.generateQueryParametersString = function (queryParameters) {
var paramsString = null;
if (queryParameters) {
Object.keys(queryParameters).forEach(function (key) {
if (paramsString == null) {
paramsString = key + "=" + encodeURIComponent(queryParameters[key]);
}
else {
paramsString += "&" + key + "=" + encodeURIComponent(queryParameters[key]);
}
});
}
return paramsString;
};
/**
* Check to see if there are SSO params set in the Request
* @param request
*/
Utils.isSSOParam = function (request) {
return request && (request.account || request.sid || request.loginHint);
};
//#endregion
//#region Response Helpers
Utils.setResponseIdToken = function (originalResponse, idToken) {
var response = tslib_1.__assign({}, originalResponse);
response.idToken = idToken;
if (response.idToken.objectId) {
response.uniqueId = response.idToken.objectId;
}
else {
response.uniqueId = response.idToken.subject;
}
response.tenantId = response.idToken.tenantId;
return response;
};
return Utils;
}());
exports.Utils = Utils;
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
Object.defineProperty(exports, "__esModule", { value: true });
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
exports.__extends = __extends;
exports.__assign = function () {
exports.__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return exports.__assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++)
if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
}
exports.__rest = __rest;
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
exports.__decorate = __decorate;
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
exports.__param = __param;
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
exports.__metadata = __metadata;
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
exports.__awaiter = __awaiter;
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
exports.__generator = __generator;
function __exportStar(m, exports) {
for (var p in m)
if (!exports.hasOwnProperty(p))
exports[p] = m[p];
}
exports.__exportStar = __exportStar;
function __values(o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m)
return m.call(o);
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
}
exports.__values = __values;
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
exports.__read = __read;
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
exports.__spread = __spread;
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
exports.__await = __await;
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
exports.__asyncGenerator = __asyncGenerator;
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
exports.__asyncDelegator = __asyncDelegator;
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
exports.__asyncValues = __asyncValues;
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
exports.__makeTemplateObject = __makeTemplateObject;
;
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (Object.hasOwnProperty.call(mod, k))
result[k] = mod[k];
result.default = mod;
return result;
}
exports.__importStar = __importStar;
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
exports.__importDefault = __importDefault;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
/**
* @hidden
*/
var Constants = /** @class */ (function () {
function Constants() {
}
Object.defineProperty(Constants, "errorDescription", {
get: function () { return "error_description"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "error", {
get: function () { return "error"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "scope", {
get: function () { return "scope"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "clientInfo", {
get: function () { return "client_info"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "clientId", {
get: function () { return "clientId"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "idToken", {
get: function () { return "id_token"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "adalIdToken", {
get: function () { return "adal.idtoken"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "accessToken", {
get: function () { return "access_token"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "expiresIn", {
get: function () { return "expires_in"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "sessionState", {
get: function () { return "session_state"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "claims", {
get: function () { return "claims"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "msalClientInfo", {
get: function () { return "msal.client.info"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "msalError", {
get: function () { return "msal.error"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "msalErrorDescription", {
get: function () { return "msal.error.description"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "msalSessionState", {
get: function () { return "msal.session.state"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "tokenKeys", {
get: function () { return "msal.token.keys"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "accessTokenKey", {
get: function () { return "msal.access.token.key"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "expirationKey", {
get: function () { return "msal.expiration.key"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "stateLogin", {
get: function () { return "msal.state.login"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "stateAcquireToken", {
get: function () { return "msal.state.acquireToken"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "stateRenew", {
get: function () { return "msal.state.renew"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "nonceIdToken", {
get: function () { return "msal.nonce.idtoken"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "userName", {
get: function () { return "msal.username"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "idTokenKey", {
get: function () { return "msal.idtoken"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "loginRequest", {
get: function () { return "msal.login.request"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "loginError", {
get: function () { return "msal.login.error"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "renewStatus", {
get: function () { return "msal.token.renew.status"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "urlHash", {
get: function () { return "msal.urlHash"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "angularLoginRequest", {
get: function () { return "msal.angular.login.request"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "msal", {
get: function () { return "msal"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "no_account", {
get: function () { return "NO_ACCOUNT"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "consumersUtid", {
get: function () { return "9188040d-6c67-4c5b-b112-36a304b66dad"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "upn", {
get: function () { return "upn"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "prompt_select_account", {
get: function () { return "&prompt=select_account"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "prompt_none", {
get: function () { return "&prompt=none"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "prompt", {
get: function () { return "prompt"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "response_mode_fragment", {
get: function () { return "&response_mode=fragment"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "resourceDelimiter", {
get: function () { return "|"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "tokenRenewStatusCancelled", {
get: function () { return "Canceled"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "tokenRenewStatusCompleted", {
get: function () { return "Completed"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "tokenRenewStatusInProgress", {
get: function () { return "In Progress"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "popUpWidth", {
get: function () { return this._popUpWidth; },
set: function (width) {
this._popUpWidth = width;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "popUpHeight", {
get: function () { return this._popUpHeight; },
set: function (height) {
this._popUpHeight = height;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "login", {
get: function () { return "LOGIN"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "renewToken", {
get: function () { return "RENEW_TOKEN"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "unknown", {
get: function () { return "UNKNOWN"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "homeAccountIdentifier", {
get: function () { return "homeAccountIdentifier"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "common", {
get: function () { return "common"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "openidScope", {
get: function () { return "openid"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "profileScope", {
get: function () { return "profile"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "cacheLocationLocal", {
get: function () { return "localStorage"; },
enumerable: true,
configurable: true
});
Object.defineProperty(Constants, "cacheLocationSession", {
get: function () { return "sessionStorage"; },
enumerable: true,
configurable: true
});
Constants._popUpWidth = 483;
Constants._popUpHeight = 600;
return Constants;
}());
exports.Constants = Constants;
/**
* @hidden
*/
exports.CacheKeys = {
AUTHORITY: "msal.authority",
ACQUIRE_TOKEN_ACCOUNT: "msal.acquireTokenAccount"
};
/**
* @hidden
*/
exports.SSOTypes = {
ACCOUNT: "account",
SID: "sid",
LOGIN_HINT: "login_hint",
ID_TOKEN: "id_token",
DOMAIN_HINT: "domain_hint",
ORGANIZATIONS: "organizations",
CONSUMERS: "consumers",
ACCOUNT_ID: "accountIdentifier",
HOMEACCOUNT_ID: "homeAccountIdentifier",
LOGIN_REQ: "login_req",
DOMAIN_REQ: "domain_req"
};
/**
* we considered making this "enum" in the request instead of string, however it looks like the allowed list of
* prompt values kept changing over past couple of years. There are some undocumented prompt values for some
* internal partners too, hence the choice of generic "string" type instead of the "enum"
* @hidden
*/
exports.PromptState = {
LOGIN: "login",
SELECT_ACCOUNT: "select_account",
CONSENT: "consent",
NONE: "none",
}