UNPKG

1.72 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.parseAuthentication = parseAuthentication;
4exports.authenticate = authenticate;
5const commons_1 = require("@feathersjs/commons");
6const authentication_1 = require("@feathersjs/authentication");
7const debug = (0, commons_1.createDebug)('@feathersjs/koa/authentication');
8function parseAuthentication(settings = {}) {
9 return async (ctx, next) => {
10 var _a;
11 const app = ctx.app;
12 const service = (_a = app.defaultAuthentication) === null || _a === void 0 ? void 0 : _a.call(app, settings.service);
13 if (!service) {
14 return next();
15 }
16 const config = service.configuration;
17 const authStrategies = settings.strategies || config.parseStrategies || config.authStrategies || [];
18 if (authStrategies.length === 0) {
19 debug('No `authStrategies` or `parseStrategies` found in authentication configuration');
20 return next();
21 }
22 const authentication = await service.parse(ctx.req, ctx.res, ...authStrategies);
23 if (authentication) {
24 debug('Parsed authentication from HTTP header', authentication);
25 ctx.feathers = { ...ctx.feathers, authentication };
26 }
27 return next();
28 };
29}
30function authenticate(settings, ...strategies) {
31 const hook = (0, authentication_1.authenticate)(settings, ...strategies);
32 return async (ctx, next) => {
33 const app = ctx.app;
34 const params = ctx.feathers;
35 const context = { app, params };
36 await hook(context);
37 ctx.feathers = context.params;
38 return next();
39 };
40}
41//# sourceMappingURL=authentication.js.map
\No newline at end of file