integreat-authenticator-oauth2
Version:
OAuth 2.0 authenticator for Integreat
33 lines • 1.08 kB
JavaScript
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