"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isJwtInvalidOrExpired = isJwtInvalidOrExpired;
exports.decodeJwtClaims = decodeJwtClaims;
exports.getGroupOfJwt = getGroupOfJwt;
const utils_1 = require("../utils");
/**
 * @internal this function is for internal use only and may be changed without notice
 * Returns true if the jwt is invalid or expired, false otherwise.
 */
function isJwtInvalidOrExpired(jwt) {
    try {
        const claims = decodeJwtClaims(jwt);
        // Using the 'exp' string is safe to use as it is part of the JWT RFC and cannot be modified by us.
        return !('exp' in claims) || claims['exp'] * 1000 < new Date().getTime();
    }
    catch (e) {
        return true;
    }
}
/**
 * @internal this function is for internal use only and may be changed without notice
 * Get the claims of the jwt.
 */
function decodeJwtClaims(jwt) {
    const parts = jwt.split('.');
    if (parts.length !== 3)
        throw new Error('Invalid JWT: should be 3 parts');
    return JSON.parse((0, utils_1.a2b)(parts[1]));
}
/**
 * @internal this function is for internal use only and may be changed without notice
 * Get the group of the jwt.
 */
function getGroupOfJwt(jwt) {
    return decodeJwtClaims(jwt)['g'];
}
//# sourceMappingURL=JwtUtils.js.map