UNPKG

1.84 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5
6var _buffer = require("buffer");
7
8/*!
9 * Copyright 2016 Amazon.com,
10 * Inc. or its affiliates. All Rights Reserved.
11 *
12 * Licensed under the Amazon Software License (the "License").
13 * You may not use this file except in compliance with the
14 * License. A copy of the License is located at
15 *
16 * http://aws.amazon.com/asl/
17 *
18 * or in the "license" file accompanying this file. This file is
19 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
20 * CONDITIONS OF ANY KIND, express or implied. See the License
21 * for the specific language governing permissions and
22 * limitations under the License.
23 */
24
25/** @class */
26var CognitoJwtToken = /*#__PURE__*/function () {
27 /**
28 * Constructs a new CognitoJwtToken object
29 * @param {string=} token The JWT token.
30 */
31 function CognitoJwtToken(token) {
32 // Assign object
33 this.jwtToken = token || '';
34 this.payload = this.decodePayload();
35 }
36 /**
37 * @returns {string} the record's token.
38 */
39
40
41 var _proto = CognitoJwtToken.prototype;
42
43 _proto.getJwtToken = function getJwtToken() {
44 return this.jwtToken;
45 }
46 /**
47 * @returns {int} the token's expiration (exp member).
48 */
49 ;
50
51 _proto.getExpiration = function getExpiration() {
52 return this.payload.exp;
53 }
54 /**
55 * @returns {int} the token's "issued at" (iat member).
56 */
57 ;
58
59 _proto.getIssuedAt = function getIssuedAt() {
60 return this.payload.iat;
61 }
62 /**
63 * @returns {object} the token's payload.
64 */
65 ;
66
67 _proto.decodePayload = function decodePayload() {
68 var payload = this.jwtToken.split('.')[1];
69
70 try {
71 return JSON.parse(_buffer.Buffer.from(payload, 'base64').toString('utf8'));
72 } catch (err) {
73 return {};
74 }
75 };
76
77 return CognitoJwtToken;
78}();
79
80exports["default"] = CognitoJwtToken;
\No newline at end of file