Questions tagged [passport-jwt]
147 questions
20
votes
10 answers
Nest.js Auth Guard JWT Authentication constantly returns 401 unauthorized
Using Postman to test my endpoints, I am able to successfully "login" and receive a JWT token. Now, I am trying to hit an endpoint that supposedly has an AuthGuard to ensure that now that I am logged in, I can now access it.
However, it constantly…

noblerare
- 10,277
- 23
- 78
- 140
14
votes
1 answer
Using passport-jwt and epilogue, my req.user is empty
My middleware code is:
exports.isAuthenticated = (req, res, context) => {
return new Promise((resolve, reject) => {
return passport.authenticate('jwt',{session: false}, (err, user, info) => {
if(err) {
…

Shamoon
- 41,293
- 91
- 306
- 570
12
votes
3 answers
fromAuthHeaderAsBearerToken is not working in NODE
I did following things to passport authentication in Node.
1) I am using jwtFromRequest : ExtractJwt.fromAuthHeaderAsBearerToken(),
module.exports = function(passport){
var opts = {};
opts.jwtFromRequest =…

Sanket Lathiya
- 189
- 1
- 1
- 11
10
votes
4 answers
How to implement multiple JWT strategies using multiple secrets in Nest.JS
I like to implement more than one named passport-JWT strategy, each with its own secret. Is there any way it can be implemented?
From what I can understand from the documentation, only one secret can be registered during module…

Arnab De
- 402
- 4
- 12
9
votes
1 answer
PassportJS, NestJS: canActivate method of AuthGuard('jwt')
Does anybody know where I can see the full code of canActivate method in AuthGuard('jwt')? I realized that canActivate method calls JwtStrategy validate method by using console.log() like this:
// jwt.strategy.ts
@Injectable()
export class…

Ryan Ro
- 304
- 2
- 11
8
votes
3 answers
What is the difference between 'passport', 'passport-local' and 'passport-jwt'?
I am trying to learn NodeJS and saw these three functions/classes in a tutorial but couldn't understand what they are and when should we use which one?
Do I need to use both passport-local and passport-jwt at the same time or only one of them?

Hasani
- 3,543
- 14
- 65
- 125
7
votes
1 answer
Nuxt auth with passportjs?
How use nuxt auth Module (front-end) with passport-local using JWT (back-end express) ?
defining jwt strategy for verify jwt token (express)
var JwtStrategy = require('passport-jwt').Strategy,
ExtractJwt =…

PRAJIN PRAKASH
- 1,366
- 1
- 15
- 31
6
votes
1 answer
I'm using a passport-jwt auth strategy in my nestJS app (with authGuard), how to get access to the token payload in my controller?
I'm trying to get access to the jwt payload in a route that is protected by an AuthGuard.
I'm using passport-jwt and the token payload is the email of the user.
I could achieve this by runing the code bellow:
import {
Controller,
…

TheAngularGuy
- 939
- 8
- 13
6
votes
2 answers
Asymmetric keys with passport jwt. Verify always returns Unauthorized
Working on an app, and I want security from the start, so I've created a private/public key pair, and I'm setting up passport-jwt like this: (key is the public part of the keypair)
(passport, key) => {
const opts = {
jwtFromRequest:…

Chris Rutherford
- 1,592
- 3
- 22
- 58
6
votes
1 answer
NestJS JwtStrategy use configService to pass secret key
I have the JwtStrategy class from docs example (https://docs.nestjs.com/techniques/authentication):
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(
private readonly authService: AuthService,
…

Vladyslav Moisieienkov
- 4,118
- 4
- 25
- 32
5
votes
2 answers
Why using passport local strategy coupled with jwt strategy
Hi I'm trying to build a NestJS API and wanna learn the best practices to do it.
So I was wondering why the documentation of Nest JS
https://docs.nestjs.com/security/authentication
is providing an example of authentication with coupling…

Oscar Rénier
- 65
- 5
5
votes
7 answers
Logout JWT with nestJS
I'm using JWT passaport to login module:
async validateUser(userEmail: string, userPassword: string) {
const user = await this.userService.findByEmail(userEmail);
if (user && user.password === userPassword) {
const { id, name, email }…

Juan Carlos
- 53
- 1
- 1
- 3
5
votes
2 answers
Customise the response on verification failure for a jwt Strategy NestJs
I successfully implemented a jwt strategy for authentication using nestJs.
Below is the code for the jwt strategy
import { ServerResponse } from './../helpers/serverResponse.helper';
import { Injectable, UnauthorizedException, HttpStatus } from…

Prémices K
- 65
- 2
- 6
5
votes
1 answer
Passport authentication with JWT: How can I change passport's default unauthorized response to my custom response?
I created a Node project with passport. When I did not give the token as header it returns Unauthorized. How can I change this message to pretty as Sorry invalid credentials
Every time when the token cannot be given I got the response as…

test team
- 677
- 3
- 12
- 27
4
votes
0 answers
dusterio/lumen-passport: Pass custom data in JWT Payload
I am using lumen-passport for authentication and authorization. When I decode the JWT token I get payload as below:
{
"aud": "9420abb1-1470-4895-8666-a702b415cb59",
"jti":…

aagjalpankaj
- 1,160
- 1
- 15
- 25