msal
Version:
Microsoft Authentication Library for js
78 lines • 3.04 kB
JavaScript
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Account = void 0;
var CryptoUtils_1 = require("./utils/CryptoUtils");
var StringUtils_1 = require("./utils/StringUtils");
/**
* accountIdentifier combination of idToken.uid and idToken.utid
* homeAccountIdentifier combination of clientInfo.uid and clientInfo.utid
* userName idToken.preferred_username
* name idToken.name
* idToken idToken
* sid idToken.sid - session identifier
* environment idtoken.issuer (the authority that issues the token)
*/
var Account = /** @class */ (function () {
/**
* Creates an Account Object
* @praram accountIdentifier
* @param homeAccountIdentifier
* @param userName
* @param name
* @param idToken
* @param sid
* @param environment
*/
function Account(accountIdentifier, homeAccountIdentifier, userName, name, idTokenClaims, sid, environment) {
this.accountIdentifier = accountIdentifier;
this.homeAccountIdentifier = homeAccountIdentifier;
this.userName = userName;
this.name = name;
// will be deprecated soon
this.idToken = idTokenClaims;
this.idTokenClaims = idTokenClaims;
this.sid = sid;
this.environment = environment;
}
/**
* @hidden
* @param idToken
* @param clientInfo
*/
Account.createAccount = function (idToken, clientInfo) {
// create accountIdentifier
var accountIdentifier = idToken.objectId || idToken.subject;
// create homeAccountIdentifier
var uid = clientInfo ? clientInfo.uid : "";
var utid = clientInfo ? clientInfo.utid : "";
var homeAccountIdentifier;
if (!StringUtils_1.StringUtils.isEmpty(uid)) {
homeAccountIdentifier = StringUtils_1.StringUtils.isEmpty(utid) ? CryptoUtils_1.CryptoUtils.base64Encode(uid) : CryptoUtils_1.CryptoUtils.base64Encode(uid) + "." + CryptoUtils_1.CryptoUtils.base64Encode(utid);
}
return new Account(accountIdentifier, homeAccountIdentifier, idToken.preferredName, idToken.name, idToken.claims, idToken.sid, idToken.issuer);
};
/**
* 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
*/
Account.compareAccounts = function (a1, a2) {
if (!a1 || !a2) {
return false;
}
if (a1.homeAccountIdentifier && a2.homeAccountIdentifier) {
if (a1.homeAccountIdentifier === a2.homeAccountIdentifier) {
return true;
}
}
return false;
};
return Account;
}());
exports.Account = Account;
//# sourceMappingURL=Account.js.map
;