/*!
 * Copyright (C) Microsoft Corporation. All rights reserved.
 */
/**
 * Decode the payload section of a JWT (no signature verification).
 * Returns an empty object on any failure (malformed JWT, invalid base64, invalid JSON).
 */
export function parseJwtPayload(jwt) {
    const parts = jwt.split('.');
    if (parts.length < 2) {
        return {};
    }
    // Base64url -> Base64
    const base64 = parts[1].replace(/-/g, '+').replace(/_/g, '/');
    try {
        const json = atob(base64);
        return JSON.parse(json);
    }
    catch {
        return {};
    }
}
/**
 * Extract the `exp` claim from a JWT and convert it to milliseconds.
 * Returns `undefined` if the token cannot be parsed or has no numeric `exp` claim.
 */
export function getJwtExpirationMs(jwt) {
    const payload = parseJwtPayload(jwt);
    const exp = payload.exp;
    if (typeof exp !== 'number') {
        return undefined;
    }
    return exp * 1000;
}
//# sourceMappingURL=JwtUtils.js.map