Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
egg-passport-jwt
Advanced tools
$ npm i egg-passport-jwt --save
// {app_root}/config/plugin.js
exports.passportJwt = {
enable: true,
package: 'egg-passport-jwt',
};
// {app_root}/config/config.default.js
exports.passportJwt = {
secret: 'your jwt secret or key',
};
see passport-jwt for more detail.
Use app.passport.authenticate()
specifying 'jwt'
as the strategy.
// app/router.js
module.exports = app => {
const { router, controller } = app;
const jwt = app.passport.authenticate('jwt', { session: false, successReturnToOrRedirect: null });
router.get('/', controller.home.index);
router.get('/protected', jwt, controller.home.index);
};
The method of including a JWT in a request depends entirely on the extractor
function you choose. For example, if you use the fromAuthHeaderAsBearerToken
extractor (default), you would include an Authorization
header in your request with the
scheme set to bearer
. e.g.
Authorization: bearer JSON_WEB_TOKEN_STRING...
Use app.passport.verify(async (ctx, user) => {})
hook:
// app.js
module.exports = app => {
app.passport.verify(async (ctx, user) => {
// check user
assert(user.provider, 'user.provider should exists');
assert(user.payload, 'user.payload should exists');
// find user from database
const existsUser = await ctx.model.User.findOne({ id: user.payload.sub });
if (existsUser) return existsUser;
// or you could create a new user
});
};
Please open an issue here.
FAQs
jwt passport plugin for egg
We found that egg-passport-jwt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.