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