lughino / passport-unique-token Goto Github PK
View Code? Open in Web Editor NEWUnique token authentication strategy for Passport
License: MIT License
Unique token authentication strategy for Passport
License: MIT License
I am getting a TypeError: UniqueTokenStrategy is not a constructor
error when trying to use this package. My configuration is as follows:
const validationPassport = require('passport');
const UniqueTokenStrategy = require('passport-unique-token').Strategy;
const uniqueTokenStrategyOptions = {
tokenQuery: 'sessionToken',
tokenHeader: 'sessionToken',
tokenField: 'sessionToken',
tokenParams: 'sessionToken',
failedOnMissing: true
};
validationPassport.use(new UniqueTokenStrategy(uniqueTokenStrategyOptions, function(token, done) {
validationSessionModel.validateAdminSessionToken(token, validationSessionModel.validationSessionModel, function (err, info) {
if (err) {
logger.error("Authentication error with token " + token + ': ' + JSON.stringify(err));
return done(err);
}
if (!token) {
logger.warn("Session not found for token " + token);
return done(null, false);
}
logger.info("Session found for token " + token);
return done(null, info, { scope: 'all' });
});
})
);
And the authentication is:
router.post('/create',
authenticationHelper.validationPassport.authenticate('token'),
validationAttemptController.create
);
Can you help me out?
I'm using this strategy for authenticating requests that possibly could not have the req.query filled. I was wondering if there a way to change this by retrieving the query fields directly parsing the URL instead of using req.query. I actually am stuck by this, in case I can make a PR.
Hi, thanks for your module.
I am going to use it in my project, but I found that it can't check token from header. Can you please add this feature?
There is a small issue on the example given:
app.put("/animals/dogs", authenticate, function (req, res) {
// User authenticated and can be found in req.user
});
function authenticate(req, res, next) {
passport.authenticate("token", function (err, user, info) {
if (err) {
return next(err);
}
if (!user) {
res.status(401).json({message: "Incorrect token credentials"});
}
req.user = user;
next();
});
}
the passport.authenticate
returns a function that needs to be called. Should be:
app.put('/animals/dogs', authenticate, function (req, res) {
// User authenticated and can be found in req.user
});
function authenticate(req, res, next) {
passport.authenticate('token', function (err, user, info) {
if (err) {
return next(err);
}
if (!user) {
res.status(401).json({message: "Incorrect token credentials"});
}
req.user = user;
next();
})(req, res, next);
}
Otherwise it stops the application flow.
In order to reduce confusion in npm, would you consider deprecating this lib in favour of https://github.com/leepowellcouk/passport-token?
Would be nice have a typescript compatible package
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are currently rate-limited. Click on a checkbox below to force their creation now.
@types/jest
, jest
, ts-jest
)These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.
@commitlint/cli
, @commitlint/config-conventional
, @commitlint/prompt-cli
)@typescript-eslint/eslint-plugin
, @typescript-eslint/parser
)These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.
.circleci/config.yml
circleci/node 14.17.6
circleci/node 16.13.1
package.json
passport-strategy ^1.0.0
@commitlint/cli ^13.0.0
@commitlint/config-conventional ^13.0.0
@commitlint/prompt-cli ^13.0.0
@semantic-release/git ^9.0.0
@types/express ^4.17.13
@types/jest ^27.0.0
@types/node ^16.3.0
@types/passport-strategy ^0.2.35
@types/supertest ^2.0.11
@typescript-eslint/eslint-plugin ^4.28.2
@typescript-eslint/parser ^4.28.2
body-parser ^1.19.0
chai-passport-strategy ^1.0.1
commitizen ^4.2.4
cross-env ^7.0.3
cz-customizable ^6.3.0
eslint ^7.30.0
eslint-config-prettier ^8.3.0
eslint-plugin-import ^2.23.4
eslint-plugin-prettier ^4.0.0
express ^4.17.1
husky ^7.0.1
is-ci ^3.0.0
jest ^27.0.6
jest-junit ^12.2.0
lint-staged ^11.0.0
passport ^0.4.1
prettier ^2.3.2
semantic-release ^18.0.0
supertest ^6.1.3
ts-jest ^27.0.3
typescript ^4.3.5
node >= 12
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.