UNPKG

integreat

Version:
38 lines 1.32 kB
import Auth from '../Auth.js'; import identAuth from '../../authenticators/ident.js'; import { ensureArray } from '../../utils/array.js'; import { isNotNullOrUndefined, isObject } from '../../utils/is.js'; import { setUpAuth } from '../../Instance.js'; import { lookupById } from '../../utils/indexUtils.js'; const isAuthDef = (def) => isObject(def) && typeof def.id === 'string' && typeof def.authenticator === 'string'; export const resolveAuth = (authenticators, auths) => function resolveAuth(auth) { if (isObject(auth) && !!auth.outgoing) { auth = auth.outgoing; } if (typeof auth === 'string') { return lookupById(auth, auths); } else if (isAuthDef(auth)) { return setUpAuth(authenticators)(auth); } else if (auth) { return new Auth('ident', identAuth, {}); } else { return undefined; } }; export const resolveIncomingAuth = (authenticators, auths) => function resolveIncomingAuth(auth) { if (isObject(auth) && auth.incoming) { const incomingAuths = ensureArray(auth.incoming); return incomingAuths .map((incoming) => resolveAuth(authenticators, auths)(incoming)) .filter(isNotNullOrUndefined); } else { return undefined; } }; //# sourceMappingURL=resolveAuth.js.map