UNPKG

3.08 kBJavaScriptView Raw
1/*
2 * Copyright (c) Microsoft Corporation. All rights reserved.
3 * Licensed under the MIT License.
4 */
5import { ClientAuthError } from "./error/ClientAuthError";
6import { TokenUtils } from "./utils/TokenUtils";
7import { StringUtils } from "./utils/StringUtils";
8/**
9 * @hidden
10 */
11var IdToken = /** @class */ (function () {
12 /* tslint:disable:no-string-literal */
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 /* tslint:enable:no-string-literal */
61 }
62 }
63 catch (e) {
64 /*
65 * TODO: This error here won't really every be thrown, since extractIdToken() returns null if the decodeJwt() fails.
66 * Need to add better error handling here to account for being unable to decode jwts.
67 */
68 throw ClientAuthError.createIdTokenParsingError(e);
69 }
70 }
71 return IdToken;
72}());
73export { IdToken };
74//# sourceMappingURL=IdToken.js.map
\No newline at end of file