UNPKG

mongodb-stitch

Version:

[![Join the chat at https://gitter.im/mongodb/stitch](https://badges.gitter.im/mongodb/stitch.svg)](https://gitter.im/mongodb/stitch?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

38 lines 1.39 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports", "../../internal/common/Base64"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Base64_1 = require("../../internal/common/Base64"); var EXPIRES = "exp"; var ISSUED_AT = "iat"; var JWT = (function () { function JWT(expires, issuedAt) { this.expires = expires; this.issuedAt = issuedAt; } JWT.fromEncoded = function (encodedJWT) { var parts = JWT.splitToken(encodedJWT); var json = JSON.parse(Base64_1.base64Decode(parts[1])); var expires = json[EXPIRES]; var iat = json[ISSUED_AT]; return new JWT(expires, iat); }; JWT.splitToken = function (jwt) { var parts = jwt.split("."); if (parts.length !== 3) { throw new Error("Malformed JWT token. The string " + jwt + " should have 3 parts."); } return parts; }; return JWT; }()); exports.default = JWT; }); //# sourceMappingURL=JWT.js.map