UNPKG

3.04 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright (c) Microsoft Corporation. All rights reserved.
4 * Licensed under the MIT License.
5 */
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.Account = void 0;
8var CryptoUtils_1 = require("./utils/CryptoUtils");
9var StringUtils_1 = require("./utils/StringUtils");
10/**
11 * accountIdentifier combination of idToken.uid and idToken.utid
12 * homeAccountIdentifier combination of clientInfo.uid and clientInfo.utid
13 * userName idToken.preferred_username
14 * name idToken.name
15 * idToken idToken
16 * sid idToken.sid - session identifier
17 * environment idtoken.issuer (the authority that issues the token)
18 */
19var Account = /** @class */ (function () {
20 /**
21 * Creates an Account Object
22 * @praram accountIdentifier
23 * @param homeAccountIdentifier
24 * @param userName
25 * @param name
26 * @param idToken
27 * @param sid
28 * @param environment
29 */
30 function Account(accountIdentifier, homeAccountIdentifier, userName, name, idTokenClaims, sid, environment) {
31 this.accountIdentifier = accountIdentifier;
32 this.homeAccountIdentifier = homeAccountIdentifier;
33 this.userName = userName;
34 this.name = name;
35 // will be deprecated soon
36 this.idToken = idTokenClaims;
37 this.idTokenClaims = idTokenClaims;
38 this.sid = sid;
39 this.environment = environment;
40 }
41 /**
42 * @hidden
43 * @param idToken
44 * @param clientInfo
45 */
46 Account.createAccount = function (idToken, clientInfo) {
47 // create accountIdentifier
48 var accountIdentifier = idToken.objectId || idToken.subject;
49 // create homeAccountIdentifier
50 var uid = clientInfo ? clientInfo.uid : "";
51 var utid = clientInfo ? clientInfo.utid : "";
52 var homeAccountIdentifier;
53 if (!StringUtils_1.StringUtils.isEmpty(uid)) {
54 homeAccountIdentifier = StringUtils_1.StringUtils.isEmpty(utid) ? CryptoUtils_1.CryptoUtils.base64Encode(uid) : CryptoUtils_1.CryptoUtils.base64Encode(uid) + "." + CryptoUtils_1.CryptoUtils.base64Encode(utid);
55 }
56 return new Account(accountIdentifier, homeAccountIdentifier, idToken.preferredName, idToken.name, idToken.claims, idToken.sid, idToken.issuer);
57 };
58 /**
59 * Utils function to compare two Account objects - used to check if the same user account is logged in
60 *
61 * @param a1: Account object
62 * @param a2: Account object
63 */
64 Account.compareAccounts = function (a1, a2) {
65 if (!a1 || !a2) {
66 return false;
67 }
68 if (a1.homeAccountIdentifier && a2.homeAccountIdentifier) {
69 if (a1.homeAccountIdentifier === a2.homeAccountIdentifier) {
70 return true;
71 }
72 }
73 return false;
74 };
75 return Account;
76}());
77exports.Account = Account;
78//# sourceMappingURL=Account.js.map
\No newline at end of file