@veramo/remote-server
Version:
Express.js module that can expose some agent methods and messaging endpoints
25 lines • 724 B
JavaScript
import passport from 'passport';
import Bearer from 'passport-http-bearer';
import { Router } from 'express';
/**
* This provides a simple authorization mechanism based on a single pre-shared API key.
*
* @param apiKey - the pre-shared API key
*
* @public
*/
export function apiKeyAuth({ apiKey }) {
const router = Router();
router.use(passport.initialize());
passport.use(new Bearer.Strategy((token, done) => {
if (!apiKey || apiKey === token) {
done(null, {}, { scope: 'all' });
}
else {
done(null, false);
}
}));
router.use(passport.authenticate('bearer', { session: false }));
return router;
}
//# sourceMappingURL=api-key-auth.js.map