UNPKG

integreat-authenticator-oauth2

Version:
33 lines 1.08 kB
import authenticate from './authenticate.js'; function isAuthenticated(authentication, _options, _action) { if (!authentication) { return false; } const { status, token, expire } = authentication; return (status === 'granted' && !!token && (typeof expire !== 'number' || Date.now() < expire)); } const oauth2 = { authenticate, isAuthenticated, authentication: { asObject(authentication) { return isAuthenticated(authentication, null, null) ? { token: authentication.token } : {}; }, asHttpHeaders(authentication) { const type = authentication?.type === undefined ? 'Bearer' : authentication.type; return isAuthenticated(authentication, null, null) ? { Authorization: type ? `${type} ${authentication.token}` : authentication.token, } : {}; }, }, }; export default oauth2; //# sourceMappingURL=index.js.map