New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@feathersjs/authentication

Package Overview
Dependencies
Maintainers
4
Versions
130
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@feathersjs/authentication - npm Package Compare versions

Comparing version 5.0.0-pre.9 to 5.0.0-pre.10

136

lib/core.js
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -22,3 +13,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const options_1 = __importDefault(require("./options"));
const debug = commons_1.createDebug('@feathersjs/authentication/base');
const debug = (0, commons_1.createDebug)('@feathersjs/authentication/base');
/**

@@ -43,3 +34,3 @@ * A base class for managing authentication strategies and creating and verifying JWTs

app.set('defaultAuthentication', app.get('defaultAuthentication') || configKey);
app.set(configKey, merge_1.default({}, app.get(configKey), options));
app.set(configKey, (0, merge_1.default)({}, app.get(configKey), options));
}

@@ -98,15 +89,13 @@ /**

*/
createAccessToken(payload, optsOverride, secretOverride) {
return __awaiter(this, void 0, void 0, function* () {
const { secret, jwtOptions } = this.configuration;
// Use configuration by default but allow overriding the secret
const jwtSecret = secretOverride || secret;
// Default jwt options merged with additional options
const options = merge_1.default({}, jwtOptions, optsOverride);
if (!options.jwtid) {
// Generate a UUID as JWT ID by default
options.jwtid = uuid_1.v4();
}
return jsonwebtoken_1.default.sign(payload, jwtSecret, options);
});
async createAccessToken(payload, optsOverride, secretOverride) {
const { secret, jwtOptions } = this.configuration;
// Use configuration by default but allow overriding the secret
const jwtSecret = secretOverride || secret;
// Default jwt options merged with additional options
const options = (0, merge_1.default)({}, jwtOptions, optsOverride);
if (!options.jwtid) {
// Generate a UUID as JWT ID by default
options.jwtid = (0, uuid_1.v4)();
}
return jsonwebtoken_1.default.sign(payload, jwtSecret, options);
}

@@ -120,21 +109,19 @@ /**

*/
verifyAccessToken(accessToken, optsOverride, secretOverride) {
return __awaiter(this, void 0, void 0, function* () {
const { secret, jwtOptions } = this.configuration;
const jwtSecret = secretOverride || secret;
const options = merge_1.default({}, jwtOptions, optsOverride);
const { algorithm } = options;
// Normalize the `algorithm` setting into the algorithms array
if (algorithm && !options.algorithms) {
options.algorithms = Array.isArray(algorithm) ? algorithm : [algorithm];
delete options.algorithm;
}
try {
const verified = jsonwebtoken_1.default.verify(accessToken, jwtSecret, options);
return verified;
}
catch (error) {
throw new errors_1.NotAuthenticated(error.message, error);
}
});
async verifyAccessToken(accessToken, optsOverride, secretOverride) {
const { secret, jwtOptions } = this.configuration;
const jwtSecret = secretOverride || secret;
const options = (0, merge_1.default)({}, jwtOptions, optsOverride);
const { algorithm } = options;
// Normalize the `algorithm` setting into the algorithms array
if (algorithm && !options.algorithms) {
options.algorithms = Array.isArray(algorithm) ? algorithm : [algorithm];
delete options.algorithm;
}
try {
const verified = jsonwebtoken_1.default.verify(accessToken, jwtSecret, options);
return verified;
}
catch (error) {
throw new errors_1.NotAuthenticated(error.message, error);
}
}

@@ -148,25 +135,24 @@ /**

*/
authenticate(authentication, params, ...allowed) {
return __awaiter(this, void 0, void 0, function* () {
const { strategy } = authentication || {};
const [authStrategy] = this.getStrategies(strategy);
const strategyAllowed = allowed.includes(strategy);
debug('Running authenticate for strategy', strategy, allowed);
if (!authentication || !authStrategy || !strategyAllowed) {
const additionalInfo = (!strategy && ' (no `strategy` set)') ||
(!strategyAllowed && ' (strategy not allowed in authStrategies)') || '';
// If there are no valid strategies or `authentication` is not an object
throw new errors_1.NotAuthenticated('Invalid authentication information' + additionalInfo);
}
return authStrategy.authenticate(authentication, Object.assign(Object.assign({}, params), { authenticated: true }));
async authenticate(authentication, params, ...allowed) {
const { strategy } = authentication || {};
const [authStrategy] = this.getStrategies(strategy);
const strategyAllowed = allowed.includes(strategy);
debug('Running authenticate for strategy', strategy, allowed);
if (!authentication || !authStrategy || !strategyAllowed) {
const additionalInfo = (!strategy && ' (no `strategy` set)') ||
(!strategyAllowed && ' (strategy not allowed in authStrategies)') || '';
// If there are no valid strategies or `authentication` is not an object
throw new errors_1.NotAuthenticated('Invalid authentication information' + additionalInfo);
}
return authStrategy.authenticate(authentication, {
...params,
authenticated: true
});
}
handleConnection(event, connection, authResult) {
return __awaiter(this, void 0, void 0, function* () {
const strategies = this.getStrategies(...Object.keys(this.strategies))
.filter(current => typeof current.handleConnection === 'function');
for (const strategy of strategies) {
yield strategy.handleConnection(event, connection, authResult);
}
});
async handleConnection(event, connection, authResult) {
const strategies = this.getStrategies(...Object.keys(this.strategies))
.filter(current => typeof current.handleConnection === 'function');
for (const strategy of strategies) {
await strategy.handleConnection(event, connection, authResult);
}
}

@@ -180,15 +166,13 @@ /**

*/
parse(req, res, ...names) {
return __awaiter(this, void 0, void 0, function* () {
const strategies = this.getStrategies(...names)
.filter(current => typeof current.parse === 'function');
debug('Strategies parsing HTTP header for authentication information', names);
for (const authStrategy of strategies) {
const value = yield authStrategy.parse(req, res);
if (value !== null) {
return value;
}
async parse(req, res, ...names) {
const strategies = this.getStrategies(...names)
.filter(current => typeof current.parse === 'function');
debug('Strategies parsing HTTP header for authentication information', names);
for (const authStrategy of strategies) {
const value = await authStrategy.parse(req, res);
if (value !== null) {
return value;
}
return null;
});
}
return null;
}

@@ -195,0 +179,0 @@ }

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -19,6 +10,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const commons_1 = require("@feathersjs/commons");
const debug = commons_1.createDebug('@feathersjs/authentication/hooks/authenticate');
const debug = (0, commons_1.createDebug)('@feathersjs/authentication/hooks/authenticate');
exports.default = (originalSettings, ...originalStrategies) => {
const settings = typeof originalSettings === 'string'
? { strategies: flatten_1.default([originalSettings, ...originalStrategies]) }
? { strategies: (0, flatten_1.default)([originalSettings, ...originalStrategies]) }
: originalSettings;

@@ -28,4 +19,4 @@ if (!originalSettings || settings.strategies.length === 0) {

}
return (context, _next) => __awaiter(void 0, void 0, void 0, function* () {
const next = typeof _next === 'function' ? _next : () => __awaiter(void 0, void 0, void 0, function* () { return context; });
return async (context, _next) => {
const next = typeof _next === 'function' ? _next : async () => context;
const { app, params, type, path, service } = context;

@@ -50,6 +41,6 @@ const { strategies } = settings;

if (authentication) {
const authParams = omit_1.default(params, 'provider', 'authentication');
const authParams = (0, omit_1.default)(params, 'provider', 'authentication');
debug('Authenticating with', authentication, strategies);
const authResult = yield authService.authenticate(authentication, authParams, ...strategies);
context.params = Object.assign({}, params, omit_1.default(authResult, 'accessToken'), { authenticated: true });
const authResult = await authService.authenticate(authentication, authParams, ...strategies);
context.params = Object.assign({}, params, (0, omit_1.default)(authResult, 'accessToken'), { authenticated: true });
}

@@ -60,4 +51,4 @@ else if (provider) {

return next();
});
};
};
//# sourceMappingURL=authenticate.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -16,11 +7,11 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const omit_1 = __importDefault(require("lodash/omit"));
exports.default = (event) => (context, next) => __awaiter(void 0, void 0, void 0, function* () {
yield next();
exports.default = (event) => async (context, next) => {
await next();
const { result, params: { connection } } = context;
if (connection) {
const service = context.service;
Object.assign(connection, omit_1.default(result, 'accessToken', 'authentication'));
yield service.handleConnection(event, connection, result);
Object.assign(connection, (0, omit_1.default)(result, 'accessToken', 'authentication'));
await service.handleConnection(event, connection, result);
}
});
};
//# sourceMappingURL=connection.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const commons_1 = require("@feathersjs/commons");
const debug = commons_1.createDebug('@feathersjs/authentication/hooks/connection');
exports.default = (event) => (context, next) => __awaiter(void 0, void 0, void 0, function* () {
yield next();
const debug = (0, commons_1.createDebug)('@feathersjs/authentication/hooks/connection');
exports.default = (event) => async (context, next) => {
await next();
const { app, result, params } = context;

@@ -21,3 +12,3 @@ if (params.provider && result) {

}
});
};
//# sourceMappingURL=event.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -23,3 +14,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const strategy_1 = require("./strategy");
const debug = commons_1.createDebug('@feathersjs/authentication/jwt');
const debug = (0, commons_1.createDebug)('@feathersjs/authentication/jwt');
const SPLIT_HEADER = /(\S+)\s+(\S+)/;

@@ -34,35 +25,40 @@ class JWTStrategy extends strategy_1.AuthenticationBaseStrategy {

const config = super.configuration;
return Object.assign({ service: authConfig.service, entity: authConfig.entity, entityId: authConfig.entityId, header: 'Authorization', schemes: ['Bearer', 'JWT'] }, config);
return {
service: authConfig.service,
entity: authConfig.entity,
entityId: authConfig.entityId,
header: 'Authorization',
schemes: ['Bearer', 'JWT'],
...config
};
}
handleConnection(event, connection, authResult) {
return __awaiter(this, void 0, void 0, function* () {
const isValidLogout = event === 'logout' && connection.authentication && authResult &&
connection.authentication.accessToken === authResult.accessToken;
const { accessToken } = authResult || {};
if (accessToken && event === 'login') {
debug('Adding authentication information to connection');
const { exp } = yield this.authentication.verifyAccessToken(accessToken);
// The time (in ms) until the token expires
const duration = (exp * 1000) - Date.now();
// This may have to be a `logout` event but right now we don't want
// the whole context object lingering around until the timer is gone
const timer = long_timeout_1.default.setTimeout(() => this.app.emit('disconnect', connection), duration);
debug(`Registering connection expiration timer for ${duration}ms`);
long_timeout_1.default.clearTimeout(this.expirationTimers.get(connection));
this.expirationTimers.set(connection, timer);
debug('Adding authentication information to connection');
connection.authentication = {
strategy: this.name,
accessToken
};
}
else if (event === 'disconnect' || isValidLogout) {
debug('Removing authentication information and expiration timer from connection');
const { entity } = this.configuration;
delete connection[entity];
delete connection.authentication;
long_timeout_1.default.clearTimeout(this.expirationTimers.get(connection));
this.expirationTimers.delete(connection);
}
});
async handleConnection(event, connection, authResult) {
const isValidLogout = event === 'logout' && connection.authentication && authResult &&
connection.authentication.accessToken === authResult.accessToken;
const { accessToken } = authResult || {};
if (accessToken && event === 'login') {
debug('Adding authentication information to connection');
const { exp } = await this.authentication.verifyAccessToken(accessToken);
// The time (in ms) until the token expires
const duration = (exp * 1000) - Date.now();
// This may have to be a `logout` event but right now we don't want
// the whole context object lingering around until the timer is gone
const timer = long_timeout_1.default.setTimeout(() => this.app.emit('disconnect', connection), duration);
debug(`Registering connection expiration timer for ${duration}ms`);
long_timeout_1.default.clearTimeout(this.expirationTimers.get(connection));
this.expirationTimers.set(connection, timer);
debug('Adding authentication information to connection');
connection.authentication = {
strategy: this.name,
accessToken
};
}
else if (event === 'disconnect' || isValidLogout) {
debug('Removing authentication information and expiration timer from connection');
const { entity } = this.configuration;
delete connection[entity];
delete connection.authentication;
long_timeout_1.default.clearTimeout(this.expirationTimers.get(connection));
this.expirationTimers.delete(connection);
}
}

@@ -80,6 +76,4 @@ verifyConfiguration() {

}
getEntityQuery(_params) {
return __awaiter(this, void 0, void 0, function* () {
return {};
});
async getEntityQuery(_params) {
return {};
}

@@ -92,66 +86,61 @@ /**

*/
getEntity(id, params) {
return __awaiter(this, void 0, void 0, function* () {
const entityService = this.entityService;
const { entity } = this.configuration;
debug('Getting entity', id);
if (entityService === null) {
throw new errors_1.NotAuthenticated('Could not find entity service');
}
const query = yield this.getEntityQuery(params);
const getParams = Object.assign({}, omit_1.default(params, 'provider'), { query });
const result = yield entityService.get(id, getParams);
if (!params.provider) {
return result;
}
return entityService.get(id, Object.assign(Object.assign({}, params), { [entity]: result }));
});
async getEntity(id, params) {
const entityService = this.entityService;
const { entity } = this.configuration;
debug('Getting entity', id);
if (entityService === null) {
throw new errors_1.NotAuthenticated('Could not find entity service');
}
const query = await this.getEntityQuery(params);
const getParams = Object.assign({}, (0, omit_1.default)(params, 'provider'), { query });
const result = await entityService.get(id, getParams);
if (!params.provider) {
return result;
}
return entityService.get(id, { ...params, [entity]: result });
}
getEntityId(authResult, _params) {
return __awaiter(this, void 0, void 0, function* () {
return authResult.authentication.payload.sub;
});
async getEntityId(authResult, _params) {
return authResult.authentication.payload.sub;
}
authenticate(authentication, params) {
return __awaiter(this, void 0, void 0, function* () {
const { accessToken } = authentication;
const { entity } = this.configuration;
if (!accessToken) {
throw new errors_1.NotAuthenticated('No access token');
}
const payload = yield this.authentication.verifyAccessToken(accessToken, params.jwt);
const result = {
async authenticate(authentication, params) {
const { accessToken } = authentication;
const { entity } = this.configuration;
if (!accessToken) {
throw new errors_1.NotAuthenticated('No access token');
}
const payload = await this.authentication.verifyAccessToken(accessToken, params.jwt);
const result = {
accessToken,
authentication: {
strategy: 'jwt',
accessToken,
authentication: {
strategy: 'jwt',
accessToken,
payload
}
};
if (entity === null) {
return result;
payload
}
const entityId = yield this.getEntityId(result, params);
const value = yield this.getEntity(entityId, params);
return Object.assign(Object.assign({}, result), { [entity]: value });
});
};
if (entity === null) {
return result;
}
const entityId = await this.getEntityId(result, params);
const value = await this.getEntity(entityId, params);
return {
...result,
[entity]: value
};
}
parse(req) {
return __awaiter(this, void 0, void 0, function* () {
const { header, schemes } = this.configuration;
const headerValue = req.headers && req.headers[header.toLowerCase()];
if (!headerValue || typeof headerValue !== 'string') {
return null;
}
debug('Found parsed header value');
const [, scheme, schemeValue] = headerValue.match(SPLIT_HEADER) || [];
const hasScheme = scheme && schemes.some(current => new RegExp(current, 'i').test(scheme));
if (scheme && !hasScheme) {
return null;
}
return {
strategy: this.name,
accessToken: hasScheme ? schemeValue : headerValue
};
});
async parse(req) {
const { header, schemes } = this.configuration;
const headerValue = req.headers && req.headers[header.toLowerCase()];
if (!headerValue || typeof headerValue !== 'string') {
return null;
}
debug('Found parsed header value');
const [, scheme, schemeValue] = headerValue.match(SPLIT_HEADER) || [];
const hasScheme = scheme && schemes.some(current => new RegExp(current, 'i').test(scheme));
if (scheme && !hasScheme) {
return null;
}
return {
strategy: this.name,
accessToken: hasScheme ? schemeValue : headerValue
};
}

@@ -158,0 +147,0 @@ }

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -23,3 +14,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
const debug = commons_1.createDebug('@feathersjs/authentication/service');
const debug = (0, commons_1.createDebug)('@feathersjs/authentication/service');
class AuthenticationService extends core_1.AuthenticationBase {

@@ -43,8 +34,6 @@ constructor(app, configKey = 'authentication', options = {}) {

*/
getPayload(_authResult, params) {
return __awaiter(this, void 0, void 0, function* () {
// Uses `params.payload` or returns an empty payload
const { payload = {} } = params;
return payload;
});
async getPayload(_authResult, params) {
// Uses `params.payload` or returns an empty payload
const { payload = {} } = params;
return payload;
}

@@ -58,18 +47,16 @@ /**

*/
getTokenOptions(authResult, params) {
return __awaiter(this, void 0, void 0, function* () {
const { service, entity, entityId } = this.configuration;
const jwtOptions = merge_1.default({}, params.jwtOptions, params.jwt);
const value = service && entity && authResult[entity];
// Set the subject to the entity id if it is available
if (value && !jwtOptions.subject) {
const idProperty = entityId || this.app.service(service).id;
const subject = value[idProperty];
if (subject === undefined) {
throw new errors_1.NotAuthenticated(`Can not set subject from ${entity}.${idProperty}`);
}
jwtOptions.subject = `${subject}`;
async getTokenOptions(authResult, params) {
const { service, entity, entityId } = this.configuration;
const jwtOptions = (0, merge_1.default)({}, params.jwtOptions, params.jwt);
const value = service && entity && authResult[entity];
// Set the subject to the entity id if it is available
if (value && !jwtOptions.subject) {
const idProperty = entityId || this.app.service(service).id;
const subject = value[idProperty];
if (subject === undefined) {
throw new errors_1.NotAuthenticated(`Can not set subject from ${entity}.${idProperty}`);
}
return jwtOptions;
});
jwtOptions.subject = `${subject}`;
}
return jwtOptions;
}

@@ -83,25 +70,23 @@ /**

*/
create(data, params) {
return __awaiter(this, void 0, void 0, function* () {
const authStrategies = params.authStrategies || this.configuration.authStrategies;
if (!authStrategies.length) {
throw new errors_1.NotAuthenticated('No authentication strategies allowed for creating a JWT (`authStrategies`)');
async create(data, params) {
const authStrategies = params.authStrategies || this.configuration.authStrategies;
if (!authStrategies.length) {
throw new errors_1.NotAuthenticated('No authentication strategies allowed for creating a JWT (`authStrategies`)');
}
const authResult = await this.authenticate(data, params, ...authStrategies);
debug('Got authentication result', authResult);
if (authResult.accessToken) {
return authResult;
}
const [payload, jwtOptions] = await Promise.all([
this.getPayload(authResult, params),
this.getTokenOptions(authResult, params)
]);
debug('Creating JWT with', payload, jwtOptions);
const accessToken = await this.createAccessToken(payload, jwtOptions, params.secret);
return (0, merge_1.default)({ accessToken }, authResult, {
authentication: {
accessToken,
payload: jsonwebtoken_1.default.decode(accessToken)
}
const authResult = yield this.authenticate(data, params, ...authStrategies);
debug('Got authentication result', authResult);
if (authResult.accessToken) {
return authResult;
}
const [payload, jwtOptions] = yield Promise.all([
this.getPayload(authResult, params),
this.getTokenOptions(authResult, params)
]);
debug('Creating JWT with', payload, jwtOptions);
const accessToken = yield this.createAccessToken(payload, jwtOptions, params.secret);
return merge_1.default({ accessToken }, authResult, {
authentication: {
accessToken,
payload: jsonwebtoken_1.default.decode(accessToken)
}
});
});

@@ -116,13 +101,11 @@ }

*/
remove(id, params) {
return __awaiter(this, void 0, void 0, function* () {
const { authentication } = params;
const { authStrategies } = this.configuration;
// When an id is passed it is expected to be the authentication `accessToken`
if (id !== null && id !== authentication.accessToken) {
throw new errors_1.NotAuthenticated('Invalid access token');
}
debug('Verifying authentication strategy in remove');
return this.authenticate(authentication, params, ...authStrategies);
});
async remove(id, params) {
const { authentication } = params;
const { authStrategies } = this.configuration;
// When an id is passed it is expected to be the authentication `accessToken`
if (id !== null && id !== authentication.accessToken) {
throw new errors_1.NotAuthenticated('Invalid access token');
}
debug('Verifying authentication strategy in remove');
return this.authenticate(authentication, params, ...authStrategies);
}

@@ -132,32 +115,30 @@ /**

*/
setup() {
return __awaiter(this, void 0, void 0, function* () {
// The setup method checks for valid settings and registers the
// connection and event (login, logout) hooks
const { secret, service, entity, entityId } = this.configuration;
if (typeof secret !== 'string') {
throw new Error('A \'secret\' must be provided in your authentication configuration');
async setup() {
// The setup method checks for valid settings and registers the
// connection and event (login, logout) hooks
const { secret, service, entity, entityId } = this.configuration;
if (typeof secret !== 'string') {
throw new Error('A \'secret\' must be provided in your authentication configuration');
}
if (entity !== null) {
if (service === undefined) {
throw new Error('The \'service\' option is not set in the authentication configuration');
}
if (entity !== null) {
if (service === undefined) {
throw new Error('The \'service\' option is not set in the authentication configuration');
}
if (this.app.service(service) === undefined) {
throw new Error(`The '${service}' entity service does not exist (set to 'null' if it is not required)`);
}
if (this.app.service(service).id === undefined && entityId === undefined) {
throw new Error(`The '${service}' service does not have an 'id' property and no 'entityId' option is set.`);
}
if (this.app.service(service) === undefined) {
throw new Error(`The '${service}' entity service does not exist (set to 'null' if it is not required)`);
}
this.hooks({
create: [hooks_1.connection('login'), hooks_1.event('login')],
remove: [hooks_1.connection('logout'), hooks_1.event('logout')]
});
this.app.on('disconnect', (connection) => __awaiter(this, void 0, void 0, function* () {
yield this.handleConnection('disconnect', connection);
}));
if (typeof this.publish === 'function') {
this.publish(() => null);
if (this.app.service(service).id === undefined && entityId === undefined) {
throw new Error(`The '${service}' service does not have an 'id' property and no 'entityId' option is set.`);
}
}
this.hooks({
create: [(0, hooks_1.connection)('login'), (0, hooks_1.event)('login')],
remove: [(0, hooks_1.connection)('logout'), (0, hooks_1.event)('logout')]
});
this.app.on('disconnect', async (connection) => {
await this.handleConnection('disconnect', connection);
});
if (typeof this.publish === 'function') {
this.publish(() => null);
}
}

@@ -164,0 +145,0 @@ }

{
"name": "@feathersjs/authentication",
"description": "Add Authentication to your FeathersJS app.",
"version": "5.0.0-pre.9",
"version": "5.0.0-pre.10",
"homepage": "https://feathersjs.com",

@@ -55,7 +55,7 @@ "main": "lib/",

"dependencies": {
"@feathersjs/commons": "^5.0.0-pre.9",
"@feathersjs/errors": "^5.0.0-pre.9",
"@feathersjs/feathers": "^5.0.0-pre.9",
"@feathersjs/transport-commons": "^5.0.0-pre.9",
"@types/jsonwebtoken": "^8.5.4",
"@feathersjs/commons": "^5.0.0-pre.10",
"@feathersjs/errors": "^5.0.0-pre.10",
"@feathersjs/feathers": "^5.0.0-pre.10",
"@feathersjs/transport-commons": "^5.0.0-pre.10",
"@types/jsonwebtoken": "^8.5.5",
"jsonwebtoken": "^8.5.1",

@@ -67,13 +67,13 @@ "lodash": "^4.17.21",

"devDependencies": {
"@feathersjs/memory": "^5.0.0-pre.9",
"@types/lodash": "^4.14.172",
"@feathersjs/memory": "^5.0.0-pre.10",
"@types/lodash": "^4.14.173",
"@types/mocha": "^9.0.0",
"@types/node": "^16.4.13",
"@types/node": "^16.9.4",
"@types/uuid": "^8.3.1",
"mocha": "^9.0.3",
"mocha": "^9.1.1",
"shx": "^0.3.3",
"ts-node": "^10.1.0",
"typescript": "^4.3.5"
"ts-node": "^10.2.1",
"typescript": "^4.4.3"
},
"gitHead": "3d1721a7286e6a7f37bbc38695fe45084023f13b"
"gitHead": "a9f7865cce8db2305b7c0d2ef4a165c2724034ef"
}

@@ -203,3 +203,3 @@ import merge from 'lodash/merge';

return verified as any;
} catch (error) {
} catch (error: any) {
throw new NotAuthenticated(error.message, error);

@@ -206,0 +206,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc