1 |
|
2 |
|
3 |
|
4 |
|
5 | import { ClientAuthError } from "./error/ClientAuthError";
|
6 | import { TokenUtils } from "./utils/TokenUtils";
|
7 | import { StringUtils } from "./utils/StringUtils";
|
8 |
|
9 |
|
10 |
|
11 | var IdToken = (function () {
|
12 |
|
13 | function IdToken(rawIdToken) {
|
14 | if (StringUtils.isEmpty(rawIdToken)) {
|
15 | throw ClientAuthError.createIdTokenNullOrEmptyError(rawIdToken);
|
16 | }
|
17 | try {
|
18 | this.rawIdToken = rawIdToken;
|
19 | this.claims = TokenUtils.extractIdToken(rawIdToken);
|
20 | if (this.claims) {
|
21 | if (this.claims.hasOwnProperty("iss")) {
|
22 | this.issuer = this.claims["iss"];
|
23 | }
|
24 | if (this.claims.hasOwnProperty("oid")) {
|
25 | this.objectId = this.claims["oid"];
|
26 | }
|
27 | if (this.claims.hasOwnProperty("sub")) {
|
28 | this.subject = this.claims["sub"];
|
29 | }
|
30 | if (this.claims.hasOwnProperty("tid")) {
|
31 | this.tenantId = this.claims["tid"];
|
32 | }
|
33 | if (this.claims.hasOwnProperty("ver")) {
|
34 | this.version = this.claims["ver"];
|
35 | }
|
36 | if (this.claims.hasOwnProperty("preferred_username")) {
|
37 | this.preferredName = this.claims["preferred_username"];
|
38 | }
|
39 | else if (this.claims.hasOwnProperty("upn")) {
|
40 | this.preferredName = this.claims["upn"];
|
41 | }
|
42 | if (this.claims.hasOwnProperty("name")) {
|
43 | this.name = this.claims["name"];
|
44 | }
|
45 | if (this.claims.hasOwnProperty("nonce")) {
|
46 | this.nonce = this.claims["nonce"];
|
47 | }
|
48 | if (this.claims.hasOwnProperty("exp")) {
|
49 | this.expiration = this.claims["exp"];
|
50 | }
|
51 | if (this.claims.hasOwnProperty("home_oid")) {
|
52 | this.homeObjectId = this.claims["home_oid"];
|
53 | }
|
54 | if (this.claims.hasOwnProperty("sid")) {
|
55 | this.sid = this.claims["sid"];
|
56 | }
|
57 | if (this.claims.hasOwnProperty("cloud_instance_host_name")) {
|
58 | this.cloudInstance = this.claims["cloud_instance_host_name"];
|
59 | }
|
60 |
|
61 | }
|
62 | }
|
63 | catch (e) {
|
64 | |
65 |
|
66 |
|
67 |
|
68 | throw ClientAuthError.createIdTokenParsingError(e);
|
69 | }
|
70 | }
|
71 | return IdToken;
|
72 | }());
|
73 | export { IdToken };
|
74 |
|
\ | No newline at end of file |