UNPKG

bento-auth-js

Version:

Authentication library for web applications of Bento-Platform

36 lines 1.36 kB
export const LS_OPENID_CONFIG_KEY = "BENTO_OPENID_CONFIG"; export const buildUrlEncodedData = (obj) => Object.entries(obj).reduce((params, [k, v]) => { if (v === null || v === undefined) return params; params.set(k, v.toString()); return params; }, new URLSearchParams()); export const getIsAuthenticated = (idTokenContents) => !!idTokenContents && idTokenContents.exp && Math.round(new Date().getTime() / 1000) < idTokenContents.exp; export const makeAuthorizationHeader = (token) => token ? { Authorization: `Bearer ${token}` } : {}; export const recursiveOrderedObject = (x) => { if (Array.isArray(x)) { // Don't sort array, but DO make sure each nested object has sorted keys return x.map((y) => recursiveOrderedObject(y)); } else if (typeof x === "object" && x !== null) { return Object.keys(x) .sort() .reduce((acc, y) => { acc[y] = x[y]; return acc; }, {}); } else { return x; // Primitive } }; export const popLocalStorageItem = (key) => { const val = localStorage.getItem(key); localStorage.removeItem(key); return val; }; export const nop = () => { }; export const logMissingAuthContext = (...keys) => { console.error(`Missing Bento auth context: ${keys.join(" or ")}`); }; //# sourceMappingURL=utils.js.map