msal
Version:
Microsoft Authentication Library for js
77 lines • 3.26 kB
JavaScript
"use strict";
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.IdToken = void 0;
var ClientAuthError_1 = require("./error/ClientAuthError");
var TokenUtils_1 = require("./utils/TokenUtils");
var StringUtils_1 = require("./utils/StringUtils");
/**
* @hidden
*/
var IdToken = /** @class */ (function () {
/* tslint:disable:no-string-literal */
function IdToken(rawIdToken) {
if (StringUtils_1.StringUtils.isEmpty(rawIdToken)) {
throw ClientAuthError_1.ClientAuthError.createIdTokenNullOrEmptyError(rawIdToken);
}
try {
this.rawIdToken = rawIdToken;
this.claims = TokenUtils_1.TokenUtils.extractIdToken(rawIdToken);
if (this.claims) {
if (this.claims.hasOwnProperty("iss")) {
this.issuer = this.claims["iss"];
}
if (this.claims.hasOwnProperty("oid")) {
this.objectId = this.claims["oid"];
}
if (this.claims.hasOwnProperty("sub")) {
this.subject = this.claims["sub"];
}
if (this.claims.hasOwnProperty("tid")) {
this.tenantId = this.claims["tid"];
}
if (this.claims.hasOwnProperty("ver")) {
this.version = this.claims["ver"];
}
if (this.claims.hasOwnProperty("preferred_username")) {
this.preferredName = this.claims["preferred_username"];
}
else if (this.claims.hasOwnProperty("upn")) {
this.preferredName = this.claims["upn"];
}
if (this.claims.hasOwnProperty("name")) {
this.name = this.claims["name"];
}
if (this.claims.hasOwnProperty("nonce")) {
this.nonce = this.claims["nonce"];
}
if (this.claims.hasOwnProperty("exp")) {
this.expiration = this.claims["exp"];
}
if (this.claims.hasOwnProperty("home_oid")) {
this.homeObjectId = this.claims["home_oid"];
}
if (this.claims.hasOwnProperty("sid")) {
this.sid = this.claims["sid"];
}
if (this.claims.hasOwnProperty("cloud_instance_host_name")) {
this.cloudInstance = this.claims["cloud_instance_host_name"];
}
/* tslint:enable:no-string-literal */
}
}
catch (e) {
/*
* TODO: This error here won't really every be thrown, since extractIdToken() returns null if the decodeJwt() fails.
* Need to add better error handling here to account for being unable to decode jwts.
*/
throw ClientAuthError_1.ClientAuthError.createIdTokenParsingError(e);
}
}
return IdToken;
}());
exports.IdToken = IdToken;
//# sourceMappingURL=IdToken.js.map