UNPKG

3.26 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.IdToken = void 0;
8var ClientAuthError_1 = require("./error/ClientAuthError");
9var TokenUtils_1 = require("./utils/TokenUtils");
10var StringUtils_1 = require("./utils/StringUtils");
11/**
12 * @hidden
13 */
14var IdToken = /** @class */ (function () {
15 /* tslint:disable:no-string-literal */
16 function IdToken(rawIdToken) {
17 if (StringUtils_1.StringUtils.isEmpty(rawIdToken)) {
18 throw ClientAuthError_1.ClientAuthError.createIdTokenNullOrEmptyError(rawIdToken);
19 }
20 try {
21 this.rawIdToken = rawIdToken;
22 this.claims = TokenUtils_1.TokenUtils.extractIdToken(rawIdToken);
23 if (this.claims) {
24 if (this.claims.hasOwnProperty("iss")) {
25 this.issuer = this.claims["iss"];
26 }
27 if (this.claims.hasOwnProperty("oid")) {
28 this.objectId = this.claims["oid"];
29 }
30 if (this.claims.hasOwnProperty("sub")) {
31 this.subject = this.claims["sub"];
32 }
33 if (this.claims.hasOwnProperty("tid")) {
34 this.tenantId = this.claims["tid"];
35 }
36 if (this.claims.hasOwnProperty("ver")) {
37 this.version = this.claims["ver"];
38 }
39 if (this.claims.hasOwnProperty("preferred_username")) {
40 this.preferredName = this.claims["preferred_username"];
41 }
42 else if (this.claims.hasOwnProperty("upn")) {
43 this.preferredName = this.claims["upn"];
44 }
45 if (this.claims.hasOwnProperty("name")) {
46 this.name = this.claims["name"];
47 }
48 if (this.claims.hasOwnProperty("nonce")) {
49 this.nonce = this.claims["nonce"];
50 }
51 if (this.claims.hasOwnProperty("exp")) {
52 this.expiration = this.claims["exp"];
53 }
54 if (this.claims.hasOwnProperty("home_oid")) {
55 this.homeObjectId = this.claims["home_oid"];
56 }
57 if (this.claims.hasOwnProperty("sid")) {
58 this.sid = this.claims["sid"];
59 }
60 if (this.claims.hasOwnProperty("cloud_instance_host_name")) {
61 this.cloudInstance = this.claims["cloud_instance_host_name"];
62 }
63 /* tslint:enable:no-string-literal */
64 }
65 }
66 catch (e) {
67 /*
68 * TODO: This error here won't really every be thrown, since extractIdToken() returns null if the decodeJwt() fails.
69 * Need to add better error handling here to account for being unable to decode jwts.
70 */
71 throw ClientAuthError_1.ClientAuthError.createIdTokenParsingError(e);
72 }
73 }
74 return IdToken;
75}());
76exports.IdToken = IdToken;
77//# sourceMappingURL=IdToken.js.map
\No newline at end of file